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.{ActivityView, UserView}
11 defp get_user(ap_id, opts) do
13 user = opts[:users][ap_id] ->
16 String.ends_with?(ap_id, "/followers") ->
19 ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
23 User.get_cached_by_ap_id(ap_id)
27 def render("notification.json", %{notifications: notifications, for: user}) do
30 Pleroma.Web.TwitterAPI.NotificationView,
39 notification: %Notification{
43 inserted_at: created_at
49 case activity.data["type"] do
52 "Announce" -> "repeat"
56 from = get_user(activity.data["actor"], opts)
61 "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
62 "from_profile" => UserView.render("show.json", %{user: from, for: user}),
63 "is_seen" => if(seen, do: 1, else: 0),
64 "created_at" => created_at |> Utils.format_naive_asctime()