Attempt to fix incorrect federation of default instance avatars
authorMark Felder <feld@FreeBSD.org>
Mon, 25 Mar 2019 23:47:04 +0000 (18:47 -0500)
committerMark Felder <feld@FreeBSD.org>
Mon, 25 Mar 2019 23:47:04 +0000 (18:47 -0500)
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/activity_pub/views/user_view.ex

index 41289b4d0591cb6cad4b07d768075726ba95d4b2..ee5eb8efa85d15ddc78879c2539b1bf04e4f977c 100644 (file)
@@ -90,6 +90,14 @@ defmodule Pleroma.User do
     end
   end
 
+  # Do not return instance default avatar for federation
+  def avatar_url_ap(user) do
+    case user.avatar do
+      %{"url" => [%{"href" => href} | _]} -> href
+      _ -> nil
+    end
+  end
+
   def banner_url(user) do
     case user.info.banner do
       %{"url" => [%{"href" => href} | _]} -> href
index 2e9ffe41c40f5b2fa33049d94f7544cd450af5a0..6d74738f0ab4cf224d23eb2ad152ad1c3891405d 100644 (file)
@@ -230,6 +230,21 @@ defmodule Pleroma.Web.ActivityPub.Utils do
     end)
   end
 
+  # Only federate user icon if not nil
+  # Prevents federating instance default avatars
+  def maybe_make_icon(user) do
+    if User.avatar_url_ap(user) do
+      %{
+        "icon" => %{
+          "type" => "Image",
+          "url" => User.avatar_url_ap(user)
+        }
+      }
+    else
+      []
+    end
+  end
+
   #### Like-related helpers
 
   @doc """
index 3d00dcbf29ea2271d8375de139ead7fb8e8d5d3e..f5c86d3609d71f5085d57d0abdbdaf8679f27b75 100644 (file)
@@ -87,16 +87,13 @@ defmodule Pleroma.Web.ActivityPub.UserView do
         "publicKeyPem" => public_key
       },
       "endpoints" => endpoints,
-      "icon" => %{
-        "type" => "Image",
-        "url" => User.avatar_url(user)
-      },
       "image" => %{
         "type" => "Image",
         "url" => User.banner_url(user)
       },
       "tag" => user.info.source_data["tag"] || []
     }
+    |> Map.merge(Utils.maybe_make_icon(user))
     |> Map.merge(Utils.make_json_ld_header())
   end