aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/tasks/pleroma/database.ex36
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex38
2 files changed, 41 insertions, 33 deletions
diff --git a/lib/mix/tasks/pleroma/database.ex b/lib/mix/tasks/pleroma/database.ex
index e91fb31d1..990651da4 100644
--- a/lib/mix/tasks/pleroma/database.ex
+++ b/lib/mix/tasks/pleroma/database.ex
@@ -35,6 +35,10 @@ defmodule Mix.Tasks.Pleroma.Database do
## Remove duplicated items from following and update followers count for all users
mix pleroma.database update_users_following_followers_counts
+
+ ## Fix the pre-existing "likes" collections for all objects
+
+ mix pleroma.database fix_likes_collections
"""
def run(["remove_embedded_objects" | args]) do
{options, [], []} =
@@ -119,4 +123,36 @@ defmodule Mix.Tasks.Pleroma.Database do
)
end
end
+
+ def run(["fix_likes_collections"]) do
+ import Ecto.Query
+
+ start_pleroma()
+
+ from(object in Object,
+ where: fragment("(?)->>'likes' is not null", object.data),
+ select: %{id: object.id, likes: fragment("(?)->>'likes'", object.data)}
+ )
+ |> Pleroma.RepoStreamer.chunk_stream(100)
+ |> Stream.each(fn objects ->
+ ids =
+ objects
+ |> Enum.filter(fn object -> object.likes |> Jason.decode!() |> is_map() end)
+ |> Enum.map(& &1.id)
+
+ Object
+ |> where([object], object.id in ^ids)
+ |> update([object],
+ set: [
+ data:
+ fragment(
+ "jsonb_set(?, '{likes}', '[]'::jsonb, true)",
+ object.data
+ )
+ ]
+ )
+ |> Repo.update_all([], timeout: :infinity)
+ end)
+ |> Stream.run()
+ end
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 591227af2..65c1f9d9f 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -24,6 +24,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
"""
def fix_object(object) do
object
+ |> strip_internal_fields
|> fix_actor
|> fix_url
|> fix_attachments
@@ -32,7 +33,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> fix_emoji
|> fix_tag
|> fix_content_map
- |> fix_likes
|> fix_addressing
|> fix_summary
|> fix_type
@@ -150,21 +150,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Map.put("actor", Containment.get_actor(%{"actor" => actor}))
end
- # Check for standardisation
- # This is what Peertube does
- # curl -H 'Accept: application/activity+json' $likes | jq .totalItems
- # Prismo returns only an integer (count) as "likes"
- def fix_likes(%{"likes" => likes} = object) when not is_map(likes) do
- object
- |> Map.put("likes", [])
- |> Map.put("like_count", 0)
- end
+ def fix_in_reply_to(object, options \\ [])
- def fix_likes(object) do
- object
- end
-
- def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object)
+ def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object, _options)
when not is_nil(in_reply_to) do
in_reply_to_id =
cond do
@@ -203,7 +191,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
end
end
- def fix_in_reply_to(object), do: object
+ def fix_in_reply_to(object, _options), do: object
def fix_context(object) do
context = object["context"] || object["conversation"] || Utils.generate_context_id()
@@ -752,7 +740,6 @@ 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
@@ -936,22 +923,6 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Map.put("attributedTo", attributed_to)
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"] || [])
@@ -967,6 +938,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
defp strip_internal_fields(object) do
object
|> Map.drop([
+ "likes",
"like_count",
"announcements",
"announcement_count",