Skip to content

Commit

Permalink
Reject existing Follow in addition to sending a Block (mastodon#9811)
Browse files Browse the repository at this point in the history
Mastodon expects remote servers to remove follow relationships upon receiving
a Block. However, the spec only evokes Block activities in a C2S context, never
in a S2S context.

This PR, in addition to federating the Block, explicitly sends a Reject for any
affected follow relationship, which makes a bit more sense with regards to the
spec.
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent df8caf8 commit 2e367f9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/services/unfollow_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def unfollow!

follow.destroy!
create_notification(follow) unless @target_account.local?
create_reject_notification(follow) if @target_account.local? && !@source_account.local?
UnmergeWorker.perform_async(@target_account.id, @source_account.id)
follow
end
Expand All @@ -42,6 +43,12 @@ def create_notification(follow)
end
end

def create_reject_notification(follow)
# Rejecting an already-existing follow request
return unless follow.account.activitypub?
ActivityPub::DeliveryWorker.perform_async(build_reject_json(follow), follow.target_account_id, follow.account.inbox_url)
end

def build_json(follow)
ActiveModelSerializers::SerializableResource.new(
follow,
Expand All @@ -50,6 +57,14 @@ def build_json(follow)
).to_json
end

def build_reject_json(follow)
ActiveModelSerializers::SerializableResource.new(
follow,
serializer: ActivityPub::RejectFollowSerializer,
adapter: ActivityPub::Adapter
).to_json
end

def build_xml(follow)
OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.unfollow_salmon(follow))
end
Expand Down
18 changes: 18 additions & 0 deletions spec/services/unfollow_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,22 @@
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
end
end

describe 'remote ActivityPub (reverse)' do
let(:bob) { Fabricate(:user, email: 'bob@example.com', account: Fabricate(:account, username: 'bob', protocol: :activitypub, domain: 'example.com', inbox_url: 'http://example.com/inbox')).account }

before do
bob.follow!(sender)
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
subject.call(bob, sender)
end

it 'destroys the following relation' do
expect(bob.following?(sender)).to be false
end

it 'sends a reject activity' do
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made.once
end
end
end

0 comments on commit 2e367f9

Please sign in to comment.