mirror of
https://github.com/mastodon/mastodon.git
synced 2026-03-21 18:05:23 -05:00
Handle Reject of a FeatureRequest (#38256)
This commit is contained in:
parent
90840b3ede
commit
f3035a8e51
|
|
@ -167,6 +167,12 @@ class ActivityPub::Activity
|
|||
@follow_from_object ||= ::Follow.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
|
||||
end
|
||||
|
||||
def feature_request_from_object
|
||||
return @collection_item if instance_variable_defined?(:@collection_item)
|
||||
|
||||
@collection_item = CollectionItem.local.find_by(activity_uri: value_or_id(@object), account_id: @account.id)
|
||||
end
|
||||
|
||||
def fetch_remote_original_status
|
||||
if object_uri.start_with?('http')
|
||||
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
|
||||
|
|
|
|||
|
|
@ -84,10 +84,4 @@ class ActivityPub::Activity::Accept < ActivityPub::Activity
|
|||
def target_uri
|
||||
@target_uri ||= value_or_id(@object['actor'])
|
||||
end
|
||||
|
||||
def feature_request_from_object
|
||||
return @collection_item if instance_variable_defined?(:@collection_item)
|
||||
|
||||
@collection_item = CollectionItem.local.find_by(activity_uri: value_or_id(@object), account_id: @account.id)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity
|
|||
return follow_request_from_object.reject! unless follow_request_from_object.nil?
|
||||
return UnfollowService.new.call(follow_from_object.account, @account) unless follow_from_object.nil?
|
||||
return reject_quote!(quote_request_from_object) unless quote_request_from_object.nil?
|
||||
return reject_feature_request! unless feature_request_from_object.nil?
|
||||
|
||||
case @object['type']
|
||||
when 'Follow'
|
||||
|
|
@ -46,6 +47,13 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity
|
|||
quote.reject!
|
||||
end
|
||||
|
||||
def reject_feature_request!
|
||||
collection_item = feature_request_from_object
|
||||
return unless collection_item.account == @account && collection_item.local?
|
||||
|
||||
collection_item.destroy!
|
||||
end
|
||||
|
||||
def relay
|
||||
@relay ||= Relay.find_by(follow_activity_id: object_uri) unless object_uri.nil?
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::Activity::Reject do
|
||||
let(:sender) { Fabricate(:account) }
|
||||
let(:sender) { Fabricate(:remote_account) }
|
||||
let(:recipient) { Fabricate(:account) }
|
||||
|
||||
let(:json) do
|
||||
|
|
@ -129,12 +129,12 @@ RSpec.describe ActivityPub::Activity::Reject do
|
|||
context 'with a QuoteRequest' do
|
||||
let(:status) { Fabricate(:status, account: recipient) }
|
||||
let(:quoted_status) { Fabricate(:status, account: sender) }
|
||||
let(:quote) { Fabricate(:quote, status: status, quoted_status: quoted_status, activity_uri: 'https://abc-123/456') }
|
||||
let!(:quote) { Fabricate(:quote, status: status, quoted_status: quoted_status) }
|
||||
let(:approval_uri) { "https://#{sender.domain}/approvals/1" }
|
||||
|
||||
let(:object_json) do
|
||||
{
|
||||
id: 'https://abc-123/456',
|
||||
id: quote.activity_uri,
|
||||
type: 'QuoteRequest',
|
||||
actor: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
object: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
||||
|
|
@ -147,5 +147,23 @@ RSpec.describe ActivityPub::Activity::Reject do
|
|||
.to change { quote.reload.rejected? }.from(false).to(true)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with a FeatureRequest' do
|
||||
let(:collection) { Fabricate(:collection, account: recipient) }
|
||||
let!(:collection_item) { Fabricate(:collection_item, collection:, account: sender, state: :pending) }
|
||||
let(:json) do
|
||||
{
|
||||
'id' => 'https://example.com/accepts/1',
|
||||
'type' => 'Accept',
|
||||
'actor' => sender.uri,
|
||||
'to' => ActivityPub::TagManager.instance.uri_for(recipient),
|
||||
'object' => collection_item.activity_uri,
|
||||
}
|
||||
end
|
||||
|
||||
it 'deletes the collection item' do
|
||||
expect { subject.perform }.to change(collection.collection_items, :count).by(-1)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user