merge in "Clean up oob" incl. always on MMS-on-OOB

Denver Gingerich created

This is a cross-merge of what we did in sgx-catapult already, in
https://gitlab.com/ossguy/sgx-catapult/commit/f95aab3 - see
https://gitlab.com/ossguy/sgx-catapult/merge_requests/19 for further
details.  The merge is not exact, as there has been some drift in
sgx-bwmsgsv2 since this was done in sgx-catapult, so indentation and
some s/next/return/ caused it to be a bit off.  But it should be fine.

This effectively removes the option to turn off MMS-on-OBB, and since
that has already been removed in sgx-catapult (per above), we can now
remove it from jmp-acct_bot as there are no further users (to be done
in a future commit).

With this commit we are getting close to feature-/fix-parity with
sgx-catapult, aside from the message blocking feature (which we won't
need to merge for a while yet).

Change summary

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

Detailed changes

sgx-bwmsgsv2.rb 🔗

@@ -270,53 +270,29 @@ module SGXbwmsgsv2
 	def self.to_catapult_possible_oob(s, num_dest, user_id, token, secret,
 		usern)
 
-		xn = s.children.find { |v| v.element_name == "x" }
-		if not xn
-			to_catapult(s, nil, num_dest, user_id, token, secret,
-				usern)
-			return
-		end
-		puts "MMSOOB: found an x node - checking for url node..."
-
-		# TODO: also check for xmlns='jabber:x:oob' in <x/> - the below
-		#  is probably fine, though, as non-OOB <x><url/></x> unlikely
-
-		un = xn.children.find { |v| v.element_name == "url" }
-		if not un
-			puts "MMSOOB: no url node found so process as normal"
-			to_catapult(s, nil, num_dest, user_id, token, secret,
-				usern)
-			return
-		end
-		puts "MMSOOB: found a url node - checking if to make MMS..."
-
-		REDIS.getbit("catapult_setting_flags-#{s.from.stripped}",
-			CatapultSettingFlagBits::MMS_ON_OOB_URL).then { |oob_on|
-
-			puts "MMSOOB: found MMS_ON_OOB_URL value is '#{oob_on}'"
-			if 0 == oob_on
-				puts "MMSOOB: MMS_ON_OOB_URL off so no MMS send"
-				to_catapult(s, nil, num_dest, user_id, token,
-					secret, usern)
-				next
+			# TODO: fix indentation
+
+			un = s.at("oob|x > oob|url", oob: "jabber:x:oob")
+			if not un
+				puts "MMSOOB: no url node found so process as normal"
+				to_catapult(s, nil, num_dest, user_id, token, secret,
+					usern)
+				return
 			end
+			puts "MMSOOB: found a url node - checking if to make MMS..."
 
 			# TODO: check size of file at un.text and shrink if need
 
 			body = s.respond_to?(:body) ? s.body : ''
+			# some clients send URI in both body & <url/> so delete
+			s.body = body.sub(/\s*#{Regexp::escape(un.text)}\s*$/, '')
+
 			puts "MMSOOB: url text is '#{un.text}'"
 			puts "MMSOOB: the body is '#{body.to_s.strip}'"
 
-			# some clients send URI in both body & <url/> so delete
-			if un.text == body.to_s.strip
-				puts "MMSOOB: url matches body so deleting body"
-				s.body = ''
-			end
-
 			puts "MMSOOB: sending MMS since found OOB & user asked"
 			to_catapult(s, un.text, num_dest, user_id, token,
 				secret, usern)
-		}
 	end
 
 	def self.to_catapult(s, murl, num_dest, user_id, token, secret, usern)