+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.MastodonAPI.StatusView do
use Pleroma.Web, :view
- alias Pleroma.{
- Activity,
- HTML,
- Repo,
- User
- }
-
- alias Pleroma.Web.{
- CommonAPI.Utils,
- MastodonAPI.AccountView,
- MastodonAPI.StatusView,
- MediaProxy
- }
+ alias Pleroma.Activity
+ alias Pleroma.HTML
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI.Utils
+ alias Pleroma.Web.MediaProxy
+ alias Pleroma.Web.MastodonAPI.AccountView
+ alias Pleroma.Web.MastodonAPI.StatusView
# TODO: Add cached version.
defp get_replied_to_activities(activities) do
favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
attachment_data = object["attachment"] || []
- attachment_data = attachment_data ++ if object["type"] == "Video", do: [object], else: []
attachments = render_many(attachment_data, StatusView, "attachment.json", as: :attachment)
created_at = Utils.to_masto_date(object["published"])
visibility: get_visibility(object),
media_attachments: attachments |> Enum.take(4),
mentions: mentions,
- tags: tags,
+ tags: build_tags(tags),
application: %{
name: "Web",
website: nil
def render_content(object), do: object["content"] || ""
+ @doc """
+ Builds a dictionary tags.
+
+ ## Examples
+
+ iex> Pleroma.Web.MastodonAPI.StatusView.build_tags(["fediverse", "nextcloud"])
+ [{"name": "fediverse", "url": "/tag/fediverse"},
+ {"name": "nextcloud", "url": "/tag/nextcloud"}]
+
+ """
+ @spec build_tags(list(any())) :: list(map())
+ def build_tags(object_tags) when is_list(object_tags) do
+ object_tags = for tag when is_binary(tag) <- object_tags, do: tag
+
+ Enum.reduce(object_tags, [], fn tag, tags ->
+ tags ++ [%{name: tag, url: "/tag/#{tag}"}]
+ end)
+ end
+
+ def build_tags(_), do: []
+
@doc """
Builds list emojis.