forked from AkkomaGang/akkoma
Fix activity_representer to work with User.get_or_fetch returning tuple.
This commit is contained in:
parent
0cf04e1088
commit
1d8950798c
2 changed files with 7 additions and 10 deletions
|
@ -81,7 +81,7 @@ def notice(%{assigns: %{format: format}} = conn, %{"id" => id}) do
|
||||||
else
|
else
|
||||||
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
|
with {_, %Activity{} = activity} <- {:activity, Activity.get_by_id_with_object(id)},
|
||||||
{_, true} <- {:public?, Visibility.is_public?(activity)},
|
{_, true} <- {:public?, Visibility.is_public?(activity)},
|
||||||
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
%User{} = user <- User.get_cached_by_ap_id(activity.data["actor"]) do
|
||||||
cond do
|
cond do
|
||||||
format == "html" && activity.data["type"] == "Create" ->
|
format == "html" && activity.data["type"] == "Create" ->
|
||||||
%Object{} = object = Object.normalize(activity)
|
%Object{} = object = Object.normalize(activity)
|
||||||
|
|
|
@ -9,20 +9,19 @@ defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
|
||||||
alias Pleroma.Web.ActivityPub.Visibility
|
alias Pleroma.Web.ActivityPub.Visibility
|
||||||
alias Pleroma.Web.Router.Helpers
|
alias Pleroma.Web.Router.Helpers
|
||||||
|
|
||||||
def prepare_activity(%User{} = user, %Object{} = object, activity_id) do
|
def prepare_activity(%User{} = user, %Activity{} = activity) do
|
||||||
|
object = Object.normalize(activity.data["object"])
|
||||||
|
|
||||||
%{}
|
%{}
|
||||||
|> set_user(user)
|
|> set_user(user)
|
||||||
|> set_object(object)
|
|> set_object(object)
|
||||||
|> set_title(object)
|
|> set_title(object)
|
||||||
|> set_content(object)
|
|> set_content(object)
|
||||||
|> set_link(activity_id)
|
|> set_link(activity.id)
|
||||||
|> set_published(object)
|
|> set_published(object)
|
||||||
|> set_attachments(object)
|
|> set_attachments(object)
|
||||||
end
|
end
|
||||||
|
|
||||||
def prepare_activity(%User{} = user, %Activity{} = activity),
|
|
||||||
do: prepare_activity(user, Object.normalize(activity.data["object"]), activity.id)
|
|
||||||
|
|
||||||
defp set_user(data, %User{} = user), do: Map.put(data, :user, user)
|
defp set_user(data, %User{} = user), do: Map.put(data, :user, user)
|
||||||
|
|
||||||
defp set_object(data, %Object{} = object), do: Map.put(data, :object, object)
|
defp set_object(data, %Object{} = object), do: Map.put(data, :object, object)
|
||||||
|
@ -52,10 +51,8 @@ defp set_attachments(data, _), do: Map.put(data, :attachments, [])
|
||||||
def represent(activity_id) do
|
def represent(activity_id) do
|
||||||
with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(activity_id),
|
with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(activity_id),
|
||||||
true <- Visibility.is_public?(activity),
|
true <- Visibility.is_public?(activity),
|
||||||
%Object{} = object <- Object.normalize(activity.data["object"]),
|
{:ok, %User{} = user} <- User.get_or_fetch(activity.data["actor"]) do
|
||||||
%User{} = user <- User.get_or_fetch(activity.data["actor"]),
|
{:ok, prepare_activity(user, activity)}
|
||||||
data <- prepare_activity(user, object, activity_id) do
|
|
||||||
{:ok, data}
|
|
||||||
else
|
else
|
||||||
e ->
|
e ->
|
||||||
{:error, e}
|
{:error, e}
|
||||||
|
|
Loading…
Reference in a new issue