Merge branch 'feature/object-normalization' into 'develop'
[akkoma] / lib / pleroma / web / mastodon_api / views / status_view.ex
index 5c6fd05f3a82eeb07adf9408a6adbdf8ceaa8aed..4c20581d6239440f3e52b2a12ca9ee23f44d7d48 100644 (file)
@@ -54,8 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     %{
       id: to_string(activity.id),
       uri: object,
-      # TODO: This might be wrong, check with mastodon.
-      url: nil,
+      url: object,
       account: AccountView.render("account.json", %{user: user}),
       in_reply_to_id: nil,
       in_reply_to_account_id: nil,
@@ -125,10 +124,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
       uri: object["id"],
       url: object["external_url"] || object["id"],
       account: AccountView.render("account.json", %{user: user}),
-      in_reply_to_id: reply_to && reply_to.id,
-      in_reply_to_account_id: reply_to_user && reply_to_user.id,
+      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: HtmlSanitizeEx.basic_html(object["content"]),
+      content: render_content(object),
       created_at: created_at,
       reblogs_count: announcement_count,
       favourites_count: like_count,
@@ -193,10 +192,35 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
     cc = object["cc"] || []
 
     cond do
-      public in to -> "public"
-      public in cc -> "unlisted"
-      Enum.any?(to, &String.contains?(&1, "/followers")) -> "private"
-      true -> "direct"
+      public in to ->
+        "public"
+
+      public in cc ->
+        "unlisted"
+
+      # this should use the sql for the object's activity
+      Enum.any?(to, &String.contains?(&1, "/followers")) ->
+        "private"
+
+      true ->
+        "direct"
     end
   end
+
+  def render_content(%{"type" => "Article"} = object) do
+    summary = object["name"]
+
+    content =
+      if !!summary and summary != "" do
+        "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
+      else
+        object["content"]
+      end
+
+    HtmlSanitizeEx.basic_html(content)
+  end
+
+  def render_content(object) do
+    HtmlSanitizeEx.basic_html(object["content"])
+  end
 end