Add streaming API updates for announcements being modified or deleted (#12963)

Change `all_day` to be a visual client-side cue only

Publish immediately if `scheduled_at` is in the past

Add `published_at` and `updated_at` to announcements JSON
This commit is contained in:
Eugen Rochko
2020-01-26 20:07:26 +01:00
committed by GitHub
parent 408b3e2b93
commit b9d74d4076
12 changed files with 100 additions and 41 deletions

View File

@ -13,7 +13,7 @@ class PublishAnnouncementReactionWorker
payload = InlineRenderer.render(reaction, nil, :reaction).tap { |h| h[:announcement_id] = announcement_id.to_s }
payload = Oj.dump(event: :'announcement.reaction', payload: payload)
Account.joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).find_each do |account|
FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
end
rescue ActiveRecord::RecordNotFound

View File

@ -11,7 +11,7 @@ class PublishScheduledAnnouncementWorker
payload = InlineRenderer.render(announcement, nil, :announcement)
payload = Oj.dump(event: :announcement, payload: payload)
Account.joins(:user).where('users.current_sign_in_at > ?', User::ACTIVE_DURATION.ago).find_each do |account|
FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
end
end

View File

@ -0,0 +1,14 @@
# frozen_string_literal: true
class UnpublishAnnouncementWorker
include Sidekiq::Worker
include Redisable
def perform(announcement_id)
payload = Oj.dump(event: :'announcement.delete', payload: announcement_id.to_s)
FeedManager.instance.with_active_accounts do |account|
redis.publish("timeline:#{account.id}", payload) if redis.exists("subscribed:timeline:#{account.id}")
end
end
end