logo

pleroma

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

marker_controller.ex (1491B)


  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.MastodonAPI.MarkerController do
  5. use Pleroma.Web, :controller
  6. alias Pleroma.Web.Plugs.OAuthScopesPlug
  7. plug(Pleroma.Web.ApiSpec.CastAndValidate)
  8. plug(
  9. OAuthScopesPlug,
  10. %{scopes: ["read:statuses"]}
  11. when action == :index
  12. )
  13. plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :upsert)
  14. action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
  15. defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MarkerOperation
  16. # GET /api/v1/markers
  17. def index(%{assigns: %{user: user}} = conn, params) do
  18. markers = Pleroma.Marker.get_markers(user, params[:timeline])
  19. render(conn, "markers.json", %{markers: markers})
  20. end
  21. # POST /api/v1/markers
  22. def upsert(%{assigns: %{user: user}, body_params: params} = conn, _) do
  23. params = Map.new(params, fn {key, value} -> {to_string(key), value} end)
  24. with {:ok, _} <- mark_notifications_read(user, params),
  25. {:ok, result} <- Pleroma.Marker.upsert(user, params),
  26. markers <- Map.values(result) do
  27. render(conn, "markers.json", %{markers: markers})
  28. end
  29. end
  30. defp mark_notifications_read(user, %{"notifications" => %{last_read_id: last_read_id}}) do
  31. Pleroma.Notification.set_read_up_to(user, last_read_id)
  32. end
  33. defp mark_notifications_read(_, _), do: {:ok, :noop}
  34. end