added recount unread notifications to markers
[akkoma] / lib / pleroma / web / mastodon_api / controllers / marker_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.MastodonAPI.MarkerController do
6 use Pleroma.Web, :controller
7 alias Pleroma.Plugs.OAuthScopesPlug
8
9 plug(
10 OAuthScopesPlug,
11 %{scopes: ["read:statuses"]}
12 when action == :index
13 )
14
15 plug(OAuthScopesPlug, %{scopes: ["write:statuses"]} when action == :upsert)
16 plug(Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug)
17 action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
18
19 # GET /api/v1/markers
20 def index(%{assigns: %{user: user}} = conn, params) do
21 markers =
22 Pleroma.Marker.get_markers(
23 user,
24 params["timeline"],
25 %{recount_unread: true}
26 )
27
28 render(conn, "markers.json", %{markers: markers})
29 end
30
31 # POST /api/v1/markers
32 def upsert(%{assigns: %{user: user}} = conn, params) do
33 with {:ok, result} <- Pleroma.Marker.upsert(user, params),
34 markers <- Map.values(result) do
35 render(conn, "markers.json", %{markers: markers})
36 end
37 end
38 end