Set location when moving to v2 SIP

Stephen Paul Weber created

From configure calls as well as from reset sip account.

Change summary

lib/bwmsgsv2_repo.rb | 12 +++++++++++-
lib/customer_fwd.rb  |  8 ++++++++
sgx_jmp.rb           |  4 ----
3 files changed, 19 insertions(+), 5 deletions(-)

Detailed changes

lib/bwmsgsv2_repo.rb 🔗

@@ -44,11 +44,21 @@ class Bwmsgsv2Repo
 				"catapult_fwd_timeout-#{sgx.from_jid}",
 				customer_fwd.timeout.to_i
 			)
-		])
+		]).then do
+			set_default_location(tel) if customer_fwd.v2_sip?
+		end
 	end
 
 protected
 
+	def set_default_location(tel)
+		# Migrate location if needed
+		BandwidthIris::SipPeer.new(
+			site_id: CONFIG[:bandwidth_site],
+			id: CONFIG[:bandwidth_peer]
+		).move_tns([tel])
+	end
+
 	def set_or_delete(k, v)
 		if v.nil?
 			REDIS.del(k)

lib/customer_fwd.rb 🔗

@@ -52,6 +52,10 @@ class CustomerFwd
 		BANDWIDTH_VOICE.create_call(account, body: request).data.call_id
 	end
 
+	def v2_sip?
+		false
+	end
+
 	class Tel < CustomerFwd
 		def to
 			uri.sub(/^tel:/, "")
@@ -59,6 +63,10 @@ class CustomerFwd
 	end
 
 	class SIP < CustomerFwd
+		def v2_sip?
+			uri.end_with?(CONFIG[:sip][:realm])
+		end
+
 		def to
 			uri
 		end

sgx_jmp.rb 🔗

@@ -625,10 +625,6 @@ Command.new(
 			reply.command << form
 		}.then do |fwd|
 			if ["1", "true"].include?(fwd.form.field("change_fwd")&.value.to_s)
-				# Migrate location if needed
-				BandwidthIris::SipPeer.new(
-					site_id: CONFIG[:bandwidth_site], id: CONFIG[:bandwidth_peer]
-				).move_tns([customer.registered?.phone])
 				Command.execution.customer_repo.put_fwd(
 					customer,
 					customer.fwd.with(uri: sip_account.uri)