Add unliking to TwAPI controller.
[akkoma] / lib / pleroma / web / twitter_api / representers / activity_representer.ex
index ed86559057be31b353896e6abda799c908ca101c..e69a63e1de8b4d55a2f097aaa9fbe6f5f9d2e49f 100644 (file)
@@ -45,6 +45,7 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
     created_at = get_in(activity.data, ["object", "published"])
     |> date_to_asctime
     like_count = get_in(activity.data, ["object", "like_count"]) || 0
+    favorited = opts[:for] && opts[:for].ap_id in (activity.data["object"]["likes"] || [])
 
     mentions = opts[:mentioned] || []
 
@@ -66,7 +67,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenter do
       "statusnet_conversation_id" => activity.data["object"]["statusnetConversationId"],
       "attachments" => (activity.data["object"]["attachment"] || []) |> ObjectRepresenter.enum_to_list(opts),
       "attentions" => attentions,
-      "fave_num" => like_count
+      "fave_num" => like_count,
+      "favorited" => !!favorited
     }
   end