diff --git a/app/lib/activitypub/activity/announce.rb b/app/lib/activitypub/activity/announce.rb index 09fec28a080..c4da405c7fd 100644 --- a/app/lib/activitypub/activity/announce.rb +++ b/app/lib/activitypub/activity/announce.rb @@ -7,6 +7,10 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity return if original_status.nil? || delete_arrived_first?(@json['id']) + status = Status.find_by(account: @account, reblog: original_status) + + return status unless status.nil? + status = Status.create!(account: @account, reblog: original_status, uri: @json['id']) distribute(status) status diff --git a/app/lib/activitypub/activity/block.rb b/app/lib/activitypub/activity/block.rb index e6b6c837ba9..f630d5db2a2 100644 --- a/app/lib/activitypub/activity/block.rb +++ b/app/lib/activitypub/activity/block.rb @@ -4,7 +4,7 @@ class ActivityPub::Activity::Block < ActivityPub::Activity def perform target_account = account_from_uri(object_uri) - return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) + return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) || @account.blocking?(target_account) UnfollowService.new.call(target_account, @account) if target_account.following?(@account) @account.block!(target_account) diff --git a/app/lib/activitypub/activity/follow.rb b/app/lib/activitypub/activity/follow.rb index 3fb698d1d52..8adbbb9c33c 100644 --- a/app/lib/activitypub/activity/follow.rb +++ b/app/lib/activitypub/activity/follow.rb @@ -4,7 +4,13 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity def perform target_account = account_from_uri(object_uri) - return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) + return if target_account.nil? || !target_account.local? || delete_arrived_first?(@json['id']) || @account.requested?(target_account) + + # Fast-forward repeat follow requests + if @account.following?(target_account) + AuthorizeFollowService.new.call(@account, target_account, skip_follow_request: true) + return + end follow_request = FollowRequest.create!(account: @account, target_account: target_account) diff --git a/app/lib/activitypub/activity/like.rb b/app/lib/activitypub/activity/like.rb index c24527597f0..674d5fe4723 100644 --- a/app/lib/activitypub/activity/like.rb +++ b/app/lib/activitypub/activity/like.rb @@ -4,9 +4,9 @@ class ActivityPub::Activity::Like < ActivityPub::Activity def perform original_status = status_from_uri(object_uri) - return if original_status.nil? || !original_status.account.local? || delete_arrived_first?(@json['id']) + return if original_status.nil? || !original_status.account.local? || delete_arrived_first?(@json['id']) || @account.favourited?(original_status) - favourite = original_status.favourites.where(account: @account).first_or_create!(account: @account) + favourite = original_status.favourites.create!(account: @account) NotifyService.new.call(original_status.account, favourite) end end diff --git a/app/services/authorize_follow_service.rb b/app/services/authorize_follow_service.rb index db35b6030bd..6f036dc5a6c 100644 --- a/app/services/authorize_follow_service.rb +++ b/app/services/authorize_follow_service.rb @@ -1,9 +1,14 @@ # frozen_string_literal: true class AuthorizeFollowService < BaseService - def call(source_account, target_account) - follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account) - follow_request.authorize! + def call(source_account, target_account, options = {}) + if options[:skip_follow_request] + follow_request = FollowRequest.new(account: source_account, target_account: target_account) + else + follow_request = FollowRequest.find_by!(account: source_account, target_account: target_account) + follow_request.authorize! + end + create_notification(follow_request) unless source_account.local? follow_request end