pleroma/lib/pleroma/web/pleroma_api/controllers/notification_controller.ex
Mark Felder 26a95e5787 Pleroma.Web.PleromaAPI.NotificationController: dialyzer errors
lib/pleroma/web/pleroma_api/controllers/user_import_controller.ex:53:call
The function call will not succeed.

Phoenix.Controller.json(
  _conn :: %{
    :assigns => %{:user => _, _ => _},
    :body_params => %{:list => _, _ => _},
    _ => _
  },
  <<106, 111, 98, 32, 115, 116, 97, 114, 116, 101, 100>>
)

breaks the contract
(Plug.Conn.t(), term()) :: Plug.Conn.t()
2024-01-27 16:15:03 -05:00

39 lines
1.2 KiB
Elixir

# Pleroma: A lightweight social networking server
# Copyright © 2017-2022 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
plug(Pleroma.Web.ApiSpec.CastAndValidate)
plug(
Pleroma.Web.Plugs.OAuthScopesPlug,
%{scopes: ["write:notifications"]} when action == :mark_as_read
)
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation
def mark_as_read(%{assigns: %{user: user}, body_params: %{"id" => notification_id}} = conn, _) 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}, body_params: %{"max_id" => max_id}} = conn, _) do
notifications =
user
|> Notification.set_read_up_to(max_id)
|> Enum.take(80)
render(conn, "index.json", notifications: notifications, for: user)
end
end