Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/services/activity_pub/accept_follow_service.rb')
-rw-r--r--app/services/activity_pub/accept_follow_service.rb55
1 files changed, 55 insertions, 0 deletions
diff --git a/app/services/activity_pub/accept_follow_service.rb b/app/services/activity_pub/accept_follow_service.rb
new file mode 100644
index 00000000000..0ec440fa972
--- /dev/null
+++ b/app/services/activity_pub/accept_follow_service.rb
@@ -0,0 +1,55 @@
+# frozen_string_literal: true
+
+module ActivityPub
+ class AcceptFollowService
+ MissingInboxURLError = Class.new(StandardError)
+
+ attr_reader :subscription, :actor
+
+ def initialize(subscription, actor)
+ @subscription = subscription
+ @actor = actor
+ end
+
+ def execute
+ return if subscription.accepted?
+ raise MissingInboxURLError unless subscription.subscriber_inbox_url.present?
+
+ upload_accept_activity
+ subscription.accepted!
+ end
+
+ private
+
+ def upload_accept_activity
+ body = Gitlab::Json::LimitedEncoder.encode(payload, limit: 1.megabyte)
+
+ begin
+ Gitlab::HTTP.post(subscription.subscriber_inbox_url, body: body, headers: headers)
+ rescue StandardError => e
+ raise ThirdPartyError, e.message
+ end
+ end
+
+ def payload
+ follow = subscription.payload.dup
+ follow.delete('@context')
+
+ {
+ '@context': 'https://www.w3.org/ns/activitystreams',
+ id: "#{actor}#follow/#{subscription.id}/accept",
+ type: 'Accept',
+ actor: actor,
+ object: follow
+ }
+ end
+
+ def headers
+ {
+ 'User-Agent' => "GitLab/#{Gitlab::VERSION}",
+ 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
+ 'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
+ }
+ end
+ end
+end