2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-07-25 06:55:56 +00:00
|
|
|
class Sessions::Backend::ActivityStream < Sessions::Backend::Base
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2018-06-29 17:04:39 +00:00
|
|
|
attr_writer :user
|
|
|
|
|
2020-09-30 09:07:01 +00:00
|
|
|
def initialize(user, asset_lookup, client = nil, client_id = nil, ttl = 25) # rubocop:disable Lint/MissingSuper
|
2016-03-03 08:56:13 +00:00
|
|
|
@user = user
|
|
|
|
@client = client
|
|
|
|
@client_id = client_id
|
|
|
|
@ttl = ttl
|
|
|
|
@asset_lookup = asset_lookup
|
|
|
|
@last_change = nil
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def load
|
|
|
|
|
|
|
|
# get whole collection
|
2016-03-01 14:26:46 +00:00
|
|
|
activity_stream = @user.activity_stream(25)
|
2014-07-13 18:52:32 +00:00
|
|
|
if activity_stream && !activity_stream.first
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-11-23 08:09:44 +00:00
|
|
|
if activity_stream&.first && activity_stream.first['created_at'] == @last_change
|
2014-07-13 18:52:32 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
# update last changed
|
2017-11-23 08:09:44 +00:00
|
|
|
if activity_stream&.first
|
2015-04-30 17:14:51 +00:00
|
|
|
@last_change = activity_stream.first['created_at']
|
2013-09-21 22:40:19 +00:00
|
|
|
end
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2018-03-20 12:16:17 +00:00
|
|
|
assets = {}
|
|
|
|
item_ids = []
|
|
|
|
activity_stream.each do |item|
|
2018-07-20 05:08:26 +00:00
|
|
|
begin
|
|
|
|
assets = item.assets(assets)
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
2018-03-20 12:16:17 +00:00
|
|
|
item_ids.push item.id
|
|
|
|
end
|
|
|
|
|
|
|
|
{
|
|
|
|
record_ids: item_ids,
|
2018-12-19 17:31:51 +00:00
|
|
|
assets: assets,
|
2018-03-20 12:16:17 +00:00
|
|
|
}
|
2014-07-13 18:52:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def push
|
2019-07-25 06:55:56 +00:00
|
|
|
return if !to_run?
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2019-07-25 06:55:56 +00:00
|
|
|
@time_now = Time.zone.now.to_i
|
2013-09-21 22:40:19 +00:00
|
|
|
|
2015-05-07 12:10:38 +00:00
|
|
|
data = load
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2017-10-18 00:09:45 +00:00
|
|
|
return if data.blank?
|
2014-07-13 18:52:32 +00:00
|
|
|
|
|
|
|
if !@client
|
|
|
|
return {
|
2018-12-19 17:31:51 +00:00
|
|
|
event: 'activity_stream_rebuild',
|
2015-04-27 13:42:53 +00:00
|
|
|
collection: 'activity_stream',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: data,
|
2014-07-13 18:52:32 +00:00
|
|
|
}
|
2013-09-21 22:40:19 +00:00
|
|
|
end
|
2014-07-13 18:52:32 +00:00
|
|
|
|
2015-07-03 15:18:01 +00:00
|
|
|
@client.log "push activity_stream #{data.first.class} for user #{@user.id}"
|
2015-04-27 15:21:17 +00:00
|
|
|
@client.send(
|
2018-12-19 17:31:51 +00:00
|
|
|
event: 'activity_stream_rebuild',
|
2015-04-27 13:42:53 +00:00
|
|
|
collection: 'activity_stream',
|
2018-12-19 17:31:51 +00:00
|
|
|
data: data,
|
2015-04-27 15:21:17 +00:00
|
|
|
)
|
2013-09-21 22:40:19 +00:00
|
|
|
end
|
|
|
|
|
2015-04-27 14:15:29 +00:00
|
|
|
end
|