2018-12-23 20:04:54 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2018-12-31 15:41:47 +00:00
|
|
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
2018-12-23 20:04:54 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-04-19 18:46:59 +00:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.NotificationView do
|
|
|
|
use Pleroma.Web, :view
|
|
|
|
alias Pleroma.{Notification, User}
|
|
|
|
alias Pleroma.Web.CommonAPI.Utils
|
2019-02-06 19:20:02 +00:00
|
|
|
alias Pleroma.Web.TwitterAPI.{ActivityView, UserView}
|
2018-04-19 18:46:59 +00:00
|
|
|
|
|
|
|
defp get_user(ap_id, opts) do
|
|
|
|
cond do
|
|
|
|
user = opts[:users][ap_id] ->
|
|
|
|
user
|
|
|
|
|
|
|
|
String.ends_with?(ap_id, "/followers") ->
|
|
|
|
nil
|
|
|
|
|
|
|
|
ap_id == "https://www.w3.org/ns/activitystreams#Public" ->
|
|
|
|
nil
|
|
|
|
|
|
|
|
true ->
|
|
|
|
User.get_cached_by_ap_id(ap_id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def render("notification.json", %{notifications: notifications, for: user}) do
|
2018-04-20 11:10:57 +00:00
|
|
|
render_many(
|
|
|
|
notifications,
|
|
|
|
Pleroma.Web.TwitterAPI.NotificationView,
|
|
|
|
"notification.json",
|
|
|
|
for: user
|
|
|
|
)
|
2018-04-19 18:46:59 +00:00
|
|
|
end
|
|
|
|
|
2018-04-20 11:10:57 +00:00
|
|
|
def render(
|
|
|
|
"notification.json",
|
|
|
|
%{
|
|
|
|
notification: %Notification{
|
|
|
|
id: id,
|
|
|
|
seen: seen,
|
|
|
|
activity: activity,
|
|
|
|
inserted_at: created_at
|
|
|
|
},
|
|
|
|
for: user
|
|
|
|
} = opts
|
|
|
|
) do
|
|
|
|
ntype =
|
|
|
|
case activity.data["type"] do
|
|
|
|
"Create" -> "mention"
|
|
|
|
"Like" -> "like"
|
|
|
|
"Announce" -> "repeat"
|
|
|
|
"Follow" -> "follow"
|
|
|
|
end
|
|
|
|
|
2018-04-19 18:46:59 +00:00
|
|
|
from = get_user(activity.data["actor"], opts)
|
|
|
|
|
|
|
|
%{
|
|
|
|
"id" => id,
|
|
|
|
"ntype" => ntype,
|
|
|
|
"notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
|
|
|
|
"from_profile" => UserView.render("show.json", %{user: from, for: user}),
|
2018-04-20 11:10:57 +00:00
|
|
|
"is_seen" => if(seen, do: 1, else: 0),
|
2018-04-19 18:46:59 +00:00
|
|
|
"created_at" => created_at |> Utils.format_naive_asctime()
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|