1 defmodule Pleroma.Web.MastodonAPI.StatusView do
3 alias Pleroma.Web.MastodonAPI.{AccountView, StatusView}
6 def render("index.json", opts) do
7 render_many(opts.activities, StatusView, "status.json", opts)
10 def render("status.json", %{activity: %{data: %{"object" => object}} = activity} = opts) do
11 user = User.get_cached_by_ap_id(activity.data["actor"])
13 like_count = object["like_count"] || 0
14 announcement_count = object["announcement_count"] || 0
16 tags = object["tag"] || []
17 sensitive = Enum.member?(tags, "nsfw")
19 mentions = activity.data["to"]
20 |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
22 |> Enum.map(fn (user) -> AccountView.render("mention.json", %{user: user}) end)
24 repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
25 favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
27 attachments = render_many(object["attachment"] || [], StatusView, "attachment.json", as: :attachment)
29 created_at = (object["published"] || "")
30 |> NaiveDateTime.from_iso8601!
31 |> NaiveDateTime.to_iso8601
32 |> String.replace(~r/(\.\d+)?$/, ".000Z", global: false)
37 url: object["external_url"],
38 account: AccountView.render("account.json", %{user: user}),
39 in_reply_to_id: object["inReplyToStatusId"],
40 in_reply_to_account_id: nil,
42 content: HtmlSanitizeEx.basic_html(object["content"]),
43 created_at: created_at,
44 reblogs_count: announcement_count,
45 favourites_count: like_count,
46 reblogged: !!repeated,
47 favourited: !!favorited,
52 media_attachments: attachments,
60 def render("attachment.json", %{attachment: attachment}) do
61 [%{"mediaType" => media_type, "href" => href} | _] = attachment["url"]
64 String.contains?(media_type, "image") -> "image"
65 String.contains?(media_type, "video") -> "video"
69 << hash_id::signed-32, _rest::binary >> = :crypto.hash(:md5, href)
72 id: attachment["id"] || hash_id,