The code powering m.abunchtell.com https://m.abunchtell.com
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.
 
 
 
 

23 lines
936 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 }
  10. payload = Oj.dump(event: :'announcement.reaction', payload: payload)
  11. Account.joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).find_each 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