aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/pleroma_api
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2020-05-20 15:14:11 +0400
committerEgor Kislitsyn <egor@kislitsyn.com>2020-05-20 15:15:13 +0400
commit5ba6e1c322c0937849eca53fc816f348659fb34c (patch)
treea4cd1b07029036d51a8c8fad9b57deffd4fa9b7c /lib/pleroma/web/pleroma_api
parentf3fc8b22b1dca8d432d066417e2bb9b62a3f1520 (diff)
downloadpleroma-5ba6e1c322c0937849eca53fc816f348659fb34c.tar.gz
Move notification actions to PleromaAPI.NotificationController
Diffstat (limited to 'lib/pleroma/web/pleroma_api')
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/notification_controller.ex36
-rw-r--r--lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex46
2 files changed, 36 insertions, 46 deletions
diff --git a/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex b/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex
new file mode 100644
index 000000000..0b2f678c5
--- /dev/null
+++ b/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex
@@ -0,0 +1,36 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.PleromaAPI.NotificationController do
+ use Pleroma.Web, :controller
+
+ alias Pleroma.Notification
+ alias Pleroma.Plugs.OAuthScopesPlug
+
+ plug(Pleroma.Web.ApiSpec.CastAndValidate)
+ plug(OAuthScopesPlug, %{scopes: ["write:notifications"]} when action == :mark_as_read)
+ plug(:put_view, Pleroma.Web.MastodonAPI.NotificationView)
+
+ defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation
+
+ def mark_as_read(%{assigns: %{user: user}} = conn, %{id: notification_id}) do
+ with {:ok, notification} <- Notification.read_one(user, notification_id) do
+ render(conn, "show.json", notification: notification, for: user)
+ else
+ {:error, message} ->
+ conn
+ |> put_status(:bad_request)
+ |> json(%{"error" => message})
+ end
+ end
+
+ def mark_as_read(%{assigns: %{user: user}} = conn, %{max_id: max_id}) do
+ notifications =
+ user
+ |> Notification.set_read_up_to(max_id)
+ |> Enum.take(80)
+
+ render(conn, "index.json", notifications: notifications, for: user)
+ end
+end
diff --git a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex b/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
deleted file mode 100644
index a58665abe..000000000
--- a/lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
+++ /dev/null
@@ -1,46 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
- use Pleroma.Web, :controller
-
- alias Pleroma.Notification
- alias Pleroma.Plugs.OAuthScopesPlug
- alias Pleroma.Web.MastodonAPI.NotificationView
-
- plug(Pleroma.Web.ApiSpec.CastAndValidate)
-
- plug(
- OAuthScopesPlug,
- %{scopes: ["write:notifications"]} when action == :mark_notifications_as_read
- )
-
- defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaOperation
-
- def mark_notifications_as_read(%{assigns: %{user: user}} = conn, %{id: notification_id}) do
- with {:ok, notification} <- Notification.read_one(user, notification_id) do
- conn
- |> put_view(NotificationView)
- |> render("show.json", %{notification: notification, for: user})
- else
- {:error, message} ->
- conn
- |> put_status(:bad_request)
- |> json(%{"error" => message})
- end
- end
-
- def mark_notifications_as_read(%{assigns: %{user: user}} = conn, %{max_id: max_id}) do
- with notifications <- Notification.set_read_up_to(user, max_id) do
- notifications = Enum.take(notifications, 80)
-
- conn
- |> put_view(NotificationView)
- |> render("index.json",
- notifications: notifications,
- for: user
- )
- end
- end
-end