add incoming group text support for >2 recipients

Denver Gingerich created

When we first added proper incoming group text support (in 90331bc),
we only supported 2 recipients.  We also assumed the first recipient
was the user, and then just truncated the rest of the recipient list
to be just one additional number, as a way of getting it implemented
quickly.

Now we've added a bit more thought, and a loop to go through all the
recipient numbers to add them to the address list we pass on to the
user.

We also needed to be careful to filter out our own number from the
recipient list, as that is already added in the addr1 section above.

Change summary

sgx-bwmsgsv2.rb | 20 +++++++++++++-------
1 file changed, 13 insertions(+), 7 deletions(-)

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -898,13 +898,19 @@ class WebhookHandler < Goliath::API
 					addr1['jid'] = bare_jid
 					addrs.add_child(addr1)
 
-					# TODO: actually do N, instead of just 1
-					addrn = Nokogiri::XML::Node.new(
-						'address', msg.document)
-					addrn['type'] = 'to'
-					addrn['uri'] = "sms:#{jparams['to'][1]}"
-					addrn['delivered'] = 'true'
-					addrs.add_child(addrn)
+					jparams['to'].each do |receiver|
+						if receiver == users_num
+							# already there in addr1
+							next
+						end
+
+						addrn = Nokogiri::XML::Node.new(
+							'address', msg.document)
+						addrn['type'] = 'to'
+						addrn['uri'] = "sms:#{receiver}"
+						addrn['delivered'] = 'true'
+						addrs.add_child(addrn)
+					end
 
 					msg.add_child(addrs)