1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.PleromaAPI.NotificationController do
6 use Pleroma.Web, :controller
8 alias Pleroma.Notification
10 plug(Pleroma.Web.ApiSpec.CastAndValidate)
13 Pleroma.Web.Plugs.OAuthScopesPlug,
14 %{scopes: ["write:notifications"]} when action == :mark_as_read
17 defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation
19 def mark_as_read(%{assigns: %{user: user}, body_params: %{id: notification_id}} = conn, _) do
20 with {:ok, notification} <- Notification.read_one(user, notification_id) do
21 render(conn, "show.json", notification: notification, for: user)
25 |> put_status(:bad_request)
26 |> json(%{"error" => message})
30 def mark_as_read(%{assigns: %{user: user}, body_params: %{max_id: max_id}} = conn, _) do
33 |> Notification.set_read_up_to(max_id)
36 render(conn, "index.json", notifications: notifications, for: user)