Fix Undo Announce activity is not sent, when not followed by the reblogged post author (#18482)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
		@@ -16,28 +16,28 @@ class StatusReachFinder
 | 
				
			|||||||
  private
 | 
					  private
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def reached_account_inboxes
 | 
					  def reached_account_inboxes
 | 
				
			||||||
 | 
					    Account.where(id: reached_account_ids).inboxes
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  def reached_account_ids
 | 
				
			||||||
    # When the status is a reblog, there are no interactions with it
 | 
					    # When the status is a reblog, there are no interactions with it
 | 
				
			||||||
    # directly, we assume all interactions are with the original one
 | 
					    # directly, we assume all interactions are with the original one
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if @status.reblog?
 | 
					    if @status.reblog?
 | 
				
			||||||
      []
 | 
					      [reblog_of_account_id]
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
      Account.where(id: reached_account_ids).inboxes
 | 
					      [
 | 
				
			||||||
    end
 | 
					        replied_to_account_id,
 | 
				
			||||||
  end
 | 
					        reblog_of_account_id,
 | 
				
			||||||
 | 
					        mentioned_account_ids,
 | 
				
			||||||
  def reached_account_ids
 | 
					        reblogs_account_ids,
 | 
				
			||||||
    [
 | 
					        favourites_account_ids,
 | 
				
			||||||
      replied_to_account_id,
 | 
					        replies_account_ids,
 | 
				
			||||||
      reblog_of_account_id,
 | 
					      ].tap do |arr|
 | 
				
			||||||
      mentioned_account_ids,
 | 
					        arr.flatten!
 | 
				
			||||||
      reblogs_account_ids,
 | 
					        arr.compact!
 | 
				
			||||||
      favourites_account_ids,
 | 
					        arr.uniq!
 | 
				
			||||||
      replies_account_ids,
 | 
					      end
 | 
				
			||||||
    ].tap do |arr|
 | 
					 | 
				
			||||||
      arr.flatten!
 | 
					 | 
				
			||||||
      arr.compact!
 | 
					 | 
				
			||||||
      arr.uniq!
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -43,11 +43,7 @@ class ReblogService < BaseService
 | 
				
			|||||||
  def create_notification(reblog)
 | 
					  def create_notification(reblog)
 | 
				
			||||||
    reblogged_status = reblog.reblog
 | 
					    reblogged_status = reblog.reblog
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if reblogged_status.account.local?
 | 
					    LocalNotificationWorker.perform_async(reblogged_status.account_id, reblog.id, reblog.class.name, 'reblog') if reblogged_status.account.local?
 | 
				
			||||||
      LocalNotificationWorker.perform_async(reblogged_status.account_id, reblog.id, reblog.class.name, 'reblog')
 | 
					 | 
				
			||||||
    elsif reblogged_status.account.activitypub? && !reblogged_status.account.following?(reblog.account)
 | 
					 | 
				
			||||||
      ActivityPub::DeliveryWorker.perform_async(build_json(reblog), reblog.account_id, reblogged_status.account.inbox_url)
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def increment_statistics
 | 
					  def increment_statistics
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -112,6 +112,14 @@ RSpec.describe ActivityPub::TagManager do
 | 
				
			|||||||
      expect(subject.cc(status)).to include(subject.uri_for(foo))
 | 
					      expect(subject.cc(status)).to include(subject.uri_for(foo))
 | 
				
			||||||
      expect(subject.cc(status)).to_not include(subject.uri_for(alice))
 | 
					      expect(subject.cc(status)).to_not include(subject.uri_for(alice))
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it 'returns poster of reblogged post, if reblog' do
 | 
				
			||||||
 | 
					      bob    = Fabricate(:account, username: 'bob', domain: 'example.com', inbox_url: 'http://example.com/bob')
 | 
				
			||||||
 | 
					      alice  = Fabricate(:account, username: 'alice')
 | 
				
			||||||
 | 
					      status = Fabricate(:status, visibility: :public, account: bob)
 | 
				
			||||||
 | 
					      reblog = Fabricate(:status, visibility: :public, account: alice, reblog: status)
 | 
				
			||||||
 | 
					      expect(subject.cc(reblog)).to include(subject.uri_for(bob))
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe '#local_uri?' do
 | 
					  describe '#local_uri?' do
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,9 +86,5 @@ RSpec.describe ReblogService, type: :service do
 | 
				
			|||||||
    it 'distributes to followers' do
 | 
					    it 'distributes to followers' do
 | 
				
			||||||
      expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
 | 
					      expect(ActivityPub::DistributionWorker).to have_received(:perform_async)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					 | 
				
			||||||
    it 'sends an announce activity to the author', :sidekiq_inline do
 | 
					 | 
				
			||||||
      expect(a_request(:post, bob.inbox_url)).to have_been_made.once
 | 
					 | 
				
			||||||
    end
 | 
					 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -116,4 +116,22 @@ RSpec.describe RemoveStatusService, :sidekiq_inline, type: :service do
 | 
				
			|||||||
             )).to have_been_made.once
 | 
					             )).to have_been_made.once
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  context 'when removed status is a reblog of a non-follower' do
 | 
				
			||||||
 | 
					    let!(:original_status) { Fabricate(:status, account: bill, text: 'Hello ThisIsASecret', visibility: :public) }
 | 
				
			||||||
 | 
					    let!(:status) { ReblogService.new.call(alice, original_status) }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it 'sends Undo activity to followers' do
 | 
				
			||||||
 | 
					      subject.call(status)
 | 
				
			||||||
 | 
					      expect(a_request(:post, bill.inbox_url).with(
 | 
				
			||||||
 | 
					               body: hash_including({
 | 
				
			||||||
 | 
					                 'type' => 'Undo',
 | 
				
			||||||
 | 
					                 'object' => hash_including({
 | 
				
			||||||
 | 
					                   'type' => 'Announce',
 | 
				
			||||||
 | 
					                   'object' => ActivityPub::TagManager.instance.uri_for(original_status),
 | 
				
			||||||
 | 
					                 }),
 | 
				
			||||||
 | 
					               })
 | 
				
			||||||
 | 
					             )).to have_been_made.once
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user