Don't Count Stanzas Without Body as Reached

Christopher Vollick created

We get messages without bodies from time to time as things like delivery
receipts.

These are great, and we don't want to forward them to the end-user for
sure if we're dealing with a reachable number, but we also don't want to
count it as a message that reached us.

It's a receipt for a thing I did, not a thing the tester did.

Change summary

lib/reachability_repo.rb | 19 +++++++++++++++++--
sgx_jmp.rb               |  9 +++++----
2 files changed, 22 insertions(+), 6 deletions(-)

Detailed changes

lib/reachability_repo.rb 🔗

@@ -39,13 +39,28 @@ class ReachabilityRepo
 		end
 	end
 
+	# This one is for things that don't have a body.
+	# I still don't want to deliver them to the user, but I don't want to count
+	# them as a message either
+	class Ignore
+		def filter(if_yes: ->(_) {}, **)
+			EMPromise.resolve(if_yes.call(nil))
+		end
+	end
+
+	ACCEPTABLE_STANZA = Blather::Stanza::Message.new(nil, "I'm cool").freeze
+
 	# The customer is who is being contacted
 	# The initiator is the phone number trying to reach them
-	def find(customer, initiator)
+	def find(customer, initiator, stanza: ACCEPTABLE_STANZA)
 		return EMPromise.resolve(NotTest.new) unless potential?(initiator)
 
 		testing?(customer).then do |active|
-			active ? Test.new(redis, key(customer)) : NotTest.new
+			if active
+				stanza.body ? Test.new(redis, key(customer)) : Ignore.new
+			else
+				NotTest.new
+			end
 		end
 	end
 

sgx_jmp.rb 🔗

@@ -282,11 +282,12 @@ before nil, to: /\Acustomer_/, from: /(\A|@)#{CONFIG[:sgx]}(\/|\Z)/ do |s|
 	CustomerRepo.new(set_user: Sentry.method(:set_user)).find(
 		s.to.node.delete_prefix("customer_")
 	).then do |customer|
-		ReachabilityRepo::SMS.new.find(customer, s.from.node).then do |reach|
-			reach.filter do
-				customer.stanza_to(s)
+		ReachabilityRepo::SMS.new
+			.find(customer, s.from.node, stanza: s).then do |reach|
+				reach.filter do
+					customer.stanza_to(s)
+				end
 			end
-		end
 	end
 
 	halt