Migrate Pleroma.Web to phoenix 1.6 formats
[akkoma] / lib / pleroma / web / mastodon_api / views / notification_view.ex
index 83914a2755ef3156de2de8858fadb4b3c0ff94eb..e527ff608a2c029c69cf5a99b91e8d1403395df4 100644 (file)
@@ -17,7 +17,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
   alias Pleroma.Web.MastodonAPI.NotificationView
   alias Pleroma.Web.MastodonAPI.StatusView
 
-  @parent_types ~w{Like Announce EmojiReact}
+  defp object_id_for(%{data: %{"object" => %{"id" => id}}}) when is_binary(id), do: id
+
+  defp object_id_for(%{data: %{"object" => id}}) when is_binary(id), do: id
+
+  @parent_types ~w{Like Announce EmojiReact Update}
 
   def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
     activities = Enum.map(notifications, & &1.activity)
@@ -28,7 +32,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
         %{data: %{"type" => type}} ->
           type in @parent_types
       end)
-      |> Enum.map(& &1.data["object"])
+      |> Enum.map(&object_id_for/1)
       |> Activity.create_by_object_ap_id()
       |> Activity.with_preloaded_object(:left)
       |> Pleroma.Repo.all()
@@ -62,7 +66,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
       |> Map.put(:parent_activities, parent_activities)
       |> Map.put(:relationships, relationships_opt)
 
-    safe_render_many(notifications, NotificationView, "show.json", opts)
+    render_many(notifications, NotificationView, "show.json", opts)
   end
 
   def render(
@@ -76,9 +80,9 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
 
     parent_activity_fn = fn ->
       if opts[:parent_activities] do
-        Activity.Queries.find_by_object_ap_id(opts[:parent_activities], activity.data["object"])
+        Activity.Queries.find_by_object_ap_id(opts[:parent_activities], object_id_for(activity))
       else
-        Activity.get_create_by_object_ap_id(activity.data["object"])
+        Activity.get_create_by_object_ap_id(object_id_for(activity))
       end
     end
 
@@ -107,6 +111,9 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
       "reblog" ->
         put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
 
+      "update" ->
+        put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
+
       "move" ->
         put_target(response, activity, reading_user, %{})