@@ -56,11 +56,10 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
 | 
				
			|||||||
    process_audience
 | 
					    process_audience
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ApplicationRecord.transaction do
 | 
					    ApplicationRecord.transaction do
 | 
				
			||||||
      @status = Status.create!(@params)
 | 
					      @status = Status.create!(@params.merge(quote: @quote))
 | 
				
			||||||
      attach_tags(@status)
 | 
					      attach_tags(@status)
 | 
				
			||||||
      attach_mentions(@status)
 | 
					      attach_mentions(@status)
 | 
				
			||||||
      attach_counts(@status)
 | 
					      attach_counts(@status)
 | 
				
			||||||
      attach_quote(@status)
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    resolve_thread(@status)
 | 
					    resolve_thread(@status)
 | 
				
			||||||
@@ -202,13 +201,6 @@ class ActivityPub::Activity::Create < ActivityPub::Activity
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def attach_quote(status)
 | 
					 | 
				
			||||||
    return if @quote.nil?
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @quote.status = status
 | 
					 | 
				
			||||||
    @quote.save
 | 
					 | 
				
			||||||
  end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  def process_tags
 | 
					  def process_tags
 | 
				
			||||||
    return if @object['tag'].nil?
 | 
					    return if @object['tag'].nil?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -106,7 +106,7 @@ class Status < ApplicationRecord
 | 
				
			|||||||
  has_one :quote, inverse_of: :status, dependent: :destroy
 | 
					  has_one :quote, inverse_of: :status, dependent: :destroy
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  validates :uri, uniqueness: true, presence: true, unless: :local?
 | 
					  validates :uri, uniqueness: true, presence: true, unless: :local?
 | 
				
			||||||
  validates :text, presence: true, unless: -> { with_media? || reblog? }
 | 
					  validates :text, presence: true, unless: -> { with_media? || reblog? || with_quote? }
 | 
				
			||||||
  validates_with StatusLengthValidator
 | 
					  validates_with StatusLengthValidator
 | 
				
			||||||
  validates_with DisallowedHashtagsValidator
 | 
					  validates_with DisallowedHashtagsValidator
 | 
				
			||||||
  validates :reblog, uniqueness: { scope: :account }, if: :reblog?
 | 
					  validates :reblog, uniqueness: { scope: :account }, if: :reblog?
 | 
				
			||||||
@@ -256,6 +256,10 @@ class Status < ApplicationRecord
 | 
				
			|||||||
    ordered_media_attachments.any?
 | 
					    ordered_media_attachments.any?
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def with_quote?
 | 
				
			||||||
 | 
					    quote.present?
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def with_preview_card?
 | 
					  def with_preview_card?
 | 
				
			||||||
    preview_cards_status.present?
 | 
					    preview_cards_status.present?
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -887,6 +887,33 @@ RSpec.describe ActivityPub::Activity::Create do
 | 
				
			|||||||
        end
 | 
					        end
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      context 'with an unverifiable quote of a known post, with summary (CW) but no text' do
 | 
				
			||||||
 | 
					        let(:quoted_status) { Fabricate(:status, account: Fabricate(:account, domain: 'example.com')) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        let(:object_json) do
 | 
				
			||||||
 | 
					          build_object(
 | 
				
			||||||
 | 
					            type: 'Note',
 | 
				
			||||||
 | 
					            summary: 'beware of what she said',
 | 
				
			||||||
 | 
					            content: nil,
 | 
				
			||||||
 | 
					            quote: ActivityPub::TagManager.instance.uri_for(quoted_status)
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        it 'creates a status with an unverified quote' do
 | 
				
			||||||
 | 
					          expect { subject.perform }.to change(sender.statuses, :count).by(1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          status = sender.statuses.first
 | 
				
			||||||
 | 
					          expect(status).to_not be_nil
 | 
				
			||||||
 | 
					          expect(status.spoiler_text).to eq 'beware of what she said'
 | 
				
			||||||
 | 
					          expect(status.content).to eq ''
 | 
				
			||||||
 | 
					          expect(status.quote).to_not be_nil
 | 
				
			||||||
 | 
					          expect(status.quote).to have_attributes(
 | 
				
			||||||
 | 
					            state: 'pending',
 | 
				
			||||||
 | 
					            approval_uri: nil
 | 
				
			||||||
 | 
					          )
 | 
				
			||||||
 | 
					        end
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      context 'with an unverifiable quote of a known post' do
 | 
					      context 'with an unverifiable quote of a known post' do
 | 
				
			||||||
        let(:quoted_status) { Fabricate(:status) }
 | 
					        let(:quoted_status) { Fabricate(:status) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -600,6 +600,39 @@ RSpec.describe ActivityPub::ProcessStatusUpdateService do
 | 
				
			|||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  context 'when the status keeps an unverifiable quote and removes text through an explicit update' do
 | 
				
			||||||
 | 
					    let(:quoted_account) { Fabricate(:account, domain: 'quoted.example.com') }
 | 
				
			||||||
 | 
					    let(:quoted_status) { Fabricate(:status, account: quoted_account) }
 | 
				
			||||||
 | 
					    let!(:quote) { Fabricate(:quote, status: status, quoted_status: quoted_status) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    let(:payload) do
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        '@context': [
 | 
				
			||||||
 | 
					          'https://www.w3.org/ns/activitystreams',
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            '@id': 'https://w3id.org/fep/044f#quote',
 | 
				
			||||||
 | 
					            '@type': '@id',
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					          {
 | 
				
			||||||
 | 
					            '@id': 'https://w3id.org/fep/044f#quoteAuthorization',
 | 
				
			||||||
 | 
					            '@type': '@id',
 | 
				
			||||||
 | 
					          },
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
 | 
					        id: 'foo',
 | 
				
			||||||
 | 
					        type: 'Note',
 | 
				
			||||||
 | 
					        summary: 'Show more',
 | 
				
			||||||
 | 
					        updated: '2021-09-08T22:39:25Z',
 | 
				
			||||||
 | 
					        quote: ActivityPub::TagManager.instance.uri_for(quoted_status),
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it 'updates the approval URI but does not verify the quote' do
 | 
				
			||||||
 | 
					      expect { subject.call(status, json, json) }
 | 
				
			||||||
 | 
					        .to change(status, :text).to('')
 | 
				
			||||||
 | 
					        .and not_change(quote, :state).from('pending')
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  context 'when the status has an existing verified quote and removes an approval link through an explicit update' do
 | 
					  context 'when the status has an existing verified quote and removes an approval link through an explicit update' do
 | 
				
			||||||
    let(:quoted_account) { Fabricate(:account, domain: 'quoted.example.com') }
 | 
					    let(:quoted_account) { Fabricate(:account, domain: 'quoted.example.com') }
 | 
				
			||||||
    let(:quoted_status) { Fabricate(:status, account: quoted_account) }
 | 
					    let(:quoted_status) { Fabricate(:status, account: quoted_account) }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user