Add conversation ids to twapi announce representer.
authorRoger Braun <roger@rogerbraun.net>
Sun, 7 May 2017 10:46:21 +0000 (12:46 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sun, 7 May 2017 10:46:21 +0000 (12:46 +0200)
lib/pleroma/web/twitter_api/representers/activity_representer.ex
test/web/twitter_api/representers/activity_representer_test.exs

index 4d7ea0c5cfb21187c542df55ae6dec6376fa067f..3fef8eec86653f1a7cc9641c08389b225f905419 100644 (file)
@@ -27,7 +27,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
 
@@ -82,11 +83,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     |> Enum.filter(&(&1))
     |> Enum.map(fn (user) -> UserRepresenter.to_map(user, opts) end)
 
-
-    conversation_id = with context when not is_nil(context) <- activity.data["context"] do
-      TwitterAPI.context_to_conversation_id(context)
-    else _e -> nil
-    end
+    conversation_id = conversation_id(activity)
 
     %{
       "id" => activity.id,
@@ -108,6 +105,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")
index 64e7f0641b33148ef1a8de95fbd16569031a5f73..84c8d9a49ee5c94bcca61ff6814093a5865b312e 100644 (file)
@@ -22,6 +22,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do
 
     retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user})
     assert retweeted_status["repeated"] == true
+    assert retweeted_status["id"] == note_activity.id
+    assert status["statusnet_conversation_id"] == retweeted_status["statusnet_conversation_id"]
 
     assert status["retweeted_status"] == retweeted_status
   end