about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-01-01 13:43:11 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-01-01 13:43:11 +0100
commit1d4215be777afde86208059e3eacf615533bc734 (patch)
treefb6e45ebc34a66720eef70a07f0e19729662a18b /app
parentea03faa167ba332b26ee26730e0d5466ca262ab2 (diff)
Restore ReplyDistributionWorker to allow existing jobs to be processed (#9676)
Diffstat (limited to 'app')
-rw-r--r--app/workers/activitypub/reply_distribution_worker.rb45
1 files changed, 45 insertions, 0 deletions
diff --git a/app/workers/activitypub/reply_distribution_worker.rb b/app/workers/activitypub/reply_distribution_worker.rb
new file mode 100644
index 000000000..d8fea6c4e
--- /dev/null
+++ b/app/workers/activitypub/reply_distribution_worker.rb
@@ -0,0 +1,45 @@
+# frozen_string_literal: true
+
+# Obsolete but kept around to make sure existing jobs do not fail after upgrade.
+# Should be removed in a subsequent release.
+
+class ActivityPub::ReplyDistributionWorker
+  include Sidekiq::Worker
+
+  sidekiq_options queue: 'push'
+
+  def perform(status_id)
+    @status  = Status.find(status_id)
+    @account = @status.thread&.account
+
+    return unless @account.present? && @status.distributable?
+
+    ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
+      [payload, @status.account_id, inbox_url]
+    end
+  rescue ActiveRecord::RecordNotFound
+    true
+  end
+
+  private
+
+  def inboxes
+    @inboxes ||= @account.followers.inboxes
+  end
+
+  def signed_payload
+    Oj.dump(ActivityPub::LinkedDataSignature.new(unsigned_payload).sign!(@status.account))
+  end
+
+  def unsigned_payload
+    ActiveModelSerializers::SerializableResource.new(
+      @status,
+      serializer: ActivityPub::ActivitySerializer,
+      adapter: ActivityPub::Adapter
+    ).as_json
+  end
+
+  def payload
+    @payload ||= @status.distributable? ? signed_payload : Oj.dump(unsigned_payload)
+  end
+end