Merge branch 'bugfix/ap-uri-user-search' into 'develop'
[akkoma] / lib / pleroma / web / mastodon_api / views / status_view.ex
index f1daa2624c3e8fb87fda8e2f4102359d6b3c1b74..8ffaf8466b88202db514b8576d6b10f795d8eaa7 100644 (file)
@@ -34,6 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       "status.json",
       Map.put(opts, :replied_to_activities, replied_to_activities)
     )
+    |> Enum.filter(fn x -> not is_nil(x) end)
   end
 
   def render(
@@ -63,6 +64,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       content: reblogged[:content],
       created_at: created_at,
       reblogs_count: 0,
+      replies_count: 0,
       favourites_count: 0,
       reblogged: false,
       favourited: false,
@@ -118,9 +120,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
           HTML.strip_tags(url)
           |> MediaProxy.url()
 
-        %{shortcode: name, url: url, static_url: url}
+        %{shortcode: name, url: url, static_url: url, visible_in_picker: false}
       end)
 
+    content =
+      render_content(object)
+      |> HTML.filter_tags(User.html_filter_policy(opts[:for]))
+
     %{
       id: to_string(activity.id),
       uri: object["id"],
@@ -129,9 +135,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       in_reply_to_id: reply_to && to_string(reply_to.id),
       in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
       reblog: nil,
-      content: render_content(object),
+      content: content,
       created_at: created_at,
       reblogs_count: announcement_count,
+      replies_count: 0,
       favourites_count: like_count,
       reblogged: !!repeated,
       favourited: !!favorited,
@@ -152,9 +159,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     }
   end
 
+  def render("status.json", _) do
+    nil
+  end
+
   def render("attachment.json", %{attachment: attachment}) do
     [attachment_url | _] = attachment["url"]
-    media_type = attachment_url["mediaType"] || attachment_url["mimeType"]
+    media_type = attachment_url["mediaType"] || attachment_url["mimeType"] || "image"
     href = attachment_url["href"]
 
     type =
@@ -222,7 +233,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         object["content"]
       end
 
-    HTML.filter_tags(content)
+    content
   end
 
   def render_content(%{"type" => "Article"} = object) do
@@ -235,10 +246,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         object["content"]
       end
 
-    HTML.filter_tags(content)
+    content
   end
 
-  def render_content(object) do
-    HTML.filter_tags(object["content"])
-  end
+  def render_content(object), do: object["content"]
 end