XEP-0033 now actually supported, offers group text

Denver Gingerich created

Now the XEP-0033 support indicated in 8e8fa1b is actually present, and
allows the SGX to receive group texts in this manner per the details
in https://wiki.soprani.ca/SGX/GroupMMS - the other method added in
96856c7 remains as of this commit, but will be removed shortly.

Note that the method parameter for validate_num had to change slightly
here, but the single-number validation code needed no changes at all.

Change summary

sgx-bwmsgsv2.rb | 45 ++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -331,8 +331,47 @@ module SGXbwmsgsv2
 		}
 	end
 
-	def self.validate_num(num)
-		EMPromise.resolve(num.to_s).then { |num_dest|
+	def self.validate_num(m)
+		# if sent to SGX domain use https://wiki.soprani.ca/SGX/GroupMMS
+		if m.to == ARGV[0]
+			an = m.children.find { |v| v.element_name == "addresses"
+				}
+			if not an
+				return EMPromise.reject([:cancel,
+					'item-not-found'])
+			end
+			puts "ADRXEP: found an addresses node - iterate addrs.."
+
+			nums = []
+			an.children.each do |e|
+				num = ''
+				type = ''
+				e.attributes.each do |c|
+					if c[0] == 'type'
+						if c[1] != 'to'
+							# TODO: error
+						end
+						type = c[1].to_s
+					elsif c[0] == 'uri'
+						if !c[1].to_s.start_with? 'sms:'
+							# TODO: error
+						end
+						num = c[1].to_s[4..-1]
+						# TODO: confirm num validates
+					else
+						# TODO: error - unexpected name
+					end
+				end
+				if num.empty? or type.empty?
+					# TODO: error
+				end
+				nums << num
+			end
+			return nums
+		end
+
+		# if not sent to SGX domain, then assume destination is in 'to'
+		EMPromise.resolve(m.to.node.to_s).then { |num_dest|
 			if num_dest =~ /\A\+?[0-9]+(?:;.*)?\Z/
 				next num_dest if num_dest[0] == '+'
 				shortcode = extract_shortcode(num_dest)
@@ -384,7 +423,7 @@ module SGXbwmsgsv2
 
 	message :body do |m|
 		EMPromise.all([
-			validate_num(m.to.node),
+			validate_num(m),
 			fetch_catapult_cred_for(m.from)
 		]).then { |(num_dest, creds)|
 			jid_key = "catapult_jid-#{num_dest}"