Fix conflict
[akkoma] / lib / pleroma / web / twitter_api / views / activity_view.ex
index 520f0aa369d99042bb07aeb43222a48d4c9c42dd..3e69af3e382967b8fbad822a0a0c22d025b24640 100644 (file)
@@ -3,16 +3,96 @@ 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()
+    announced_activity = Activity.get_create_activity_by_object_ap_id(activity.data["object"])
+
+    text = "#{user.nickname} retweeted a status."
+
+    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
+
+    created_at =
+      activity.data["published"]
+      |> Utils.date_to_asctime()
 
     text = "#{user.nickname} favorited a status."
 
@@ -31,20 +111,24 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
     }
   end
 
-  def render("activity.json", %{activity: %{data: %{"type" => "Create", "object" => object}} = activity} = opts) do
+  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)
 
-    created_at = object["published"] |> Utils.date_to_asctime
+    created_at = object["published"] |> Utils.date_to_asctime()
     like_count = object["like_count"] || 0
     announcement_count = object["announcement_count"] || 0
     favorited = opts[:for] && opts[:for].ap_id in (object["likes"] || [])
     repeated = opts[:for] && opts[:for].ap_id in (object["announcements"] || [])
 
-    attentions = activity.recipients
-    |> Enum.map(fn (ap_id) -> User.get_cached_by_ap_id(ap_id) end)
-    |> Enum.filter(&(&1))
-    |> Enum.map(fn (user) -> UserView.render("show.json", %{user: user, for: opts[:for]}) end)
+    attentions =
+      activity.recipients
+      |> Enum.map(fn ap_id -> User.get_cached_by_ap_id(ap_id) end)
+      |> Enum.filter(& &1)
+      |> Enum.map(fn user -> UserView.render("show.json", %{user: user, for: opts[:for]}) end)
 
     conversation_id = conversation_id(activity)
 
@@ -55,14 +139,17 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
 
     summary = activity.data["object"]["summary"]
     content = object["content"]
-    content = if !!summary and summary != "" do
-      "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
-    else
-      content
-    end
 
-    html = HtmlSanitizeEx.basic_html(content)
-    |> Formatter.emojify(object["emoji"])
+    content =
+      if !!summary and summary != "" do
+        "<span>#{activity.data["object"]["summary"]}</span><br />#{content}</span>"
+      else
+        content
+      end
+
+    html =
+      HtmlSanitizeEx.basic_html(content)
+      |> Formatter.emojify(object["emoji"])
 
     %{
       "id" => activity.id,
@@ -91,7 +178,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityView do
   defp conversation_id(activity) do
     with context when not is_nil(context) <- activity.data["context"] do
       TwitterAPI.context_to_conversation_id(context)
-    else _e -> nil
+    else
+      _e -> nil
     end
   end
 end