1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.NotificationView do
9 alias Pleroma.Notification
11 alias Pleroma.Web.CommonAPI
12 alias Pleroma.Web.MastodonAPI.AccountView
13 alias Pleroma.Web.MastodonAPI.NotificationView
14 alias Pleroma.Web.MastodonAPI.StatusView
16 def render("index.json", %{notifications: notifications, for: user}) do
17 safe_render_many(notifications, NotificationView, "show.json", %{for: user})
20 def render("show.json", %{
21 notification: %Notification{activity: activity} = notification,
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)
28 with %{id: _} = account <- AccountView.render("show.json", %{user: actor, for: user}) do
30 id: to_string(notification.id),
32 created_at: CommonAPI.Utils.to_masto_date(notification.inserted_at),
35 is_seen: notification.seen
40 "mention" -> put_status(response, activity, user)
41 "favourite" -> put_status(response, parent_activity, user)
42 "reblog" -> put_status(response, parent_activity, user)
43 "move" -> put_target(response, activity, user)
52 defp put_status(response, activity, user) do
53 Map.put(response, :status, StatusView.render("show.json", %{activity: activity, for: user}))
56 defp put_target(response, activity, user) do
57 target = User.get_cached_by_ap_id(activity.data["target"])
58 Map.put(response, :target, AccountView.render("show.json", %{user: target, for: user}))