about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2020-01-26 20:07:26 +0100
committerGitHub <noreply@github.com>2020-01-26 20:07:26 +0100
commitb9d74d407673a6dbdc87c3310618b22c85358c85 (patch)
treeace3034da9a8d8973ccbbcf3532dee2f597a5364 /app/workers
parent408b3e2b9328f54d471deba346a182f7c8856676 (diff)
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
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/publish_announcement_reaction_worker.rb2
-rw-r--r--app/workers/publish_scheduled_announcement_worker.rb2
-rw-r--r--app/workers/unpublish_announcement_worker.rb14
3 files changed, 16 insertions, 2 deletions
diff --git a/app/workers/publish_announcement_reaction_worker.rb b/app/workers/publish_announcement_reaction_worker.rb
index e01deb64d..418dc7127 100644
--- a/app/workers/publish_announcement_reaction_worker.rb
+++ b/app/workers/publish_announcement_reaction_worker.rb
@@ -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
diff --git a/app/workers/publish_scheduled_announcement_worker.rb b/app/workers/publish_scheduled_announcement_worker.rb
index 4b2014e34..6b5898bf5 100644
--- a/app/workers/publish_scheduled_announcement_worker.rb
+++ b/app/workers/publish_scheduled_announcement_worker.rb
@@ -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
diff --git a/app/workers/unpublish_announcement_worker.rb b/app/workers/unpublish_announcement_worker.rb
new file mode 100644
index 000000000..e99d70cf8
--- /dev/null
+++ b/app/workers/unpublish_announcement_worker.rb
@@ -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