Visibility: Make it more resilient.
authorlain <lain@soykaf.club>
Wed, 8 May 2019 16:08:50 +0000 (18:08 +0200)
committerlain <lain@soykaf.club>
Wed, 8 May 2019 16:08:50 +0000 (18:08 +0200)
lib/pleroma/web/activity_pub/visibility.ex
test/web/activity_pub/visibilty_test.exs

index 6dee61dd61b02bf9dc337d86becb7faa807b711f..e7613a5c8db0dab23ad4d7951eafad05989aab58 100644 (file)
@@ -13,11 +13,12 @@ defmodule Pleroma.Web.ActivityPub.Visibility do
   end
 
   def is_private?(activity) do
-    unless is_public?(activity) do
-      follower_address = User.get_cached_by_ap_id(activity.data["actor"]).follower_address
-      Enum.any?(activity.data["to"], &(&1 == follower_address))
+    with false <- is_public?(activity),
+         %User{follower_address: follower_address} <-
+           User.get_cached_by_ap_id(activity.data["actor"]) do
+      follower_address in activity.data["to"]
     else
-      false
+      _ -> false
     end
   end
 
index 24b96c4aa7429925694ea5e0bda3b86dc810dc81..ff0e724014ed47c62edfd898bc83991e5049891b 100644 (file)
@@ -95,4 +95,14 @@ defmodule Pleroma.Web.ActivityPub.VisibilityTest do
     refute Visibility.visible_for_user?(private, unrelated)
     refute Visibility.visible_for_user?(direct, unrelated)
   end
+
+  test "doesn't die when the user doesn't exist",
+       %{
+         direct: direct,
+         user: user
+       } do
+    Repo.delete(user)
+    Cachex.clear(:user_cache)
+    refute Visibility.is_private?(direct)
+  end
 end