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.TwitterAPI.NotificationView do
7 alias Pleroma.{Notification, User}
8 alias Pleroma.Web.CommonAPI.Utils
9 alias Pleroma.Web.TwitterAPI.UserView
10 alias Pleroma.Web.TwitterAPI.ActivityView
12 defp get_user(ap_id, opts) do
14 user = opts[:users][ap_id] ->
17 String.ends_with?(ap_id, "/followers") ->
20 ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
24 User.get_cached_by_ap_id(ap_id)
28 def render("notification.json", %{notifications: notifications, for: user}) do
31 Pleroma.Web.TwitterAPI.NotificationView,
40 notification: %Notification{
44 inserted_at: created_at
50 case activity.data["type"] do
53 "Announce" -> "repeat"
57 from = get_user(activity.data["actor"], opts)
62 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
63 "from_profile" => UserView.render("show.json", %{user: from, for: user}),
64 "is_seen" => if(seen, do: 1, else: 0),
65 "created_at" => created_at |> Utils.format_naive_asctime()