~singpolyma/sgx-jmp

4f26f5f84be11e7cc4eb94c0f7bd4a20e11c7775 — Stephen Paul Weber 1 year, 7 months ago 1d81fc9
Set location when moving to v2 SIP

From configure calls as well as from reset sip account.
3 files changed, 19 insertions(+), 5 deletions(-)

M lib/bwmsgsv2_repo.rb
M lib/customer_fwd.rb
M sgx_jmp.rb
M lib/bwmsgsv2_repo.rb => lib/bwmsgsv2_repo.rb +11 -1
@@ 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)

M lib/customer_fwd.rb => lib/customer_fwd.rb +8 -0
@@ 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

M sgx_jmp.rb => sgx_jmp.rb +0 -4
@@ 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)