reverse proxy / uploads
[akkoma] / lib / pleroma / web / activity_pub / views / user_view.ex
index fdb2b8ea9e444a6803274a3eada9ff11b4d9da68..eb335813d2bf41333a8dfc6f334e85a57c92eb00 100644 (file)
@@ -9,6 +9,35 @@ defmodule Pleroma.Web.ActivityPub.UserView do
   alias Pleroma.Web.ActivityPub.Utils
   import Ecto.Query
 
+  # the instance itself is not a Person, but instead an Application
+  def render("user.json", %{user: %{nickname: nil} = user}) do
+    {:ok, user} = WebFinger.ensure_keys_present(user)
+    {:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
+    public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
+    public_key = :public_key.pem_encode([public_key])
+
+    %{
+      "id" => user.ap_id,
+      "type" => "Application",
+      "following" => "#{user.ap_id}/following",
+      "followers" => "#{user.ap_id}/followers",
+      "inbox" => "#{user.ap_id}/inbox",
+      "name" => "Pleroma",
+      "summary" => "Virtual actor for Pleroma relay",
+      "url" => user.ap_id,
+      "manuallyApprovesFollowers" => false,
+      "publicKey" => %{
+        "id" => "#{user.ap_id}#main-key",
+        "owner" => user.ap_id,
+        "publicKeyPem" => public_key
+      },
+      "endpoints" => %{
+        "sharedInbox" => "#{Pleroma.Web.Endpoint.url()}/inbox"
+      }
+    }
+    |> Map.merge(Utils.make_json_ld_header())
+  end
+
   def render("user.json", %{user: user}) do
     {:ok, user} = WebFinger.ensure_keys_present(user)
     {:ok, _, public_key} = Salmon.keys_from_pem(user.info["keys"])
@@ -99,9 +128,6 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     info = User.user_info(user)
 
     params = %{
-      "type" => ["Create", "Announce"],
-      "actor_id" => user.ap_id,
-      "whole_db" => true,
       "limit" => "10"
     }
 
@@ -112,10 +138,8 @@ defmodule Pleroma.Web.ActivityPub.UserView do
         params
       end
 
-    activities = ActivityPub.fetch_public_activities(params)
-    min_id = Enum.at(activities, 0).id
-
-    activities = Enum.reverse(activities)
+    activities = ActivityPub.fetch_user_activities(user, nil, params)
+    min_id = Enum.at(Enum.reverse(activities), 0).id
     max_id = Enum.at(activities, 0).id
 
     collection =