Merge branch 'feature/message-summary' into 'develop'
[akkoma] / lib / pleroma / web / twitter_api / views / activity_view.ex
index 4e4433aed5653e1186314473d3b7736dc2ec4422..55b5287f5e2bb4e94cfcde2bdc7ea646a2009f00 100644 (file)
@@ -31,7 +31,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
   end
 
   defp collect_context_ids(activities) do
-    contexts =
+    _contexts =
       activities
       |> Enum.reject(& &1.data["context_id"])
       |> Enum.map(fn %{data: data} ->
@@ -228,15 +228,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
 
     tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
 
-    summary = activity.data["object"]["summary"]
-    content = object["content"]
-
-    content =
-      if !!summary and summary != "" do
-        "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
-      else
-        content
-      end
+    {summary, content} = render_content(object)
 
     html =
       HtmlSanitizeEx.basic_html(content)
@@ -262,7 +254,42 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       "external_url" => object["external_url"] || object["id"],
       "tags" => tags,
       "activity_type" => "post",
-      "possibly_sensitive" => possibly_sensitive
+      "possibly_sensitive" => possibly_sensitive,
+      "visibility" => Pleroma.Web.MastodonAPI.StatusView.get_visibility(object),
+      "summary" => summary
     }
   end
+
+  def render_content(%{"type" => "Note"} = object) do
+    summary = object["summary"]
+
+    content =
+      if !!summary and summary != "" do
+        "<p>#{summary}</p>#{object["content"]}"
+      else
+        object["content"]
+      end
+
+    {summary, content}
+  end
+
+  def render_content(%{"type" => "Article"} = object) do
+    summary = object["name"] || object["summary"]
+
+    content =
+      if !!summary and summary != "" do
+        "<p><a href=\"#{object["url"]}\">#{summary}</a></p>#{object["content"]}"
+      else
+        object["content"]
+      end
+
+    {summary, content}
+  end
+
+  def render_content(object) do
+    summary = object["summary"] || "Unhandled activity type: #{object["type"]}"
+    content = "<p>#{summary}</p>#{object["content"]}"
+
+    {summary, content}
+  end
 end