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 require Pleroma.Constants
15 defp get_user(ap_id, opts) do
17 user = opts[:users][ap_id] ->
20 String.ends_with?(ap_id, "/followers") ->
23 ap_id == Pleroma.Constants.as_public() ->
27 User.get_cached_by_ap_id(ap_id)
31 def render("notification.json", %{notifications: notifications, for: user}) do
34 Pleroma.Web.TwitterAPI.NotificationView,
43 notification: %Notification{
47 inserted_at: created_at
53 case activity.data["type"] do
56 "Announce" -> "repeat"
60 from = get_user(activity.data["actor"], opts)
65 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
66 "from_profile" => UserView.render("show.json", %{user: from, for: user}),
67 "is_seen" => if(seen, do: 1, else: 0),
68 "created_at" => created_at |> Utils.format_naive_asctime()