Handle Reject of a FeatureRequest (#38256)
This commit is contained in:
@@ -167,6 +167,12 @@ class ActivityPub::Activity
|
|||||||
@follow_from_object ||= ::Follow.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
|
@follow_from_object ||= ::Follow.find_by(target_account: @account, uri: object_uri) unless object_uri.nil?
|
||||||
end
|
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
|
def fetch_remote_original_status
|
||||||
if object_uri.start_with?('http')
|
if object_uri.start_with?('http')
|
||||||
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
|
return if ActivityPub::TagManager.instance.local_uri?(object_uri)
|
||||||
|
|||||||
@@ -84,10 +84,4 @@ class ActivityPub::Activity::Accept < ActivityPub::Activity
|
|||||||
def target_uri
|
def target_uri
|
||||||
@target_uri ||= value_or_id(@object['actor'])
|
@target_uri ||= value_or_id(@object['actor'])
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity
|
|||||||
return follow_request_from_object.reject! unless follow_request_from_object.nil?
|
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 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_quote!(quote_request_from_object) unless quote_request_from_object.nil?
|
||||||
|
return reject_feature_request! unless feature_request_from_object.nil?
|
||||||
|
|
||||||
case @object['type']
|
case @object['type']
|
||||||
when 'Follow'
|
when 'Follow'
|
||||||
@@ -46,6 +47,13 @@ class ActivityPub::Activity::Reject < ActivityPub::Activity
|
|||||||
quote.reject!
|
quote.reject!
|
||||||
end
|
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
|
def relay
|
||||||
@relay ||= Relay.find_by(follow_activity_id: object_uri) unless object_uri.nil?
|
@relay ||= Relay.find_by(follow_activity_id: object_uri) unless object_uri.nil?
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
RSpec.describe ActivityPub::Activity::Reject do
|
RSpec.describe ActivityPub::Activity::Reject do
|
||||||
let(:sender) { Fabricate(:account) }
|
let(:sender) { Fabricate(:remote_account) }
|
||||||
let(:recipient) { Fabricate(:account) }
|
let(:recipient) { Fabricate(:account) }
|
||||||
|
|
||||||
let(:json) do
|
let(:json) do
|
||||||
@@ -129,12 +129,12 @@ RSpec.describe ActivityPub::Activity::Reject do
|
|||||||
context 'with a QuoteRequest' do
|
context 'with a QuoteRequest' do
|
||||||
let(:status) { Fabricate(:status, account: recipient) }
|
let(:status) { Fabricate(:status, account: recipient) }
|
||||||
let(:quoted_status) { Fabricate(:status, account: sender) }
|
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(:approval_uri) { "https://#{sender.domain}/approvals/1" }
|
||||||
|
|
||||||
let(:object_json) do
|
let(:object_json) do
|
||||||
{
|
{
|
||||||
id: 'https://abc-123/456',
|
id: quote.activity_uri,
|
||||||
type: 'QuoteRequest',
|
type: 'QuoteRequest',
|
||||||
actor: ActivityPub::TagManager.instance.uri_for(recipient),
|
actor: ActivityPub::TagManager.instance.uri_for(recipient),
|
||||||
object: ActivityPub::TagManager.instance.uri_for(quoted_status),
|
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)
|
.to change { quote.reload.rejected? }.from(false).to(true)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user