2021-05-19 05:58:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PublishEmojiReactionWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include Redisable
|
|
|
|
include RoutingHelper
|
2021-09-22 04:56:05 +00:00
|
|
|
include PublishScope
|
2021-05-19 05:58:27 +00:00
|
|
|
|
2021-09-22 04:56:05 +00:00
|
|
|
def perform(status_id, account_id, name)
|
|
|
|
@status = Status.find(status_id)
|
|
|
|
@account_id = account_id
|
|
|
|
@name = name
|
2021-05-19 05:58:27 +00:00
|
|
|
|
2021-09-22 04:56:05 +00:00
|
|
|
FeedManager.instance.active_accounts.merge(visibility_scope).find_each do |account|
|
2023-02-18 10:10:06 +00:00
|
|
|
redis.publish("timeline:#{account.id}", payload_json) if redis.exists?("subscribed:timeline:#{account.id}") && !account.user.setting_disable_reaction_streaming
|
2021-05-19 05:58:27 +00:00
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
2021-09-22 04:56:05 +00:00
|
|
|
|
|
|
|
def payload_json
|
2022-03-17 14:25:16 +00:00
|
|
|
return @payload_json if defined?(@payload_json)
|
|
|
|
|
2021-09-22 04:56:05 +00:00
|
|
|
payload = @status.grouped_emoji_reactions.find { |emoji_reaction| emoji_reaction['name'] == @name }
|
|
|
|
payload ||= { name: @name, count: 0, account_ids: [] }
|
|
|
|
|
|
|
|
payload['status_id'] = @status.id.to_s
|
|
|
|
|
2022-03-17 14:25:16 +00:00
|
|
|
@payload_json = Oj.dump(event: :'emoji_reaction', payload: payload)
|
2021-09-22 04:56:05 +00:00
|
|
|
end
|
2021-05-19 05:58:27 +00:00
|
|
|
end
|