1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ApiSpec.NotificationOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Operation
8 alias OpenApiSpex.Schema
9 alias Pleroma.Web.ApiSpec.Schemas.Account
10 alias Pleroma.Web.ApiSpec.Schemas.ApiError
11 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
12 alias Pleroma.Web.ApiSpec.Schemas.Status
13 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
15 import Pleroma.Web.ApiSpec.Helpers
17 def open_api_operation(action) do
18 operation = String.to_existing_atom("#{action}_operation")
19 apply(__MODULE__, operation, [])
22 def index_operation do
24 tags: ["Notifications"],
25 summary: "Get all notifications",
27 "Notifications concerning the user. This API returns Link headers containing links to the next/previous page. However, the links can also be constructed dynamically using query params and `id` values.",
28 operationId: "NotificationController.index",
29 security: [%{"oAuth" => ["read:notifications"]}],
35 %Schema{type: :array, items: notification_type()},
36 "Array of types to exclude"
41 %Schema{type: :string},
42 "Return only notifications received from this account"
45 :exclude_visibilities,
47 %Schema{type: :array, items: VisibilityScope},
48 "Exclude the notifications for activities with the given visibilities"
53 %Schema{type: :array, items: notification_type()},
54 "Include the notifications for activities with the given types"
60 "Include the notifications from muted users"
62 ] ++ pagination_params(),
65 Operation.response("Array of notifications", "application/json", %Schema{
69 404 => Operation.response("Error", "application/json", ApiError)
76 tags: ["Notifications"],
77 summary: "Get a single notification",
78 description: "View information about a notification with a given ID.",
79 operationId: "NotificationController.show",
80 security: [%{"oAuth" => ["read:notifications"]}],
81 parameters: [id_param()],
83 200 => Operation.response("Notification", "application/json", notification())
88 def clear_operation do
90 tags: ["Notifications"],
91 summary: "Dismiss all notifications",
92 description: "Clear all notifications from the server.",
93 operationId: "NotificationController.clear",
94 security: [%{"oAuth" => ["write:notifications"]}],
95 responses: %{200 => empty_object_response()}
99 def dismiss_operation do
101 tags: ["Notifications"],
102 summary: "Dismiss a single notification",
103 description: "Clear a single notification from the server.",
104 operationId: "NotificationController.dismiss",
105 parameters: [id_param()],
106 security: [%{"oAuth" => ["write:notifications"]}],
107 responses: %{200 => empty_object_response()}
111 def dismiss_via_body_operation do
113 tags: ["Notifications"],
114 summary: "Dismiss a single notification",
116 description: "Clear a single notification from the server.",
117 operationId: "NotificationController.dismiss_via_body",
121 %Schema{type: :object, properties: %{id: %Schema{type: :string}}},
124 security: [%{"oAuth" => ["write:notifications"]}],
125 responses: %{200 => empty_object_response()}
129 def destroy_multiple_operation do
131 tags: ["Notifications"],
132 summary: "Dismiss multiple notifications",
133 operationId: "NotificationController.destroy_multiple",
134 security: [%{"oAuth" => ["write:notifications"]}],
139 %Schema{type: :array, items: %Schema{type: :string}},
140 "Array of notification IDs to dismiss",
144 responses: %{200 => empty_object_response()}
150 title: "Notification",
151 description: "Response schema for a notification",
154 id: %Schema{type: :string},
155 type: notification_type(),
156 created_at: %Schema{type: :string, format: :"date-time"},
159 description: "The account that performed the action that generated the notification."
164 "Status that was the object of the notification, e.g. in mentions, reblogs, favourites, or polls.",
171 "created_at" => "2019-11-23T07:49:02.064Z",
172 "account" => Account.schema().example,
173 "status" => Status.schema().example
178 defp notification_type do
186 "pleroma:emoji_reaction",
187 "pleroma:chat_mention",
192 The type of event that resulted in the notification.
194 - `follow` - Someone followed you
195 - `mention` - Someone mentioned you in their status
196 - `reblog` - Someone boosted one of your statuses
197 - `favourite` - Someone favourited one of your statuses
198 - `poll` - A poll you have voted in or created has ended
199 - `move` - Someone moved their account
200 - `pleroma:emoji_reaction` - Someone reacted with emoji to your status
206 Operation.parameter(:id, :path, :string, "Notification ID",