Fix conflict
[akkoma] / lib / pleroma / web / twitter_api / views / activity_view.ex
index 1596b34dca1ac29b08ecd289194cbae082d034af..3e69af3e382967b8fbad822a0a0c22d025b24640 100644 (file)
@@ -3,11 +3,64 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
   alias Pleroma.Web.CommonAPI.Utils
   alias Pleroma.User
   alias Pleroma.Web.TwitterAPI.UserView
+  alias Pleroma.Web.TwitterAPI.ActivityView
   alias Pleroma.Web.TwitterAPI.TwitterAPI
   alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
   alias Pleroma.Activity
   alias Pleroma.Formatter
 
+  def render("index.json", opts) do
+    render_many(
+      opts.activities,
+      ActivityView,
+      "activity.json",
+      opts
+    )
+  end
+
+  def render("activity.json", %{activity: %{data: %{"type" => "Delete"}} = activity} = opts) do
+    user = User.get_cached_by_ap_id(activity.data["actor"])
+    created_at = activity.data["published"] |> Utils.date_to_asctime()
+
+    %{
+      "id" => activity.id,
+      "uri" => activity.data["object"],
+      "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+      "attentions" => [],
+      "statusnet_html" => "deleted notice {{tag",
+      "text" => "deleted notice {{tag",
+      "is_local" => activity.local,
+      "is_post_verb" => false,
+      "created_at" => created_at,
+      "in_reply_to_status_id" => nil,
+      "external_url" => activity.data["id"],
+      "activity_type" => "delete"
+    }
+  end
+
+  def render("activity.json", %{activity: %{data: %{"type" => "Follow"}} = activity} = opts) do
+    user = User.get_cached_by_ap_id(activity.data["actor"])
+    created_at = activity.data["published"] || DateTime.to_iso8601(activity.inserted_at)
+    created_at = created_at |> Utils.date_to_asctime()
+
+    followed = User.get_cached_by_ap_id(activity.data["object"])
+    text = "#{user.nickname} started following #{followed.nickname}"
+
+    %{
+      "id" => activity.id,
+      "user" => UserView.render("show.json", %{user: user, for: opts[:for]}),
+      "attentions" => [],
+      "statusnet_html" => text,
+      "text" => text,
+      "is_local" => activity.local,
+      "is_post_verb" => false,
+      "created_at" => created_at,
+      "in_reply_to_status_id" => nil,
+      "external_url" => activity.data["id"],
+      "activity_type" => "follow"
+    }
+  end
+
   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()
@@ -15,7 +68,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
 
     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}))
 
     %{