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

57 lines
1.3 KiB
Ruby
Raw Normal View History

2022-01-01 13:38:12 +00:00
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
2015-12-09 13:09:37 +00:00
class Sessions::Event::Spool < Sessions::Event::Base
=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']
log 'info', "request spool data > '#{Time.at(@payload['timestamp']).utc.iso8601}'"
2015-12-09 13:09:37 +00:00
else
log 'info', 'request spool with init data'
2015-12-09 13:09:37 +00:00
end
if !@session || !@session['id']
log 'error', "Can't send spool, session not authenticated"
return {
event: 'error',
data: {
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'])
spool.each do |item|
2015-12-09 13:09:37 +00:00
# create new msg to push to client
if item[:type] == 'direct'
log 'info', "send spool to (user_id=#{@session['id']})"
2015-12-09 13:09:37 +00:00
else
log 'info', 'send spool'
2015-12-09 13:09:37 +00:00
end
websocket_send(@client_id, item[:message])
end
2015-12-09 13:09:37 +00:00
# send spool:sent event to client
log 'info', 'send spool:sent event'
2015-12-09 13:09:37 +00:00
{
event: 'spool:sent',
data: {
2015-12-09 13:09:37 +00:00
timestamp: Time.now.utc.to_i,
},
}
end
end