X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Fmastodon_api%2Fviews%2Fnotification_view.ex;h=33145c484d6f74fe03e95a88292ebd9cb58d2bc1;hb=86f2fbc81e5f3df6c16e05127e9e39c8fca0cde9;hp=ec8eadcaab88af0d648db975670fa0179fedaeb8;hpb=3e30f6e19824dc90717fc0929feddb24220a89ab;p=akkoma
diff --git a/lib/pleroma/web/mastodon_api/views/notification_view.ex b/lib/pleroma/web/mastodon_api/views/notification_view.ex
index ec8eadcaa..33145c484 100644
--- a/lib/pleroma/web/mastodon_api/views/notification_view.ex
+++ b/lib/pleroma/web/mastodon_api/views/notification_view.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.NotificationView do
@@ -25,40 +25,55 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
mastodon_type = Activity.mastodon_notification_type(activity)
- response = %{
- id: to_string(notification.id),
- type: mastodon_type,
- created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
- account: AccountView.render("account.json", %{user: actor, for: user}),
- pleroma: %{
- is_seen: notification.seen
+ with %{id: _} = account <- AccountView.render("show.json", %{user: actor, for: user}) do
+ response = %{
+ id: to_string(notification.id),
+ type: mastodon_type,
+ created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
+ account: account,
+ pleroma: %{
+ is_seen: notification.seen
+ }
}
- }
- case mastodon_type do
- "mention" ->
- response
- |> Map.merge(%{
- status: StatusView.render("status.json", %{activity: activity, for: user})
- })
+ case mastodon_type do
+ "mention" ->
+ put_status(response, activity, user)
- "favourite" ->
- response
- |> Map.merge(%{
- status: StatusView.render("status.json", %{activity: parent_activity, for: user})
- })
+ "favourite" ->
+ put_status(response, parent_activity, user)
- "reblog" ->
- response
- |> Map.merge(%{
- status: StatusView.render("status.json", %{activity: parent_activity, for: user})
- })
+ "reblog" ->
+ put_status(response, parent_activity, user)
- "follow" ->
- response
+ "move" ->
+ put_target(response, activity, user)
- _ ->
- nil
+ "follow" ->
+ response
+
+ "pleroma:emoji_reaction" ->
+ put_status(response, parent_activity, user) |> put_emoji(activity)
+
+ _ ->
+ nil
+ end
+ else
+ _ -> nil
end
end
+
+ defp put_emoji(response, activity) do
+ response
+ |> Map.put(:emoji, activity.data["content"])
+ end
+
+ defp put_status(response, activity, user) do
+ Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
+ end
+
+ defp put_target(response, activity, user) do
+ target = User.get_cached_by_ap_id(activity.data["target"])
+ Map.put(response, :target, AccountView.render("show.json", %{user: target, for: user}))
+ end
end