2020-05-20 11:14:11 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2020-05-20 11:14:11 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.PleromaAPI.NotificationController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
alias Pleroma.Notification
|
|
|
|
|
2024-01-31 00:15:11 +00:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
|
2020-06-24 06:57:27 +00:00
|
|
|
|
|
|
|
plug(
|
|
|
|
Pleroma.Web.Plugs.OAuthScopesPlug,
|
|
|
|
%{scopes: ["write:notifications"]} when action == :mark_as_read
|
|
|
|
)
|
|
|
|
|
2020-05-20 11:14:11 +00:00
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation
|
|
|
|
|
2024-01-31 00:15:11 +00:00
|
|
|
def mark_as_read(
|
|
|
|
%{
|
|
|
|
assigns: %{user: user},
|
|
|
|
private: %{open_api_spex: %{body_params: %{id: notification_id}}}
|
|
|
|
} = conn,
|
|
|
|
_
|
|
|
|
) do
|
2020-05-20 11:14:11 +00:00
|
|
|
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
|
|
|
|
|
2024-01-31 00:15:11 +00:00
|
|
|
def mark_as_read(
|
|
|
|
%{assigns: %{user: user}, private: %{open_api_spex: %{body_params: %{max_id: max_id}}}} =
|
|
|
|
conn,
|
|
|
|
_
|
|
|
|
) do
|
2020-05-20 11:14:11 +00:00
|
|
|
notifications =
|
|
|
|
user
|
|
|
|
|> Notification.set_read_up_to(max_id)
|
|
|
|
|> Enum.take(80)
|
|
|
|
|
|
|
|
render(conn, "index.json", notifications: notifications, for: user)
|
|
|
|
end
|
|
|
|
end
|