move unauth'd user blocks?/2 check
authorSadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 23 Jul 2019 18:44:47 +0000 (19:44 +0100)
committerSadposter <hannah+pleroma@coffee-and-dreams.uk>
Tue, 23 Jul 2019 18:44:47 +0000 (19:44 +0100)
lib/pleroma/user.ex
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex

index a3f6add28cb13f033ecba47fc604733a75155771..e017efad6b7173811cc4bd00c6ca78171f9d6c38 100644 (file)
@@ -882,6 +882,8 @@ defmodule Pleroma.User do
       Pleroma.Web.ActivityPub.MRF.subdomain_match?(domain_blocks, host)
   end
 
+  def blocks?(nil, _), do: false
+
   def subscribed_to?(user, %{ap_id: ap_id}) do
     with %User{} = target <- get_cached_by_ap_id(ap_id) do
       Enum.member?(target.info.subscribers, user.ap_id)
index 9269a5a29a7e6e326a42e0fe66f7a6de267df86c..d660f3f0561e0d12bfde01cc0c19f394519f366b 100644 (file)
@@ -884,14 +884,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
          %Object{data: %{"likes" => likes}} <- Object.normalize(object) do
       q = from(u in User, where: u.ap_id in ^likes)
 
-      users = Repo.all(q)
-
       users =
-        if is_nil(user) do
-          users
-        else
-          Enum.filter(users, &(not User.blocks?(user, &1)))
-        end
+        Repo.all(q)
+        |> Enum.filter(&(not User.blocks?(user, &1)))
 
       conn
       |> put_view(AccountView)
@@ -906,14 +901,9 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
          %Object{data: %{"announcements" => announces}} <- Object.normalize(object) do
       q = from(u in User, where: u.ap_id in ^announces)
 
-      users = Repo.all(q)
-
       users =
-        if is_nil(user) do
-          users
-        else
-          Enum.filter(users, &(not User.blocks?(user, &1)))
-        end
+        Repo.all(q)
+        |> Enum.filter(&(not User.blocks?(user, &1)))
 
       conn
       |> put_view(AccountView)