Refactor SubscriptionNotificationView
This commit is contained in:
parent
e9f69a3eb7
commit
9fa2586abd
@ -7,11 +7,16 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationController do
|
|||||||
|
|
||||||
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
|
import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.SubscriptionNotification
|
alias Pleroma.SubscriptionNotification
|
||||||
|
alias Pleroma.User
|
||||||
alias Pleroma.Web.PleromaAPI.PleromaAPI
|
alias Pleroma.Web.PleromaAPI.PleromaAPI
|
||||||
|
|
||||||
def index(%{assigns: %{user: user}} = conn, params) do
|
def index(%{assigns: %{user: user}} = conn, params) do
|
||||||
notifications = PleromaAPI.get_subscription_notifications(user, params)
|
notifications =
|
||||||
|
user
|
||||||
|
|> PleromaAPI.get_subscription_notifications(params)
|
||||||
|
|> Enum.map(&build_notification_data/1)
|
||||||
|
|
||||||
conn
|
conn
|
||||||
|> add_link_headers(notifications)
|
|> add_link_headers(notifications)
|
||||||
@ -20,7 +25,10 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationController do
|
|||||||
|
|
||||||
def show(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
|
def show(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
|
||||||
with {:ok, notification} <- SubscriptionNotification.get(user, id) do
|
with {:ok, notification} <- SubscriptionNotification.get(user, id) do
|
||||||
render(conn, "show.json", %{subscription_notification: notification, for: user})
|
render(conn, "show.json", %{
|
||||||
|
subscription_notification: build_notification_data(notification),
|
||||||
|
for: user
|
||||||
|
})
|
||||||
else
|
else
|
||||||
{:error, reason} ->
|
{:error, reason} ->
|
||||||
conn
|
conn
|
||||||
@ -52,4 +60,12 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationController do
|
|||||||
SubscriptionNotification.destroy_multiple(user, ids)
|
SubscriptionNotification.destroy_multiple(user, ids)
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp build_notification_data(%{activity: %{data: data}} = notification) do
|
||||||
|
%{
|
||||||
|
notification: notification,
|
||||||
|
actor: User.get_cached_by_ap_id(data["actor"]),
|
||||||
|
parent_activity: Activity.get_create_by_object_ap_id(data["object"])
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,6 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationView do
|
|||||||
use Pleroma.Web, :view
|
use Pleroma.Web, :view
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Web.CommonAPI
|
alias Pleroma.Web.CommonAPI
|
||||||
alias Pleroma.Web.MastodonAPI.AccountView
|
alias Pleroma.Web.MastodonAPI.AccountView
|
||||||
alias Pleroma.Web.MastodonAPI.StatusView
|
alias Pleroma.Web.MastodonAPI.StatusView
|
||||||
@ -17,11 +16,13 @@ defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationView do
|
|||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{
|
def render("show.json", %{
|
||||||
subscription_notification: %{activity: activity} = notification,
|
subscription_notification: %{
|
||||||
|
notification: %{activity: activity} = notification,
|
||||||
|
actor: actor,
|
||||||
|
parent_activity: parent_activity
|
||||||
|
},
|
||||||
for: user
|
for: user
|
||||||
}) do
|
}) do
|
||||||
actor = User.get_cached_by_ap_id(activity.data["actor"])
|
|
||||||
parent_activity = Activity.get_create_by_object_ap_id(activity.data["object"])
|
|
||||||
mastodon_type = Activity.mastodon_notification_type(activity)
|
mastodon_type = Activity.mastodon_notification_type(activity)
|
||||||
|
|
||||||
response = %{
|
response = %{
|
||||||
|
Loading…
Reference in New Issue
Block a user