2021-05-19 05:58:27 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class PublishEmojiReactionWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
include Redisable
|
|
|
|
include RoutingHelper
|
|
|
|
|
2021-09-12 16:24:47 +00:00
|
|
|
def perform(status_id, name)
|
|
|
|
status = Status.find(status_id)
|
|
|
|
payload = status.grouped_emoji_reactions.find { |emoji_reaction| emoji_reaction['name'] == name }
|
|
|
|
payload ||= { name: name, count: 0, account_ids: [] }
|
2021-05-19 05:58:27 +00:00
|
|
|
|
2021-09-12 16:24:47 +00:00
|
|
|
payload['status_id'] = status_id.to_s
|
2021-05-19 05:58:27 +00:00
|
|
|
|
2021-09-12 16:24:47 +00:00
|
|
|
json = Oj.dump(event: :'emoji_reaction', payload: payload)
|
2021-05-19 05:58:27 +00:00
|
|
|
|
|
|
|
FeedManager.instance.with_active_accounts do |account|
|
2021-09-12 16:24:47 +00:00
|
|
|
redis.publish("timeline:#{account.id}", json) if redis.exists?("subscribed:timeline:#{account.id}")
|
2021-05-19 05:58:27 +00:00
|
|
|
end
|
|
|
|
rescue ActiveRecord::RecordNotFound
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|