X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Ftwitter_api%2Fviews%2Fnotification_view.ex;h=e7c7a74964d06f832c30b9355aed88a12340edb3;hb=6a6a5b3251f7137e30b687a9a8448e678446f8b0;hp=4e1ba0b544604fd8bfa6a06486ebdf849bf8db02;hpb=193be32f45df3194c5cfa99f98cfc6900282d368;p=akkoma diff --git a/lib/pleroma/web/twitter_api/views/notification_view.ex b/lib/pleroma/web/twitter_api/views/notification_view.ex index 4e1ba0b54..e7c7a7496 100644 --- a/lib/pleroma/web/twitter_api/views/notification_view.ex +++ b/lib/pleroma/web/twitter_api/views/notification_view.ex @@ -1,10 +1,14 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2019 Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only + defmodule Pleroma.Web.TwitterAPI.NotificationView do use Pleroma.Web, :view - alias Pleroma.{Notification, User} + alias Pleroma.Notification + alias Pleroma.User alias Pleroma.Web.CommonAPI.Utils - alias Pleroma.Web.MediaProxy - alias Pleroma.Web.TwitterAPI.UserView alias Pleroma.Web.TwitterAPI.ActivityView + alias Pleroma.Web.TwitterAPI.UserView defp get_user(ap_id, opts) do cond do @@ -23,16 +27,34 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do end def render("notification.json", %{notifications: notifications, for: user}) do - render_many(notifications, Pleroma.Web.TwitterAPI.NotificationView, "notification.json", for: user) + 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 + 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) %{ @@ -40,7 +62,7 @@ defmodule Pleroma.Web.TwitterAPI.NotificationView do "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), + "is_seen" => if(seen, do: 1, else: 0), "created_at" => created_at |> Utils.format_naive_asctime() } end