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

41 lines
901 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::ChatStatusAgent < Sessions::Event::ChatBase
2015-11-10 14:01:04 +00:00
=begin
a agent requests a the current state of all chat sessions
payload
{
event: 'chat_status_agent',
data: {},
}
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
# renew timestamps
state = Chat::Agent.state(@session['id'])
Chat::Agent.state(@session['id'], state)
2015-11-10 14:01:04 +00:00
# update recipients of existing sessions
Chat::Session.where(state: 'running', user_id: @session['id']).order(created_at: :asc).each do |chat_session|
chat_session.add_recipient(@client_id, true)
end
2015-11-10 14:01:04 +00:00
{
event: 'chat_status_agent',
data: Chat.agent_state_with_sessions(@session['id']),
2015-11-10 14:01:04 +00:00
}
end
end