gearheads
/
mastodon
Archived
2
0
Fork 0

Handle duplicate ActivityPub activities (#4639)

* Handle duplicate ActivityPub activities

Only perform side-effects when record processed for the first time

* Fast-forward repeat follow requests
gh/stable
Eugen Rochko 2017-08-20 16:53:47 +02:00 committed by GitHub
parent 93d4192a67
commit fe5b66aa08
5 changed files with 22 additions and 7 deletions

View File

@ -7,6 +7,10 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
return if original_status.nil? || delete_arrived_first?(@json['id']) 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']) status = Status.create!(account: @account, reblog: original_status, uri: @json['id'])
distribute(status) distribute(status)
status status

View File

@ -4,7 +4,7 @@ class ActivityPub::Activity::Block < ActivityPub::Activity
def perform def perform
target_account = account_from_uri(object_uri) 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) UnfollowService.new.call(target_account, @account) if target_account.following?(@account)
@account.block!(target_account) @account.block!(target_account)

View File

@ -4,7 +4,13 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
def perform def perform
target_account = account_from_uri(object_uri) 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) follow_request = FollowRequest.create!(account: @account, target_account: target_account)

View File

@ -4,9 +4,9 @@ class ActivityPub::Activity::Like < ActivityPub::Activity
def perform def perform
original_status = status_from_uri(object_uri) 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) NotifyService.new.call(original_status.account, favourite)
end end
end end

View File

@ -1,9 +1,14 @@
# frozen_string_literal: true # frozen_string_literal: true
class AuthorizeFollowService < BaseService class AuthorizeFollowService < BaseService
def call(source_account, target_account) 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 = FollowRequest.find_by!(account: source_account, target_account: target_account)
follow_request.authorize! follow_request.authorize!
end
create_notification(follow_request) unless source_account.local? create_notification(follow_request) unless source_account.local?
follow_request follow_request
end end