1 defmodule Pleroma.Web.TwitterAPI.NotificationView do
3 alias Pleroma.{Notification, User}
4 alias Pleroma.Web.CommonAPI.Utils
5 alias Pleroma.Web.MediaProxy
6 alias Pleroma.Web.TwitterAPI.UserView
7 alias Pleroma.Web.TwitterAPI.ActivityView
9 defp get_user(ap_id, opts) do
11 user = opts[:users][ap_id] ->
14 String.ends_with?(ap_id, "/followers") ->
17 ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
21 User.get_cached_by_ap_id(ap_id)
25 def render("notification.json", %{notifications: notifications, for: user}) do
26 render_many(notifications, Pleroma.Web.TwitterAPI.NotificationView, "notification.json", for: user)
29 def render("notification.json", %{notification: %Notification{id: id, seen: seen, activity: activity, inserted_at: created_at}, for: user} = opts) do
30 ntype = case activity.data["type"] do
33 "Announce" -> "repeat"
36 from = get_user(activity.data["actor"], opts)
41 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
42 "from_profile" => UserView.render("show.json", %{user: from, for: user}),
43 "is_seen" => (if seen, do: 1, else: 0),
44 "created_at" => created_at |> Utils.format_naive_asctime()