diff --git a/lib/pleroma/web/twitter_api/views/activity_view.ex b/lib/pleroma/web/twitter_api/views/activity_view.ex
index ae5be60ce..520f0aa36 100644
--- a/lib/pleroma/web/twitter_api/views/activity_view.ex
+++ b/lib/pleroma/web/twitter_api/views/activity_view.ex
@@ -5,8 +5,32 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
alias Pleroma.Web.TwitterAPI.UserView
alias Pleroma.Web.TwitterAPI.TwitterAPI
alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
+ alias Pleroma.Activity
alias Pleroma.Formatter
+ def render("activity.json", %{activity: %{data: %{"type" => "Like"}} = activity} = opts) do
+ user = User.get_cached_by_ap_id(activity.data["actor"])
+ liked_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
+ created_at = activity.data["published"]
+ |> Utils.date_to_asctime
+
+ text = "#{user.nickname} favorited a status."
+
+ %{
+ "id" => activity.id,
+ "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+ "statusnet_html" => text,
+ "text" => text,
+ "is_local" => activity.local,
+ "is_post_verb" => false,
+ "uri" => "tag:#{activity.data["id"]}:objectType=Favourite",
+ "created_at" => created_at,
+ "in_reply_to_status_id" => liked_activity.id,
+ "external_url" => activity.data["id"],
+ "activity_type" => "like"
+ }
+ end
+
def render("activity.json", %{activity: %{data: %{"type" => "Create", "object" => object}} = activity} = opts) do
actor = get_in(activity.data, ["actor"])
user = User.get_cached_by_ap_id(actor)
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 76ce10724..244ffd5c4 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -24,7 +24,7 @@ test "a create activity with a note" do
"attentions" => [
UserView.render("show.json", %{user: other_user})
],
- "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime,
+ "created_at" => activity.data["object"]["published"] |> Utils.date_to_asctime(),
"external_url" => activity.data["object"]["id"],
"fave_num" => 0,
"favorited" => false,
@@ -37,7 +37,7 @@ test "a create activity with a note" do
"repeated" => false,
"statusnet_conversation_id" => convo_id,
"statusnet_html" =>
- "Hey @shp!",
+ "Hey @shp!",
"tags" => [],
"text" => "Hey @shp!",
"uri" => activity.data["object"]["id"],
@@ -46,4 +46,44 @@ test "a create activity with a note" do
assert result == expected
end
+
+ test "an activity that is a reply" do
+ user = insert(:user)
+ other_user = insert(:user, %{nickname: "shp"})
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+
+ {:ok, answer} =
+ CommonAPI.post(other_user, %{"status" => "Hi!", "in_reply_to_status_id" => activity.id})
+
+ result = ActivityView.render("activity.json", %{activity: answer})
+
+ assert result["in_reply_to_status_id"] == activity.id
+ end
+
+ test "a like activity" do
+ user = insert(:user)
+ other_user = insert(:user, %{nickname: "shp"})
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+ {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
+
+ result = ActivityView.render("activity.json", activity: like)
+
+ expected = %{
+ "activity_type" => "like",
+ "created_at" => like.data["published"] |> Utils.date_to_asctime(),
+ "external_url" => like.data["id"],
+ "id" => like.id,
+ "in_reply_to_status_id" => activity.id,
+ "is_local" => true,
+ "is_post_verb" => false,
+ "statusnet_html" => "shp favorited a status.",
+ "text" => "shp favorited a status.",
+ "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
+ "user" => UserView.render("show.json", user: other_user)
+ }
+
+ assert result == expected
+ end
end