diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-06-04 23:11:18 +0200 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-11-19 16:32:36 -0600 |
commit | fbf08920a0d73231c04b35c263ea4e04224b6e7d (patch) | |
tree | afc2717ba1e5b121d170d0d5adc5236cf73f78dd /app/workers | |
parent | 82bd234c3cb4aed81ab4e4c8844bd27d065ea4d9 (diff) |
Refactor all ActivityPub deliveries to be serialized and signed through one concern (#10966)
Diffstat (limited to 'app/workers')
4 files changed, 8 insertions, 48 deletions
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 |