Resolve unknown status from Add activity, skip Remove if unknown (#7526)
Fix #7518
This commit is contained in:
parent
dafd7afc5e
commit
57b503d4ef
|
@ -118,4 +118,13 @@ class ActivityPub::Activity
|
|||
def delete_later!(uri)
|
||||
redis.setex("delete_upon_arrival:#{@account.id}:#{uri}", 6.hours.seconds, uri)
|
||||
end
|
||||
|
||||
def fetch_remote_original_status
|
||||
if object_uri.start_with?('http')
|
||||
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
|
||||
ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true, on_behalf_of: @account.followers.local.first)
|
||||
elsif @object['url'].present?
|
||||
::FetchRemoteStatusService.new.call(@object['url'])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,8 +5,9 @@ class ActivityPub::Activity::Add < ActivityPub::Activity
|
|||
return unless @json['target'].present? && value_or_id(@json['target']) == @account.featured_collection_url
|
||||
|
||||
status = status_from_uri(object_uri)
|
||||
status ||= fetch_remote_original_status
|
||||
|
||||
return unless status.account_id == @account.id && !@account.pinned?(status)
|
||||
return unless !status.nil? && status.account_id == @account.id && !@account.pinned?(status)
|
||||
|
||||
StatusPin.create!(account: @account, status: status)
|
||||
end
|
||||
|
|
|
@ -26,16 +26,6 @@ class ActivityPub::Activity::Announce < ActivityPub::Activity
|
|||
|
||||
private
|
||||
|
||||
def fetch_remote_original_status
|
||||
if object_uri.start_with?('http')
|
||||
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
|
||||
|
||||
ActivityPub::FetchRemoteStatusService.new.call(object_uri, id: true, on_behalf_of: @account.followers.local.first)
|
||||
elsif @object['url'].present?
|
||||
::FetchRemoteStatusService.new.call(@object['url'])
|
||||
end
|
||||
end
|
||||
|
||||
def announceable?(status)
|
||||
status.account_id == @account.id || status.public_visibility? || status.unlisted_visibility?
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ class ActivityPub::Activity::Remove < ActivityPub::Activity
|
|||
|
||||
status = status_from_uri(object_uri)
|
||||
|
||||
return unless status.account_id == @account.id
|
||||
return unless !status.nil? && status.account_id == @account.id
|
||||
|
||||
pin = StatusPin.find_by(account: @account, status: status)
|
||||
pin&.destroy!
|
||||
|
|
|
@ -18,12 +18,31 @@ RSpec.describe ActivityPub::Activity::Add do
|
|||
describe '#perform' do
|
||||
subject { described_class.new(json, sender) }
|
||||
|
||||
before do
|
||||
subject.perform
|
||||
end
|
||||
|
||||
it 'creates a pin' do
|
||||
subject.perform
|
||||
expect(sender.pinned?(status)).to be true
|
||||
end
|
||||
|
||||
context 'when status was not known before' do
|
||||
let(:json) do
|
||||
{
|
||||
'@context': 'https://www.w3.org/ns/activitystreams',
|
||||
id: 'foo',
|
||||
type: 'Add',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(sender),
|
||||
object: 'https://example.com/unknown',
|
||||
target: sender.featured_collection_url,
|
||||
}.with_indifferent_access
|
||||
end
|
||||
|
||||
before do
|
||||
stub_request(:get, 'https://example.com/unknown').to_return(status: 410)
|
||||
end
|
||||
|
||||
it 'fetches the status' do
|
||||
subject.perform
|
||||
expect(a_request(:get, 'https://example.com/unknown')).to have_been_made.at_least_once
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue