From 46283b489e71416084e2d6ba8bacf63ab2f0713c Mon Sep 17 00:00:00 2001
From: ThibG <thib@sitedethib.com>
Date: Mon, 24 Aug 2020 16:56:21 +0200
Subject: [PATCH] Fix dereferencing remote statuses not using the correct
 account (#14656)

Follow-up to #14359

In the case of limited toots, the receiver may not be explicitly part of the
audience. If a specific user's inbox URI was specified, it makes sense to
dereference the toot from the corresponding user, instead of trying to find
someone in the explicit audience.
---
 app/lib/activitypub/activity.rb | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb
index f0ef4d553d..a379a7ef43 100644
--- a/app/lib/activitypub/activity.rb
+++ b/app/lib/activitypub/activity.rb
@@ -168,6 +168,8 @@ class ActivityPub::Activity
   end
 
   def signed_fetch_account
+    return Account.find(@options[:delivered_to_account_id]) if @options[:delivered_to_account_id].present?
+
     first_mentioned_local_account || first_local_follower
   end