Remove vapidPublicKey from Nodeinfo
[akkoma] / lib / pleroma / web / mastodon_api / views / notification_view.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.NotificationView do
6 use Pleroma.Web, :view
7
8 alias Pleroma.Activity
9 alias Pleroma.Notification
10 alias Pleroma.User
11 alias Pleroma.Web.CommonAPI
12 alias Pleroma.Web.MastodonAPI.AccountView
13 alias Pleroma.Web.MastodonAPI.NotificationView
14 alias Pleroma.Web.MastodonAPI.StatusView
15
16 def render("index.json", %{notifications: notifications, for: user}) do
17 safe_render_many(notifications, NotificationView, "show.json", %{for: user})
18 end
19
20 def render("show.json", %{
21 notification: %Notification{activity: activity} = notification,
22 for: user
23 }) do
24 actor = User.get_cached_by_ap_id(activity.data["actor"])
25 parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
26 mastodon_type = Activity.mastodon_notification_type(activity)
27
28 with %{id: _} = account <- AccountView.render("show.json", %{user: actor, for: user}) do
29 response = %{
30 id: to_string(notification.id),
31 type: mastodon_type,
32 created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
33 account: account,
34 pleroma: %{
35 is_seen: notification.seen
36 }
37 }
38
39 case mastodon_type do
40 "mention" ->
41 put_status(response, activity, user)
42
43 "favourite" ->
44 put_status(response, parent_activity, user)
45
46 "reblog" ->
47 put_status(response, parent_activity, user)
48
49 "move" ->
50 put_target(response, activity, user)
51
52 "follow" ->
53 response
54
55 "pleroma:emoji_reaction" ->
56 put_status(response, parent_activity, user) |> put_emoji(activity)
57
58 _ ->
59 nil
60 end
61 else
62 _ -> nil
63 end
64 end
65
66 defp put_emoji(response, activity) do
67 response
68 |> Map.put(:emoji, activity.data["content"])
69 end
70
71 defp put_status(response, activity, user) do
72 Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
73 end
74
75 defp put_target(response, activity, user) do
76 target = User.get_cached_by_ap_id(activity.data["target"])
77 Map.put(response, :target, AccountView.render("show.json", %{user: target, for: user}))
78 end
79 end