Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into develop
[akkoma] / lib / pleroma / web / twitter_api / views / activity_view.ex
index 76b8cb14bb92d37895e4888487fe48ce71b91eee..50d536d0ea2d56a75ca70457175b73d3934424e3 100644 (file)
@@ -5,8 +5,58 @@ 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" => "Announce"}} = activity} = opts) do
+    user = User.get_by_ap_id(activity.data["actor"])
+    created_at = activity.data["published"] |> Utils.date_to_asctime
+    announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
+
+    text = "#{user.nickname} retweeted a status."
+
+    # retweeted_status = to_map(announced_activity, Map.merge(%{user: announced_user}, opts))
+    retweeted_status = render("activity.json", Map.merge(opts, %{activity: announced_activity}))
+
+    %{
+      "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=note",
+      "created_at" => created_at,
+      "retweeted_status" => retweeted_status,
+      "statusnet_conversation_id" => conversation_id(announced_activity),
+      "external_url" => activity.data["id"],
+      "activity_type" => "repeat"
+    }
+  end
+
+  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)
@@ -37,7 +87,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
       content
     end
 
-    html = HtmlSanitizeEx.basic_html(content) |> Formatter.emojify(object["emoji"])
+    html = HtmlSanitizeEx.basic_html(content)
+    |> Formatter.emojify(object["emoji"])
 
     %{
       "id" => activity.id,