publish_announcement_reaction_worker.rb 888 B

12345678910111213141516171819202122
  1. # frozen_string_literal: true
  2. class PublishAnnouncementReactionWorker
  3. include Sidekiq::Worker
  4. include Redisable
  5. def perform(announcement_id, name)
  6. announcement = Announcement.find(announcement_id)
  7. reaction, = announcement.announcement_reactions.where(name: name).group(:announcement_id, :name, :custom_emoji_id).select('name, custom_emoji_id, count(*) as count, false as me')
  8. reaction ||= announcement.announcement_reactions.new(name: name)
  9. payload = InlineRenderer.render(reaction, nil, :reaction).tap { |h| h[:announcement_id] = announcement_id.to_s }
  10. payload = Oj.dump(event: :'announcement.reaction', payload: payload)
  11. FeedManager.instance.with_active_accounts do |account|
  12. redis.publish("timeline:#{account.id}", payload) if redis.exists?("subscribed:timeline:#{account.id}")
  13. end
  14. rescue ActiveRecord::RecordNotFound
  15. true
  16. end
  17. end