闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
887 B

  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