2020-01-23 23:00:13 +02:00
# frozen_string_literal: true
class PublishAnnouncementReactionWorker
include Sidekiq :: Worker
include Redisable
def perform ( announcement_id , name )
announcement = Announcement . find ( announcement_id )
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' )
reaction || = announcement . announcement_reactions . new ( name : name )
2020-01-24 23:08:24 +02:00
payload = InlineRenderer . render ( reaction , nil , :reaction ) . tap { | h | h [ :announcement_id ] = announcement_id . to_s }
2020-01-23 23:00:13 +02:00
payload = Oj . dump ( event : :'announcement.reaction' , payload : payload )
2020-01-26 21:07:26 +02:00
FeedManager . instance . with_active_accounts do | account |
2020-07-01 20:05:21 +03:00
redis . publish ( " timeline: #{ account . id } " , payload ) if redis . exists? ( " subscribed:timeline: #{ account . id } " )
2020-01-23 23:00:13 +02:00
end
rescue ActiveRecord :: RecordNotFound
true
end
end