Don't go through all available emoji.
[akkoma] / lib / pleroma / web / twitter_api / representers / activity_representer.ex
index 929e26bf0ff1dfe3bb0f40bce37ab26e1ff54f07..73ae3422bb260d410e3f3c5f30275af7dea8e5c1 100644 (file)
@@ -56,7 +56,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     }
   end
 
-  def to_map(%Activity{data: %{"type" => "Follow", "published" => created_at, "object" => followed_id}} = activity, %{user: user} = opts) do
+  def to_map(%Activity{data: %{"type" => "Follow", "object" => followed_id}} = activity, %{user: user} = opts) do
+    created_at = activity.data["published"] || (DateTime.to_iso8601(activity.inserted_at))
     created_at = created_at |> Utils.date_to_asctime
 
     followed = User.get_cached_by_ap_id(followed_id)
@@ -97,7 +98,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     }
   end
 
-  def to_map(%Activity{data: %{"type" => "Delete", "published" => created_at, "object" => deleted_object }} = activity, %{user: user} = opts) do
+  def to_map(%Activity{data: %{"type" => "Delete", "published" => created_at, "object" => _ }} = activity, %{user: user} = opts) do
     created_at = created_at |> Utils.date_to_asctime
 
     %{
@@ -125,7 +126,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
 
     mentions = opts[:mentioned] || []
 
-    attentions = activity.data["to"]
+    attentions = activity.recipients
     |> Enum.map(fn (ap_id) -> Enum.find(mentions, fn(user) -> ap_id == user.ap_id end) end)
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> UserView.render("show.json", %{user: user, for: opts[:for]}) end)
@@ -133,9 +134,19 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     conversation_id = conversation_id(activity)
 
     tags = activity.data["object"]["tag"] || []
-    possibly_sensitive = Enum.member?(tags, "nsfw")
+    possibly_sensitive = activity.data["object"]["sensitive"] || Enum.member?(tags, "nsfw")
 
-    html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"])
+    tags = if possibly_sensitive, do: Enum.uniq(["nsfw" | tags]), else: tags
+
+    summary = activity.data["object"]["summary"]
+    content = if !!summary and summary != "" do
+      "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
+    else
+      content
+    end
+
+    html = HtmlSanitizeEx.basic_html(content)
+    |> Formatter.emojify(object["emoji"])
 
     %{
       "id" => activity.id,
@@ -154,7 +165,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
       "repeat_num" => announcement_count,
       "favorited" => to_boolean(favorited),
       "repeated" => to_boolean(repeated),
-      "external_url" => object["external_url"],
+      "external_url" => object["external_url"] || object["id"],
       "tags" => tags,
       "activity_type" => "post",
       "possibly_sensitive" => possibly_sensitive