Skip to content

Commit 6e8a339

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Restore ReplyDistributionWorker to allow existing jobs to be processed (mastodon#9676)
1 parent 1c0c5d3 commit 6e8a339

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
# Obsolete but kept around to make sure existing jobs do not fail after upgrade.
4+
# Should be removed in a subsequent release.
5+
6+
class ActivityPub::ReplyDistributionWorker
7+
include Sidekiq::Worker
8+
9+
sidekiq_options queue: 'push'
10+
11+
def perform(status_id)
12+
@status = Status.find(status_id)
13+
@account = @status.thread&.account
14+
15+
return unless @account.present? && @status.distributable?
16+
17+
ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
18+
[payload, @status.account_id, inbox_url]
19+
end
20+
rescue ActiveRecord::RecordNotFound
21+
true
22+
end
23+
24+
private
25+
26+
def inboxes
27+
@inboxes ||= @account.followers.inboxes
28+
end
29+
30+
def signed_payload
31+
Oj.dump(ActivityPub::LinkedDataSignature.new(unsigned_payload).sign!(@status.account))
32+
end
33+
34+
def unsigned_payload
35+
ActiveModelSerializers::SerializableResource.new(
36+
@status,
37+
serializer: ActivityPub::ActivitySerializer,
38+
adapter: ActivityPub::Adapter
39+
).as_json
40+
end
41+
42+
def payload
43+
@payload ||= @status.distributable? ? signed_payload : Oj.dump(unsigned_payload)
44+
end
45+
end

0 commit comments

Comments
 (0)