Class: Legion::Gaia::Channels::Teams::ConversationStore
- Inherits:
-
Object
- Object
- Legion::Gaia::Channels::Teams::ConversationStore
show all
- Defined in:
- lib/legion/gaia/channels/teams/conversation_store.rb
Defined Under Namespace
Classes: Reference, UserProfile
Instance Method Summary
collapse
Constructor Details
Returns a new instance of ConversationStore.
22
23
24
25
26
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 22
def initialize
@references = {}
@user_profiles = {}
@mutex = Mutex.new
end
|
Instance Method Details
#clear ⇒ Object
88
89
90
91
92
93
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 88
def clear
@mutex.synchronize do
@references.clear
@user_profiles.clear
end
end
|
#conversations ⇒ Object
80
81
82
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 80
def conversations
@mutex.synchronize { @references.keys }
end
|
#conversations_for_user(user_id) ⇒ Object
70
71
72
73
74
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 70
def conversations_for_user(user_id)
@mutex.synchronize do
@references.values.select { |ref| ref.tenant_id && user_related?(ref, user_id) }
end
end
|
#lookup(conversation_id) ⇒ Object
62
63
64
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 62
def lookup(conversation_id)
@mutex.synchronize { @references[conversation_id] }
end
|
#lookup_user_profile(user_id) ⇒ Object
66
67
68
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 66
def lookup_user_profile(user_id)
@mutex.synchronize { @user_profiles[user_id] }
end
|
#remove(conversation_id) ⇒ Object
76
77
78
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 76
def remove(conversation_id)
@mutex.synchronize { @references.delete(conversation_id) }
end
|
#size ⇒ Object
84
85
86
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 84
def size
@mutex.synchronize { @references.size }
end
|
#store(conversation_id:, service_url:, tenant_id: nil, bot_id: nil, activity_id: nil) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 28
def store(conversation_id:, service_url:, tenant_id: nil, bot_id: nil, activity_id: nil)
@mutex.synchronize do
@references[conversation_id] = Reference.new(
conversation_id: conversation_id,
service_url: service_url,
tenant_id: tenant_id,
bot_id: bot_id,
last_activity_id: activity_id
)
end
end
|
#store_from_activity(activity) ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 52
def store_from_activity(activity)
parsed = parse_activity(activity)
store(**parsed.slice(:conversation_id, :service_url, :tenant_id, :bot_id, :activity_id))
store_user_profile(
user_id: parsed[:user_id],
service_url: parsed[:service_url],
tenant_id: parsed[:tenant_id]
)
end
|
#store_user_profile(user_id:, service_url:, tenant_id: nil) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/legion/gaia/channels/teams/conversation_store.rb', line 40
def store_user_profile(user_id:, service_url:, tenant_id: nil)
return unless user_id && service_url
@mutex.synchronize do
@user_profiles[user_id] = UserProfile.new(
user_id: user_id,
service_url: service_url,
tenant_id: tenant_id
)
end
end
|