From fbf08920a0d73231c04b35c263ea4e04224b6e7d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Tue, 4 Jun 2019 23:11:18 +0200 Subject: Refactor all ActivityPub deliveries to be serialized and signed through one concern (#10966) --- app/workers/activitypub/distribute_poll_update_worker.rb | 15 ++------------- app/workers/activitypub/distribution_worker.rb | 15 ++------------- app/workers/activitypub/reply_distribution_worker.rb | 15 ++------------- app/workers/activitypub/update_distribution_worker.rb | 11 ++--------- 4 files changed, 8 insertions(+), 48 deletions(-) (limited to 'app/workers') diff --git a/app/workers/activitypub/distribute_poll_update_worker.rb b/app/workers/activitypub/distribute_poll_update_worker.rb index 310e42433..57379768f 100644 --- a/app/workers/activitypub/distribute_poll_update_worker.rb +++ b/app/workers/activitypub/distribute_poll_update_worker.rb @@ -2,6 +2,7 @@ class ActivityPub::DistributePollUpdateWorker include Sidekiq::Worker + include Payloadable sidekiq_options queue: 'push', unique: :until_executed, retry: 0 @@ -41,20 +42,8 @@ class ActivityPub::DistributePollUpdateWorker @inboxes end - def signed_payload - Oj.dump(ActivityPub::LinkedDataSignature.new(unsigned_payload).sign!(@account)) - end - - def unsigned_payload - ActiveModelSerializers::SerializableResource.new( - @status, - serializer: ActivityPub::UpdatePollSerializer, - adapter: ActivityPub::Adapter - ).as_json - end - def payload - @payload ||= @status.distributable? ? signed_payload : Oj.dump(unsigned_payload) + @payload ||= Oj.dump(serialize_payload(@status, ActivityPub::UpdatePollSerializer, signer: @account)) end def relay! diff --git a/app/workers/activitypub/distribution_worker.rb b/app/workers/activitypub/distribution_worker.rb index d83f01700..11b6a6111 100644 --- a/app/workers/activitypub/distribution_worker.rb +++ b/app/workers/activitypub/distribution_worker.rb @@ -2,6 +2,7 @@ class ActivityPub::DistributionWorker include Sidekiq::Worker + include Payloadable sidekiq_options queue: 'push' @@ -41,20 +42,8 @@ class ActivityPub::DistributionWorker end end - def signed_payload - Oj.dump(ActivityPub::LinkedDataSignature.new(unsigned_payload).sign!(@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) + @payload ||= Oj.dump(serialize_payload(@status, ActivityPub::ActivitySerializer, signer: @account)) end def relay! diff --git a/app/workers/activitypub/reply_distribution_worker.rb b/app/workers/activitypub/reply_distribution_worker.rb index d8fea6c4e..1ff8a657e 100644 --- a/app/workers/activitypub/reply_distribution_worker.rb +++ b/app/workers/activitypub/reply_distribution_worker.rb @@ -5,6 +5,7 @@ class ActivityPub::ReplyDistributionWorker include Sidekiq::Worker + include Payloadable sidekiq_options queue: 'push' @@ -27,19 +28,7 @@ class ActivityPub::ReplyDistributionWorker @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) + @payload ||= Oj.dump(serialize_payload(@status, ActivityPub::ActivitySerializer, signer: @status.account)) end end diff --git a/app/workers/activitypub/update_distribution_worker.rb b/app/workers/activitypub/update_distribution_worker.rb index b9e5ff064..3a207f071 100644 --- a/app/workers/activitypub/update_distribution_worker.rb +++ b/app/workers/activitypub/update_distribution_worker.rb @@ -2,6 +2,7 @@ class ActivityPub::UpdateDistributionWorker include Sidekiq::Worker + include Payloadable sidekiq_options queue: 'push' @@ -27,14 +28,6 @@ class ActivityPub::UpdateDistributionWorker end def signed_payload - @signed_payload ||= Oj.dump(ActivityPub::LinkedDataSignature.new(payload).sign!(@account, sign_with: @options[:sign_with])) - end - - def payload - @payload ||= ActiveModelSerializers::SerializableResource.new( - @account, - serializer: ActivityPub::UpdateSerializer, - adapter: ActivityPub::Adapter - ).as_json + @signed_payload ||= Oj.dump(serialize_payload(@account, ActivityPub::UpdateSerializer, signer: @account, sign_with: @options[:sign_with])) end end -- cgit