Merge branch 'develop' into dtluna/pleroma-feature/unfollow-activity
[akkoma] / lib / pleroma / web / twitter_api / representers / activity_representer.ex
index b5857282930a1e9e9226e9b80a6c7ef2d6162ea1..affd435771e28d4f792d933b6041cd1bdbe58994 100644 (file)
@@ -3,6 +3,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
   alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ObjectRepresenter}
   alias Pleroma.{Activity, User}
   alias Calendar.Strftime
+  alias Pleroma.Web.TwitterAPI.TwitterAPI
+  alias Pleroma.Wi
 
   defp user_by_ap_id(user_list, ap_id) do
     Enum.find(user_list, fn (%{ap_id: user_id}) -> ap_id == user_id end)
@@ -26,7 +28,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
       "is_post_verb" => false,
       "uri" => "tag:#{activity.data["id"]}:objectType=note",
       "created_at" => created_at,
-      "retweeted_status" => retweeted_status
+      "retweeted_status" => retweeted_status,
+      "statusnet_conversation_id" => conversation_id(announced_activity)
     }
   end
 
@@ -81,6 +84,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> UserRepresenter.to_map(user, opts) end)
 
+    conversation_id = conversation_id(activity)
+
     %{
       "id" => activity.id,
       "user" => UserRepresenter.to_map(user, opts),
@@ -91,7 +96,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
       "is_post_verb" => true,
       "created_at" => created_at,
       "in_reply_to_status_id" => object["inReplyToStatusId"],
-      "statusnet_conversation_id" => object["statusnetConversationId"],
+      "statusnet_conversation_id" => conversation_id,
       "attachments" => (object["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
       "attentions" => attentions,
       "fave_num" => like_count,
@@ -101,6 +106,13 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     }
   end
 
+  def conversation_id(activity) do
+    with context when not is_nil(context) <- activity.data["context"] do
+      TwitterAPI.context_to_conversation_id(context)
+    else _e -> nil
+    end
+  end
+
   defp date_to_asctime(date) do
     with {:ok, date, _offset} <- date |> DateTime.from_iso8601 do
       Strftime.strftime!(date, "%a %b %d %H:%M:%S %z %Y")