apply-hotfix: relocate deduplication of group msgs

Phillip Davis created

Change summary

sgx-bwmsgsv2.rb | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -1009,10 +1009,6 @@ class WebhookHandler < Goliath::API
 			return [400, {}, "OK"]
 		end
 
-		jparams['to'].reject! { |num|
-			num == users_num || num == others_num
-		}
-
 		return [400, {}, "Missing params\n"] unless users_num && others_num
 		return [400, {}, "Missing params\n"] unless jparams['to'].is_a?(Array)
 
@@ -1066,7 +1062,11 @@ class WebhookHandler < Goliath::API
 					addr1['jid'] = bare_jid
 					addrs.add_child(addr1)
 
-					jparams['to'].each do |receiver|
+					jparams['to'].reject(
+						# Don't send to the same person twice,
+						# and don't send to the person who sent it
+						&[users_num, others_num].method(:include?)
+					).each do |receiver|
 						addrn = Nokogiri::XML::Node.new(
 							'address', msg.document)
 						addrn['type'] = 'to'
@@ -1180,7 +1180,7 @@ class WebhookHandler < Goliath::API
 				MessageEvent::In.new(
 					timestamp: jparams['time'],
 					from: jparams['from'],
-					to: jparams['to'] << users_num,
+					to: jparams['to'],
 					owner: jparams['owner'],
 					bandwidth_id: jparams['id'],
 					body: jparams['text'].to_s,