aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorsxsdv1 <sxsdv1@gmail.com>2019-01-09 09:22:00 +0100
committersxsdv1 <sxsdv1@gmail.com>2019-01-12 20:24:41 +0100
commit868034375c5122175f872967e49559dafed9403c (patch)
tree373da9d1a6089ede161e76601ec96df4e76811a0 /lib
parent581edd5a91189e6fb2a94a277b96f9c8197617b8 (diff)
downloadpleroma-868034375c5122175f872967e49559dafed9403c.tar.gz
Add likes to activitypub object representation
Top level of the likes OrderedCollection is inlined to get immediate access to totalItems. Because the count can be returned without scanning the database for like activities the extra query is saved when the client only wants to display the total.
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index b0f8c59cc..86d11c874 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -629,6 +629,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> add_mention_tags
|> add_emoji_tags
|> add_attributed_to
+ |> add_likes
|> prepare_attachments
|> set_conversation
|> set_reply_to_uri
@@ -788,6 +789,22 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Map.put("attributedTo", attributedTo)
end
+ def add_likes(%{"id" => id, "like_count" => likes} = object) do
+ likes = %{
+ "id" => "#{id}/likes",
+ "first" => "#{id}/likes?page=1",
+ "type" => "OrderedCollection",
+ "totalItems" => likes
+ }
+
+ object
+ |> Map.put("likes", likes)
+ end
+
+ def add_likes(object) do
+ object
+ end
+
def prepare_attachments(object) do
attachments =
(object["attachment"] || [])
@@ -803,7 +820,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
defp strip_internal_fields(object) do
object
|> Map.drop([
- "likes",
"like_count",
"announcements",
"announcement_count",