refactor: add `addresses` blather helper

Phillip Davis created

Change summary

lib/blather_ext.rb | 10 ++++++++++
sgx_jmp.rb         |  4 +---
2 files changed, 11 insertions(+), 3 deletions(-)

Detailed changes

lib/blather_ext.rb 🔗

@@ -16,4 +16,14 @@ module Blather
 			})
 		end
 	end
+
+	class Stanza
+		class Message
+			def addresses
+				find("ns:addresses", ns: ADDRESSES_NS)
+					.first
+					&.find("ns:address", ns: ADDRESSES_NS)
+			end
+		end
+	end
 end

sgx_jmp.rb 🔗

@@ -300,9 +300,7 @@ message(
 	Sentry.get_current_scope.set_transaction_name("inbound_group_text")
 	log.info "Possible group text #{m.from}"
 
-	address = m.find("ns:addresses", ns: ADDRESSES_NS).first
-		&.find("ns:address", ns: ADDRESSES_NS)
-		&.find { |el| el["jid"].to_s.start_with?("customer_") }
+	address = m.addresses&.find { |el| el["jid"].to_s.start_with?("customer_") }
 	pass unless address
 
 	CustomerRepo