Skip to content
This repository has been archived by the owner on May 16, 2019. It is now read-only.

Commit

Permalink
Accept the same payload in multiple inboxes and deliver (mastodon#9150)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Oct 30, 2018
1 parent 47b8d19 commit be202f9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
20 changes: 19 additions & 1 deletion app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ def perform
RedisLock.acquire(lock_options) do |lock|
if lock.acquired?
@status = find_existing_status
process_status if @status.nil?

if @status.nil?
process_status
elsif @options[:delivered_to_account_id].present?
postprocess_audience_and_deliver
end
else
raise Mastodon::RaceConditionError
end
Expand Down Expand Up @@ -99,6 +104,19 @@ def process_audience
@params[:visibility] = :limited
end

def postprocess_audience_and_deliver
return if @status.mentions.find_by(account_id: @options[:delivered_to_account_id])

delivered_to_account = Account.find(@options[:delivered_to_account_id])

@status.mentions.create(account: delivered_to_account, silent: true)
@status.update(visibility: :limited) if @status.direct_visibility?

return unless delivered_to_account.following?(@account)

FeedInsertWorker.perform_async(@status.id, delivered_to_account.id, :home)
end

def attach_tags(status)
@tags.each do |tag|
status.tags << tag
Expand Down
6 changes: 2 additions & 4 deletions app/services/fan_out_on_write_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ def deliver_to_lists(status)
def deliver_to_mentioned_followers(status)
Rails.logger.debug "Delivering status #{status.id} to limited followers"

status.mentions.includes(:account).each do |mention|
mentioned_account = mention.account
next if !mentioned_account.local? || !mentioned_account.following?(status.account) || FeedManager.instance.filter?(:home, status, mention.account_id)
FeedManager.instance.push_to_home(mentioned_account, status)
FeedInsertWorker.push_bulk(status.mentions.includes(:account).map(&:account).select { |mentioned_account| mentioned_account.local? && mentioned_account.following?(status.account) }) do |follower|
[status.id, follower.id, :home]
end
end

Expand Down

0 comments on commit be202f9

Please sign in to comment.