logo

pleroma

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

notification_controller.ex (1371B)


  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} <- Notification.read_one(user, notification_id) do
  21. render(conn, "show.json", notification: notification, for: user)
  22. else
  23. {:error, message} ->
  24. conn
  25. |> put_status(:bad_request)
  26. |> json(%{"error" => message})
  27. end
  28. end
  29. def mark_as_read(
  30. %{assigns: %{user: user}, private: %{open_api_spex: %{body_params: %{max_id: max_id}}}} =
  31. conn,
  32. _
  33. ) do
  34. notifications =
  35. user
  36. |> Notification.set_read_up_to(max_id)
  37. |> Enum.take(80)
  38. render(conn, "index.json", notifications: notifications, for: user)
  39. end
  40. end