1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
9 alias Pleroma.Web.ActivityPub.Visibility
11 def prepare_activity(%User{} = user, %Object{} = object) do
16 |> set_content(object)
17 |> set_attachments(object)
20 defp set_user(data, %User{} = user), do: Map.put(data, :user, user)
22 defp set_object(data, %Object{} = object), do: Map.put(data, :object, object)
24 defp set_title(data, %Object{data: %{"name" => name}}) when is_binary(name),
25 do: Map.put(data, :title, name)
27 defp set_title(data, %Object{data: %{"summary" => summary}}) when is_binary(summary),
28 do: Map.put(data, :title, summary)
30 defp set_title(data, _), do: Map.put(data, :title, nil)
32 defp set_content(data, %Object{data: %{"content" => content}}) when is_binary(content),
33 do: Map.put(data, :content, content)
35 defp set_content(data, _), do: Map.put(data, :content, nil)
38 defp set_attachments(data, _), do: Map.put(data, :attachments, [])
40 def represent(activity_id) do
41 with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(activity_id),
42 true <- Visibility.is_public?(activity),
43 %Object{} = object <- Object.normalize(activity.data["object"]),
44 %User{} = user <- User.get_or_fetch(activity.data["actor"]),
45 data <- prepare_activity(user, object) do