diff options
author | eal <eal@waifu.club> | 2018-04-19 21:46:59 +0300 |
---|---|---|
committer | eal <eal@waifu.club> | 2018-04-19 21:46:59 +0300 |
commit | fa37acfcc75d069aaaea0b00e619f716e5d6a19a (patch) | |
tree | e10e5a098b641969da97ab95a4d4ef3d19787106 /lib/pleroma/web/twitter_api/views | |
parent | 7b96a756fbcc6f814e70ad1b9ad6bd45844ea734 (diff) | |
download | pleroma-fa37acfcc75d069aaaea0b00e619f716e5d6a19a.tar.gz |
TwitterAPI: Add Qvitter notification endpoint.
Diffstat (limited to 'lib/pleroma/web/twitter_api/views')
-rw-r--r-- | lib/pleroma/web/twitter_api/views/notification_view.ex | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex new file mode 100644 index 000000000..4e1ba0b54 --- /dev/null +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -0,0 +1,47 @@ +defmodule Pleroma.Web.TwitterAPI.NotificationView do + use Pleroma.Web, :view + alias Pleroma.{Notification, User} + alias Pleroma.Web.CommonAPI.Utils + alias Pleroma.Web.MediaProxy + alias Pleroma.Web.TwitterAPI.UserView + alias Pleroma.Web.TwitterAPI.ActivityView + + 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 + render_many(notifications, Pleroma.Web.TwitterAPI.NotificationView, "notification.json", for: user) + end + + 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 + 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}), + "is_seen" => (if seen, do: 1, else: 0), + "created_at" => created_at |> Utils.format_naive_asctime() + } + end +end |