chat_status_agent.rb 903 B

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