logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

notification_controller.ex (1377B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.PleromaAPI.NotificationController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Notification
  7. plug(Pleroma.Web.ApiSpec.CastAndValidate, replace_params: false)
  8. plug(
  9. Pleroma.Web.Plugs.OAuthScopesPlug,
  10. %{scopes: ["write:notifications"]} when action == :mark_as_read
  11. )
  12. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaNotificationOperation
  13. def mark_as_read(
  14. %{
  15. assigns: %{user: user},
  16. private: %{open_api_spex: %{body_params: %{id: notification_id}}}
  17. } = conn,
  18. _
  19. ) do
  20. with {:ok, _} <- Notification.read_one(user, notification_id) do
  21. conn
  22. |> json("ok")
  23. else
  24. {:error, message} ->
  25. conn
  26. |> put_status(:bad_request)
  27. |> json(%{"error" => message})
  28. end
  29. end
  30. def mark_as_read(
  31. %{assigns: %{user: user}, private: %{open_api_spex: %{body_params: %{max_id: max_id}}}} =
  32. conn,
  33. _
  34. ) do
  35. with {:ok, _} <- Notification.set_read_up_to(user, max_id) do
  36. conn
  37. |> json("ok")
  38. else
  39. {:error, message} ->
  40. conn
  41. |> put_status(:bad_request)
  42. |> json(%{"error" => message})
  43. end
  44. end
  45. end