2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2015-12-09 13:09:37 +00:00
|
|
|
class Sessions::Event::Spool < Sessions::Event::Base
|
|
|
|
|
2018-11-02 17:42:57 +00:00
|
|
|
=begin
|
|
|
|
|
|
|
|
Event module to serve spool messages and send them to new client connection.
|
|
|
|
|
|
|
|
To execute this manually, just paste the following into the browser console
|
|
|
|
|
|
|
|
App.WebSocket.send({event:'spool'})
|
|
|
|
|
|
|
|
=end
|
|
|
|
|
2015-12-09 13:09:37 +00:00
|
|
|
def run
|
|
|
|
|
|
|
|
# error handling
|
|
|
|
if @payload['timestamp']
|
2020-11-27 09:49:36 +00:00
|
|
|
log 'info', "request spool data > '#{Time.at(@payload['timestamp']).utc.iso8601}'"
|
2015-12-09 13:09:37 +00:00
|
|
|
else
|
2020-11-27 09:49:36 +00:00
|
|
|
log 'info', 'request spool with init data'
|
2015-12-09 13:09:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if !@session || !@session['id']
|
2018-11-02 17:42:57 +00:00
|
|
|
log 'error', "Can't send spool, session not authenticated"
|
|
|
|
return {
|
|
|
|
event: 'error',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2018-11-02 17:42:57 +00:00
|
|
|
error: 'Can\'t send spool, session not authenticated',
|
|
|
|
},
|
|
|
|
}
|
2015-12-09 13:09:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
spool = Sessions.spool_list(@payload['timestamp'], @session['id'])
|
2017-10-01 12:25:52 +00:00
|
|
|
spool.each do |item|
|
2015-12-09 13:09:37 +00:00
|
|
|
|
|
|
|
# create new msg to push to client
|
|
|
|
if item[:type] == 'direct'
|
2020-11-27 09:49:36 +00:00
|
|
|
log 'info', "send spool to (user_id=#{@session['id']})"
|
2015-12-09 13:09:37 +00:00
|
|
|
else
|
2020-11-27 09:49:36 +00:00
|
|
|
log 'info', 'send spool'
|
2015-12-09 13:09:37 +00:00
|
|
|
end
|
2016-01-15 17:22:57 +00:00
|
|
|
websocket_send(@client_id, item[:message])
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2015-12-09 13:09:37 +00:00
|
|
|
|
|
|
|
# send spool:sent event to client
|
2020-11-27 09:49:36 +00:00
|
|
|
log 'info', 'send spool:sent event'
|
2015-12-09 13:09:37 +00:00
|
|
|
{
|
|
|
|
event: 'spool:sent',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: {
|
2015-12-09 13:09:37 +00:00
|
|
|
timestamp: Time.now.utc.to_i,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|