trabajo-afectivo/lib/sessions/event/chat_agent_state.rb

53 lines
959 B
Ruby
Raw Permalink Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
class Sessions::Event::ChatAgentState < Sessions::Event::ChatBase
2015-11-10 14:01:04 +00:00
=begin
a agent triggers its own chat availability state
payload
{
event: 'chat_agent_state',
data: {
active: true, # true|false
},
}
return is sent as message back to peer
=end
def run
2015-12-09 13:09:37 +00:00
return super if super
2015-11-10 14:01:04 +00:00
# check if user has permissions
return if !permission_check('chat.agent', 'chat')
2015-11-10 14:01:04 +00:00
update_state
2015-11-15 10:01:48 +00:00
2015-11-10 14:01:04 +00:00
{
event: 'chat_agent_state',
data: {
state: 'ok',
2015-12-09 13:09:37 +00:00
active: @payload['data']['active'],
2015-11-10 14:01:04 +00:00
},
}
end
2015-12-09 13:09:37 +00:00
private
def update_state
chat_user = User.lookup(id: @session['id'])
return if !Chat::Agent.state(@session['id'], @payload['data']['active'])
chat_ids = Chat.agent_active_chat_ids(chat_user)
# broadcast new state to agents
Chat.broadcast_agent_state_update(chat_ids, @session['id'])
end
2015-11-10 14:01:04 +00:00
end