mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
[#1505] Minor refactoring.
This commit is contained in:
parent
7c3991f59e
commit
6ea3c06d8d
1 changed files with 11 additions and 13 deletions
|
@ -914,22 +914,23 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
Based on Mastodon's ActivityPub::NoteSerializer#replies.
|
Based on Mastodon's ActivityPub::NoteSerializer#replies.
|
||||||
"""
|
"""
|
||||||
def set_replies(obj_data) do
|
def set_replies(obj_data) do
|
||||||
limit = Pleroma.Config.get([:activitypub, :note_replies_output_limit], 0)
|
|
||||||
|
|
||||||
replies_uris =
|
replies_uris =
|
||||||
with true <- limit > 0 || nil,
|
with limit when limit > 0 <-
|
||||||
|
Pleroma.Config.get([:activitypub, :note_replies_output_limit], 0),
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(obj_data["id"]) do
|
%Object{} = object <- Object.get_cached_by_ap_id(obj_data["id"]) do
|
||||||
object
|
object
|
||||||
|> Object.self_replies()
|
|> Object.self_replies()
|
||||||
|> select([o], fragment("?->>'id'", o.data))
|
|> select([o], fragment("?->>'id'", o.data))
|
||||||
|> limit(^limit)
|
|> limit(^limit)
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
|
else
|
||||||
|
_ -> []
|
||||||
end
|
end
|
||||||
|
|
||||||
set_replies(obj_data, replies_uris || [])
|
set_replies(obj_data, replies_uris)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp set_replies(obj, replies_uris) when replies_uris in [nil, []] do
|
defp set_replies(obj, []) do
|
||||||
obj
|
obj
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -952,15 +953,12 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
Map.merge(obj, %{"replies" => replies_collection})
|
Map.merge(obj, %{"replies" => replies_collection})
|
||||||
end
|
end
|
||||||
|
|
||||||
def replies(%{"replies" => replies} = _object) when is_map(replies) do
|
def replies(%{"replies" => %{"first" => %{"items" => items}}}) when not is_nil(items) do
|
||||||
replies =
|
items
|
||||||
if is_map(replies["first"]) do
|
|
||||||
replies["first"]
|
|
||||||
else
|
|
||||||
replies
|
|
||||||
end
|
end
|
||||||
|
|
||||||
replies["items"] || []
|
def replies(%{"replies" => %{"items" => items}}) when not is_nil(items) do
|
||||||
|
items
|
||||||
end
|
end
|
||||||
|
|
||||||
def replies(_), do: []
|
def replies(_), do: []
|
||||||
|
|
Loading…
Reference in a new issue