From 39e361a56d849a027ed12df69122a369bc6ff39d Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Sun, 12 Aug 2018 18:16:26 +0200 Subject: Expect relays to answer with accept/reject (#8179) --- app/lib/activitypub/activity/accept.rb | 14 ++++++++++++++ app/lib/activitypub/activity/reject.rb | 14 ++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'app/lib/activitypub/activity') diff --git a/app/lib/activitypub/activity/accept.rb b/app/lib/activitypub/activity/accept.rb index bd90c9019..7e60b2c00 100644 --- a/app/lib/activitypub/activity/accept.rb +++ b/app/lib/activitypub/activity/accept.rb @@ -11,6 +11,8 @@ class ActivityPub::Activity::Accept < ActivityPub::Activity private def accept_follow + return accept_follow_for_relay if relay_follow? + target_account = account_from_uri(target_uri) return if target_account.nil? || !target_account.local? @@ -19,6 +21,18 @@ class ActivityPub::Activity::Accept < ActivityPub::Activity follow_request&.authorize! end + def accept_follow_for_relay + relay.update!(state: :accepted) + end + + def relay + @relay ||= Relay.find_by(follow_activity_id: object_uri) + end + + def relay_follow? + relay.present? + end + def target_uri @target_uri ||= value_or_id(@object['actor']) end diff --git a/app/lib/activitypub/activity/reject.rb b/app/lib/activitypub/activity/reject.rb index 28d472883..d81b157de 100644 --- a/app/lib/activitypub/activity/reject.rb +++ b/app/lib/activitypub/activity/reject.rb @@ -11,6 +11,8 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity private def reject_follow + return reject_follow_for_relay if relay_follow? + target_account = account_from_uri(target_uri) return if target_account.nil? || !target_account.local? @@ -21,6 +23,18 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity UnfollowService.new.call(target_account, @account) if target_account.following?(@account) end + def reject_follow_for_relay + relay.update!(state: :rejected) + end + + def relay + @relay ||= Relay.find_by(follow_activity_id: object_uri) + end + + def relay_follow? + relay.present? + end + def target_uri @target_uri ||= value_or_id(@object['actor']) end -- cgit From 1ee675d68bfd2034183a03408a2377c338dfac41 Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 17 Aug 2018 14:08:17 +0200 Subject: Use correct activity id in Accept when receiving duplicate Follow (fixes #8218) (#8244) --- app/lib/activitypub/activity/follow.rb | 2 +- app/services/authorize_follow_service.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'app/lib/activitypub/activity') diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb index 826dcf18e..c45832648 100644 --- a/app/lib/activitypub/activity/follow.rb +++ b/app/lib/activitypub/activity/follow.rb @@ -13,7 +13,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity # Fast-forward repeat follow requests if @account.following?(target_account) - AuthorizeFollowService.new.call(@account, target_account, skip_follow_request: true) + AuthorizeFollowService.new.call(@account, target_account, skip_follow_request: true, follow_request_uri: @json['id']) return end diff --git a/app/services/authorize_follow_service.rb b/app/services/authorize_follow_service.rb index f47d488f1..1674239df 100644 --- a/app/services/authorize_follow_service.rb +++ b/app/services/authorize_follow_service.rb @@ -3,7 +3,7 @@ class AuthorizeFollowService < BaseService def call(source_account, target_account, **options) if options[:skip_follow_request] - follow_request = FollowRequest.new(account: source_account, target_account: target_account) + follow_request = FollowRequest.new(account: source_account, target_account: target_account, uri: options[:follow_request_uri]) else follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account) follow_request.authorize! -- cgit From 59f7f4c923494bb8dd6f2881a1610c7b51240d9c Mon Sep 17 00:00:00 2001 From: ThibG Date: Fri, 17 Aug 2018 16:24:56 +0200 Subject: Implement Undo { Accept { Follow } } (fixes #8234) (#8245) * Add Follow#revoke_request! * Implement Undo { Accept { Follow } } (fixes #8234) --- app/lib/activitypub/activity/undo.rb | 6 ++++++ app/models/follow.rb | 5 +++++ spec/lib/activitypub/activity/undo_spec.rb | 26 ++++++++++++++++++++++++++ spec/models/follow_spec.rb | 16 ++++++++++++++++ 4 files changed, 53 insertions(+) (limited to 'app/lib/activitypub/activity') diff --git a/app/lib/activitypub/activity/undo.rb b/app/lib/activitypub/activity/undo.rb index cbed417c4..64c2be7d9 100644 --- a/app/lib/activitypub/activity/undo.rb +++ b/app/lib/activitypub/activity/undo.rb @@ -5,6 +5,8 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity case @object['type'] when 'Announce' undo_announce + when 'Accept' + undo_accept when 'Follow' undo_follow when 'Like' @@ -27,6 +29,10 @@ class ActivityPub::Activity::Undo < ActivityPub::Activity end end + def undo_accept + ::Follow.find_by(target_account: @account, uri: target_uri)&.revoke_request! + end + def undo_follow target_account = account_from_uri(target_uri) diff --git a/app/models/follow.rb b/app/models/follow.rb index 3fce14b9a..714f4e898 100644 --- a/app/models/follow.rb +++ b/app/models/follow.rb @@ -32,6 +32,11 @@ class Follow < ApplicationRecord false # Force uri_for to use uri attribute end + def revoke_request! + FollowRequest.create!(account: account, target_account: target_account, show_reblogs: show_reblogs, uri: uri) + destroy! + end + before_validation :set_uri, only: :create after_destroy :remove_endorsements diff --git a/spec/lib/activitypub/activity/undo_spec.rb b/spec/lib/activitypub/activity/undo_spec.rb index e01c5e03e..9545e1f46 100644 --- a/spec/lib/activitypub/activity/undo_spec.rb +++ b/spec/lib/activitypub/activity/undo_spec.rb @@ -52,6 +52,32 @@ RSpec.describe ActivityPub::Activity::Undo do end end + context 'with Accept' do + let(:recipient) { Fabricate(:account) } + let(:object_json) do + { + id: 'bar', + type: 'Accept', + actor: ActivityPub::TagManager.instance.uri_for(sender), + object: 'follow-to-revoke', + } + end + + before do + recipient.follow!(sender, uri: 'follow-to-revoke') + end + + it 'deletes follow from recipient to sender' do + subject.perform + expect(recipient.following?(sender)).to be false + end + + it 'creates a follow request from recipient to sender' do + subject.perform + expect(recipient.requested?(sender)).to be true + end + end + context 'with Block' do let(:recipient) { Fabricate(:account) } diff --git a/spec/models/follow_spec.rb b/spec/models/follow_spec.rb index 43175d852..f221973b6 100644 --- a/spec/models/follow_spec.rb +++ b/spec/models/follow_spec.rb @@ -37,4 +37,20 @@ RSpec.describe Follow, type: :model do expect(a[1]).to eq follow0 end end + + describe 'revoke_request!' do + let(:follow) { Fabricate(:follow, account: account, target_account: target_account) } + let(:account) { Fabricate(:account) } + let(:target_account) { Fabricate(:account) } + + it 'revokes the follow relation' do + follow.revoke_request! + expect(account.following?(target_account)).to be false + end + + it 'creates a follow request' do + follow.revoke_request! + expect(account.requested?(target_account)).to be true + end + end end -- cgit