Merge branch 'fix/put-repeats-at-activitypub-outbox' into 'develop'
[akkoma] / lib / pleroma / web / activity_pub / views / user_view.ex
index a1f0be9ed8e3dcdb25f0f98e37321e6087a0d84f..0b1d5a9fa59461277fac543ee1c8bbd35cab4975 100644 (file)
@@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
   def render("user.json", %{user: 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(:RSAPublicKey, public_key)
+    public_key = :public_key.pem_entry_encode(:SubjectPublicKeyInfo, public_key)
     public_key = :public_key.pem_encode([public_key])
 
     %{
@@ -26,7 +26,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       "name" => user.name,
       "summary" => user.bio,
       "url" => user.ap_id,
-      "manuallyApprovesFollowers" => false,
+      "manuallyApprovesFollowers" => user.info["locked"] || false,
       "publicKey" => %{
         "id" => "#{user.ap_id}#main-key",
         "owner" => user.ap_id,
@@ -98,9 +98,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"
     }
 
@@ -111,10 +108,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 =
@@ -147,21 +142,21 @@ defmodule Pleroma.Web.ActivityPub.UserView do
     end
   end
 
-  def collection(collection, iri, page, _total \\ nil) do
+  def collection(collection, iri, page, total \\ nil) do
     offset = (page - 1) * 10
     items = Enum.slice(collection, offset, 10)
     items = Enum.map(items, fn user -> user.ap_id end)
-    total = _total || length(collection)
+    total = total || length(collection)
 
     map = %{
       "id" => "#{iri}?page=#{page}",
       "type" => "OrderedCollectionPage",
       "partOf" => iri,
-      "totalItems" => length(collection),
+      "totalItems" => total,
       "orderedItems" => items
     }
 
-    if offset < length(collection) do
+    if offset < total do
       Map.put(map, "next", "#{iri}?page=#{page + 1}")
     end
   end