Add support for editing for published statuses (#16697)
* Add support for editing for published statuses * Fix references to stripped-out code * Various fixes and improvements * Further fixes and improvements * Fix updates being potentially sent to unauthorized recipients * Various fixes and improvements * Fix wrong words in test * Fix notifying accounts that were tagged but were not in the audience * Fix mistake
This commit is contained in:
		@@ -1,54 +1,32 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
class ActivityPub::DistributionWorker
 | 
			
		||||
  include Sidekiq::Worker
 | 
			
		||||
  include Payloadable
 | 
			
		||||
 | 
			
		||||
  sidekiq_options queue: 'push'
 | 
			
		||||
 | 
			
		||||
class ActivityPub::DistributionWorker < ActivityPub::RawDistributionWorker
 | 
			
		||||
  # Distribute a new status or an edit of a status to all the places
 | 
			
		||||
  # where the status is supposed to go or where it was interacted with
 | 
			
		||||
  def perform(status_id)
 | 
			
		||||
    @status  = Status.find(status_id)
 | 
			
		||||
    @account = @status.account
 | 
			
		||||
 | 
			
		||||
    return if skip_distribution?
 | 
			
		||||
 | 
			
		||||
    ActivityPub::DeliveryWorker.push_bulk(inboxes) do |inbox_url|
 | 
			
		||||
      [payload, @account.id, inbox_url, { synchronize_followers: !@status.distributable? }]
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
    relay! if relayable?
 | 
			
		||||
    distribute!
 | 
			
		||||
  rescue ActiveRecord::RecordNotFound
 | 
			
		||||
    true
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def skip_distribution?
 | 
			
		||||
    @status.direct_visibility? || @status.limited_visibility?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def relayable?
 | 
			
		||||
    @status.public_visibility?
 | 
			
		||||
  end
 | 
			
		||||
  protected
 | 
			
		||||
 | 
			
		||||
  def inboxes
 | 
			
		||||
    # Deliver the status to all followers.
 | 
			
		||||
    # If the status is a reply to another local status, also forward it to that
 | 
			
		||||
    # status' authors' followers.
 | 
			
		||||
    @inboxes ||= if @status.in_reply_to_local_account? && @status.distributable?
 | 
			
		||||
                   @account.followers.or(@status.thread.account.followers).inboxes
 | 
			
		||||
                 else
 | 
			
		||||
                   @account.followers.inboxes
 | 
			
		||||
                 end
 | 
			
		||||
    @inboxes ||= StatusReachFinder.new(@status).inboxes
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def payload
 | 
			
		||||
    @payload ||= Oj.dump(serialize_payload(ActivityPub::ActivityPresenter.from_status(@status), ActivityPub::ActivitySerializer, signer: @account))
 | 
			
		||||
    @payload ||= Oj.dump(serialize_payload(activity, ActivityPub::ActivitySerializer, signer: @account))
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def relay!
 | 
			
		||||
    ActivityPub::DeliveryWorker.push_bulk(Relay.enabled.pluck(:inbox_url)) do |inbox_url|
 | 
			
		||||
      [payload, @account.id, inbox_url]
 | 
			
		||||
    end
 | 
			
		||||
  def activity
 | 
			
		||||
    ActivityPub::ActivityPresenter.from_status(@status)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def options
 | 
			
		||||
    { synchronize_followers: @status.private_visibility? }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user