chat_status_agent.rb 824 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. class Sessions::Event::ChatStatusAgent < Sessions::Event::ChatBase
  2. =begin
  3. a agent requests a the current state of all chat sessions
  4. payload
  5. {
  6. event: 'chat_status_agent',
  7. data: {},
  8. }
  9. return is sent as message back to peer
  10. =end
  11. def run
  12. return super if super
  13. # check if user has permissions
  14. return if !permission_check('chat.agent', 'chat')
  15. # renew timestamps
  16. state = Chat::Agent.state(@session['id'])
  17. Chat::Agent.state(@session['id'], state)
  18. # update recipients of existing sessions
  19. Chat::Session.where(state: 'running', user_id: @session['id']).order(created_at: :asc).each do |chat_session|
  20. chat_session.add_recipient(@client_id, true)
  21. end
  22. {
  23. event: 'chat_status_agent',
  24. data: Chat.agent_state_with_sessions(@session['id']),
  25. }
  26. end
  27. end