~singpolyma/sgx-jmp

ref: 358e8664769bdeef7c225e347d309c139ec51a69 sgx-jmp/lib/web_register_manager.rb -rw-r--r-- 661 bytes
358e8664Stephen Paul Weber Merge branch 'finish-btc' 1 year, 3 months 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
# frozen_string_literal: true

class WebRegisterManager
	THIRTY_DAYS = 60 * 60 * 24 * 30

	def initialize(redis: REDIS)
		@redis = redis
	end

	def set(jid, tel)
		@redis.setex("pending_tel_for-#{jid}", tel, THIRTY_DAYS)
	end

	def [](jid)
		@redis.get("pending_tel_for-#{jid}").then do |tel|
			tel ? HaveTel.new(tel) : ChooseTel.new
		end
	end

	class HaveTel
		def initialize(tel)
			@tel = tel
		end

		def choose_tel
			EMPromise.resolve(@tel)
		end
	end

	class ChooseTel
		def choose_tel
			Command.finish(
				"You have not chosen a phone number yet, please return to " \
				"https://jmp.chat and choose one now.",
				type: :error
			)
		end
	end
end