~singpolyma/sgx-jmp

ref: 345895de5e28ddf4e57ae13599924149f5d44d5c sgx-jmp/lib/command_list.rb -rw-r--r-- 1.1 KiB
345895deStephen Paul Weber Show commands conditionally (plus add voicemail record command) 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true

class CommandList
	include Enumerable

	def self.for(jid)
		Customer.for_jid(jid).then(&:registered?).catch { nil }.then { |reg|
			next [] unless reg
			REDIS.get("catapult_fwd-#{reg.phone}").then { |fwd| [reg, fwd] }
		}.then do |(reg, fwd)|
			next RegisteredAndHasForwarding.new if reg && fwd
			next Registered.new if reg
			CommandList.new
		end
	end

	def each
		yield node: "jabber:iq:register", name: "Register"
	end

	class Registered < CommandList
		def each
			super
			yield node: "number-display", name: "Display JMP Number"
			yield node: "configure-calls", name: "Configure Calls"
			# TODO: don't show this item if no braintree methods available
			# TODO: don't show this item if no plan for this customer
			yield node: "buy-credit", name: "Buy account credit"
			yield node: "usage", name: "Show Monthly Usage"
			yield node: "reset sip account", name: "Create or Reset SIP Account"
		end
	end

	class RegisteredAndHasForwarding < Registered
		def each
			super
			yield(
				node: "record-voicemail-greeting",
				name: "Record Voicemail Greeting"
			)
		end
	end
end