fedibird-fe/app/workers/publish_emoji_reaction_worker.rb

24 lines
701 B
Ruby
Raw Normal View History

2021-05-19 05:58:27 +00:00
# frozen_string_literal: true
class PublishEmojiReactionWorker
include Sidekiq::Worker
include Redisable
include RoutingHelper
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
payload['status_id'] = status_id.to_s
2021-05-19 05:58:27 +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|
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