Return "audio" info in mastodon api.
[akkoma] / lib / pleroma / web / mastodon_api / views / status_view.ex
index e205a420db03ca659315d96c735204916288a55f..62b967e02ffe770aef4196c5a7168a2527487078 100644 (file)
@@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     reblogged = Activity.get_create_activity_by_object_ap_id(object)
     reblogged = render("status.json", Map.put(opts, :activity, reblogged))
 
-    mentions = activity.data["to"]
+    mentions = activity.recipients
     |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> AccountView.render("mention.json", %{user: user}) end)
@@ -58,9 +58,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     announcement_count = object["announcement_count"] || 0
 
     tags = object["tag"] || []
-    sensitive = Enum.member?(tags, "nsfw")
+    sensitive = object["sensitive"] || Enum.member?(tags, "nsfw")
 
-    mentions = activity.data["to"]
+    mentions = activity.recipients
     |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> AccountView.render("mention.json", %{user: user}) end)
@@ -77,7 +77,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     reply_to_user = reply_to && User.get_cached_by_ap_id(reply_to.data["actor"])
 
     emojis = (activity.data["object"]["emoji"] || [])
-    |> Enum.map(fn {name, url} -> %{ shortcode: name, url: url, static_url: url } end)
+    |> Enum.map(fn {name, url} ->
+      name = HtmlSanitizeEx.strip_tags(name)
+      url = HtmlSanitizeEx.strip_tags(url)
+      %{ shortcode: name, url: url, static_url: url }
+    end)
 
     %{
       id: to_string(activity.id),
@@ -116,18 +120,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     cond do
       public in to -> "public"
       public in cc -> "unlisted"
-      [] == cc -> "direct"
-      true -> "private"
+      Enum.any?(to, &(String.contains?(&1, "/followers"))) -> "private"
+      true -> "direct"
     end
   end
 
   def render("attachment.json", %{attachment: attachment}) do
-    IO.inspect(attachment)
     [%{"mediaType" => media_type, "href" => href} | _] = attachment["url"]
 
     type = cond do
       String.contains?(media_type, "image") -> "image"
       String.contains?(media_type, "video") -> "video"
+      String.contains?(media_type, "audio") -> "audio"
       true -> "unknown"
     end