1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.MastodonAPI.NotificationController do
6 use Pleroma.Web, :controller
8 import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
10 alias Pleroma.Notification
11 alias Pleroma.Web.MastodonAPI.MastodonAPI
13 # GET /api/v1/notifications
14 def index(%{assigns: %{user: user}} = conn, params) do
15 notifications = MastodonAPI.get_notifications(user, params)
18 |> add_link_headers(notifications)
19 |> render("index.json", notifications: notifications, for: user)
22 # GET /api/v1/notifications/:id
23 def show(%{assigns: %{user: user}} = conn, %{"id" => id}) do
24 with {:ok, notification} <- Notification.get(user, id) do
25 render(conn, "show.json", notification: notification, for: user)
29 |> put_status(:forbidden)
30 |> json(%{"error" => reason})
34 # POST /api/v1/notifications/clear
35 def clear(%{assigns: %{user: user}} = conn, _params) do
36 Notification.clear(user)
40 # POST /api/v1/notifications/dismiss
41 def dismiss(%{assigns: %{user: user}} = conn, %{"id" => id} = _params) do
42 with {:ok, _notif} <- Notification.dismiss(user, id) do
47 |> put_status(:forbidden)
48 |> json(%{"error" => reason})
52 # DELETE /api/v1/notifications/destroy_multiple
53 def destroy_multiple(%{assigns: %{user: user}} = conn, %{"ids" => ids} = _params) do
54 Notification.destroy_multiple(user, ids)