TwitterAPI: support follow activities without published date.
[akkoma] / lib / pleroma / web / twitter_api / representers / activity_representer.ex
index b17013d875141c255b4b4a98a7d1e27106f5bd22..98be18c9895cdbbbd68bb076a2220b585c27d5c9 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
 
     %{
@@ -133,7 +134,9 @@ 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")
+
+    tags = if possibly_sensitive, do: ["nsfw" | tags], else: tags
 
     summary = activity.data["object"]["summary"]
     content = if !!summary and summary != "" do