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
9 alias Pleroma.Web.CommonAPI.Utils
10 alias Pleroma.Web.TwitterAPI.ActivityView
11 alias Pleroma.Web.TwitterAPI.UserView
13 defp get_user(ap_id, opts) do
15 user = opts[:users][ap_id] ->
18 String.ends_with?(ap_id, "/followers") ->
21 ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
25 User.get_cached_by_ap_id(ap_id)
29 def render("notification.json", %{notifications: notifications, for: user}) do
32 Pleroma.Web.TwitterAPI.NotificationView,
41 notification: %Notification{
45 inserted_at: created_at
51 case activity.data["type"] do
54 "Announce" -> "repeat"
58 from = get_user(activity.data["actor"], opts)
63 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
64 "from_profile" => UserView.render("show.json", %{user: from, for: user}),
65 "is_seen" => if(seen, do: 1, else: 0),
66 "created_at" => created_at |> Utils.format_naive_asctime()