Skip to content

Commit

Permalink
Fix processing incoming post edits with mentions to unresolvable acco…
Browse files Browse the repository at this point in the history
…unts (mastodon#33129)
  • Loading branch information
ClearlyClaire authored Dec 2, 2024
1 parent 4b80ff9 commit 5c06fe4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions app/services/activitypub/process_status_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def update_tags!
def update_mentions!
previous_mentions = @status.active_mentions.includes(:account).to_a
current_mentions = []
unresolved_mentions = []

@raw_mentions.each do |href|
next if href.blank?
Expand All @@ -205,6 +206,12 @@ def update_mentions!
mention ||= account.mentions.new(status: @status)

current_mentions << mention
rescue Mastodon::UnexpectedResponseError, *Mastodon::HTTP_CONNECTION_ERRORS
# Since previous mentions are about already-known accounts,
# they don't try to resolve again and won't fall into this case.
# In other words, this failure case is only for new mentions and won't
# affect `removed_mentions` so they can safely be retried asynchronously
unresolved_mentions << href
end

current_mentions.each do |mention|
Expand All @@ -217,6 +224,11 @@ def update_mentions!
removed_mentions = previous_mentions - current_mentions

Mention.where(id: removed_mentions.map(&:id)).update_all(silent: true) unless removed_mentions.empty?

# Queue unresolved mentions for later
unresolved_mentions.uniq.each do |uri|
MentionResolveWorker.perform_in(rand(30...600).seconds, @status.id, uri, { 'request_id' => @request_id })
end
end

def update_emojis!
Expand Down

0 comments on commit 5c06fe4

Please sign in to comment.