StatusView: show quoted posts through the API, probably
This commit is contained in:
parent
04709e1a27
commit
0584a6f131
|
@ -57,6 +57,27 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp get_quoted_activities([]), do: %{}
|
||||||
|
|
||||||
|
defp get_quoted_activities(activities) do
|
||||||
|
activities
|
||||||
|
|> Enum.map(fn
|
||||||
|
%{data: %{"type" => "Create"}} = activity ->
|
||||||
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
object && object.data["quoteUrl"] != "" && object.data["quoteUrl"]
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
nil
|
||||||
|
end)
|
||||||
|
|> Enum.filter(& &1)
|
||||||
|
|> Activity.create_by_object_ap_id_with_object()
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.reduce(%{}, fn activity, acc ->
|
||||||
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
if object, do: Map.put(acc, object.data["id"], activity), else: acc
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
defp get_context_id(%{data: %{"context_id" => context_id}}) when not is_nil(context_id),
|
defp get_context_id(%{data: %{"context_id" => context_id}}) when not is_nil(context_id),
|
||||||
do: context_id
|
do: context_id
|
||||||
|
|
||||||
|
@ -89,6 +110,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
# length(activities_with_links) * timeout
|
# length(activities_with_links) * timeout
|
||||||
fetch_rich_media_for_activities(activities)
|
fetch_rich_media_for_activities(activities)
|
||||||
replied_to_activities = get_replied_to_activities(activities)
|
replied_to_activities = get_replied_to_activities(activities)
|
||||||
|
quoted_activities = get_quoted_activities(activities)
|
||||||
|
|
||||||
parent_activities =
|
parent_activities =
|
||||||
activities
|
activities
|
||||||
|
@ -121,6 +143,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
opts =
|
opts =
|
||||||
opts
|
opts
|
||||||
|> Map.put(:replied_to_activities, replied_to_activities)
|
|> Map.put(:replied_to_activities, replied_to_activities)
|
||||||
|
|> Map.put(:quoted_activities, quoted_activities)
|
||||||
|> Map.put(:parent_activities, parent_activities)
|
|> Map.put(:parent_activities, parent_activities)
|
||||||
|> Map.put(:relationships, relationships_opt)
|
|> Map.put(:relationships, relationships_opt)
|
||||||
|
|
||||||
|
@ -259,9 +282,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
created_at = Utils.to_masto_date(object.data["published"])
|
created_at = Utils.to_masto_date(object.data["published"])
|
||||||
|
|
||||||
reply_to = get_reply_to(activity, opts)
|
reply_to = get_reply_to(activity, opts)
|
||||||
|
|
||||||
reply_to_user = reply_to && CommonAPI.get_user(reply_to.data["actor"])
|
reply_to_user = reply_to && CommonAPI.get_user(reply_to.data["actor"])
|
||||||
|
|
||||||
|
quote_activity = get_quote(activity, opts)
|
||||||
|
|
||||||
content =
|
content =
|
||||||
object
|
object
|
||||||
|> render_content()
|
|> render_content()
|
||||||
|
@ -368,6 +392,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
local: activity.local,
|
local: activity.local,
|
||||||
conversation_id: get_context_id(activity),
|
conversation_id: get_context_id(activity),
|
||||||
in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
|
in_reply_to_account_acct: reply_to_user && reply_to_user.nickname,
|
||||||
|
quote_id: quote_activity && to_string(quote_activity.id),
|
||||||
content: %{"text/plain" => content_plaintext},
|
content: %{"text/plain" => content_plaintext},
|
||||||
spoiler_text: %{"text/plain" => summary},
|
spoiler_text: %{"text/plain" => summary},
|
||||||
expires_at: expires_at,
|
expires_at: expires_at,
|
||||||
|
@ -500,6 +525,21 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_quote(activity, %{quoted_activities: quoted_activities}) do
|
||||||
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
quoted_activities[object.data["quoteUrl"]]
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_quote(%{data: %{"object" => _object}} = activity, _) do
|
||||||
|
object = Object.normalize(activity, fetch: false)
|
||||||
|
|
||||||
|
if object.data["quoteUrl"] && object.data["quoteUrl"] != "" do
|
||||||
|
Activity.get_create_by_object_ap_id(object.data["quoteUrl"])
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do
|
def render_content(%{data: %{"name" => name}} = object) when not is_nil(name) and name != "" do
|
||||||
url = object.data["url"] || object.data["id"]
|
url = object.data["url"] || object.data["id"]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue