Commit hotfixes

Stephen Paul Weber created

Change summary

lib/outgoing_mms.rb      |  2 +-
lib/registration_repo.rb |  4 ++--
sgx_endstream.rb         | 12 +++++++-----
3 files changed, 10 insertions(+), 8 deletions(-)

Detailed changes

lib/outgoing_mms.rb 🔗

@@ -2,7 +2,7 @@
 
 class OutgoingMMS
 	def self.for(m)
-		body = m.body.sub(m.oobs.first.url, "")
+		body = m.body.sub(m.oobs.first&.url.to_s, "")
 		OutgoingMMS.new(
 			addresses: m.addresses ||
 				[Addresses::Address.new(uri: "sms:#{m.to.node}")],

lib/registration_repo.rb 🔗

@@ -17,7 +17,7 @@ class RegistrationRepo
 
 	def put(jid, *creds)
 		setup_endstream_route(*creds, jid).then do |status|
-			next status unless status.first[:code].to_i.zero?
+			next status unless status[:code].to_i.zero?
 
 			@redis.rpush(
 				"endstream_registration-#{jid.stripped}",
@@ -28,7 +28,7 @@ class RegistrationRepo
 
 	def delete(jid)
 		find(jid).then do |creds|
-			next { code: 0 } unless creds
+			next { code: 0 } unless creds&.length&.positive?
 
 			EMPromise.all([
 				remove_endstream_route(*creds),

sgx_endstream.rb 🔗

@@ -10,6 +10,7 @@ require "json"
 require "ougai"
 require "sentry-ruby"
 
+require_relative "lib/addresses"
 require_relative "lib/blather_client"
 require_relative "lib/blather_ext"
 require_relative "lib/em"
@@ -148,17 +149,18 @@ ibr type: :set do |iq|
 		self << if status[:code].to_i.zero?
 			iq.reply
 		else
-			iq.as_error("bad-request", :modify, r[:text])
+			iq.as_error("bad-request", :modify, status[:text])
 		end
 	}
 end
 
 message from: /@sms.chat.1pcom.net\Z/ do |m|
 	tel = if m.from.node.length > 7
-		"+{m.from.node}"
+		"+#{m.from.node}"
 	else
 		"#{m.from.node};phone-context=ca-us.phone-context.soprani.ca"
 	end
+	m = m.dup
 	m.from = Blather::JID.new(tel, CONFIG[:component][:jid])
 	m.to = ProxiedJID.new(m.to).unproxied
 	m.subject = nil # They send a generic subject for some reason
@@ -167,7 +169,7 @@ end
 
 message from: /@mms.chat.1pcom.net\Z/ do |m|
 	json = JSON.parse(m.body)
-	if json["GlobalStatus"]
+	if json.is_a?(Hash) && json["GlobalStatus"]
 		log.info("MMS Status", json["disposition"])
 		next
 	end
@@ -198,13 +200,13 @@ def too_long_for_sms(m)
 	m.body.length > (m.body.ascii_only? ? 160 : 70) * 3
 end
 
-message :body, method(:too_long_for_sms), to: /\A\+?\d+@/ do |m|
+message :body, method(:too_long_for_sms).to_proc, to: /\A\+?\d+@/ do |m|
 	self << OutgoingMMS.for(m).to_stanza(id: m.id, from: m.from)
 end
 
 message(
 	:body,
-	to: /(?:\A\+?\d+@)|(?:;phone-context=ca-us\.phone-context\.soprani\.ca\Z)/
+	to: /(?:\A\+?\d+@)|(?:;phone-context=ca-us\.phone-context\.soprani\.ca@)/
 ) do |m|
 	m.to = Blather::JID.new(
 		m.to.node.sub(/\A\+/, "").sub(/;phone-context=.*\Z/, ""),