about summary refs log tree commit diff
path: root/app/services/resolve_url_service.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2019-11-10 23:04:48 +0100
committerEugen Rochko <eugen@zeonfederated.com>2019-11-11 00:04:48 +0200
commit0d5f3ae33135f2cae28c13df6bba63d396dd08cc (patch)
treeb98ace6ba1f91d515681835b3b1864955209c4d3 /app/services/resolve_url_service.rb
parent823dcc4dc663fc85013df0891b3cb6d6292642ba (diff)
Fix already-known remote private toots not being searchable by URL (#12336)
* Fix already-known remote private toots not being searchable by URL

Whenever an URL search fails, and an account is provided, try getting a
private status matching that URL from database.

* Fix searching by `id` field instead of `uri`
Diffstat (limited to 'app/services/resolve_url_service.rb')
-rw-r--r--app/services/resolve_url_service.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/app/services/resolve_url_service.rb b/app/services/resolve_url_service.rb
index aa883597a..4e971a4b8 100644
--- a/app/services/resolve_url_service.rb
+++ b/app/services/resolve_url_service.rb
@@ -24,6 +24,12 @@ class ResolveURLService < BaseService
       status = FetchRemoteStatusService.new.call(resource_url, body, protocol)
       authorize_with @on_behalf_of, status, :show? unless status.nil?
       status
+    elsif fetched_resource.nil? && @on_behalf_of.present?
+      # It may happen that the resource is a private toot, and thus not fetchable,
+      # but we can return the toot if we already know about it.
+      status = Status.find_by(uri: @url) || Status.find_by(url: @url)
+      authorize_with @on_behalf_of, status, :show? unless status.nil?
+      status
     end
   end