logo

pleroma

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

notification_operation.ex (7863B)


  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.ApiSpec.NotificationOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Operation
  7. alias OpenApiSpex.Schema
  8. alias Pleroma.Web.ApiSpec.Schemas.Account
  9. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  10. alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
  11. alias Pleroma.Web.ApiSpec.Schemas.Status
  12. alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
  13. import Pleroma.Web.ApiSpec.Helpers
  14. def open_api_operation(action) do
  15. operation = String.to_existing_atom("#{action}_operation")
  16. apply(__MODULE__, operation, [])
  17. end
  18. def index_operation do
  19. %Operation{
  20. tags: ["Notifications"],
  21. summary: "Retrieve a list of notifications",
  22. description:
  23. "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.",
  24. operationId: "NotificationController.index",
  25. security: [%{"oAuth" => ["read:notifications"]}],
  26. parameters:
  27. [
  28. Operation.parameter(
  29. :exclude_types,
  30. :query,
  31. %Schema{type: :array, items: notification_type()},
  32. "Array of types to exclude"
  33. ),
  34. Operation.parameter(
  35. :account_id,
  36. :query,
  37. %Schema{type: :string},
  38. "Return only notifications received from this account"
  39. ),
  40. Operation.parameter(
  41. :exclude_visibilities,
  42. :query,
  43. %Schema{type: :array, items: VisibilityScope},
  44. "Exclude the notifications for activities with the given visibilities"
  45. ),
  46. Operation.parameter(
  47. :include_types,
  48. :query,
  49. %Schema{type: :array, items: notification_type()},
  50. "Deprecated, use `types` instead"
  51. ),
  52. Operation.parameter(
  53. :types,
  54. :query,
  55. %Schema{type: :array, items: notification_type()},
  56. "Include the notifications for activities with the given types"
  57. ),
  58. Operation.parameter(
  59. :with_muted,
  60. :query,
  61. BooleanLike.schema(),
  62. "Include the notifications from muted users"
  63. )
  64. ] ++ pagination_params(),
  65. responses: %{
  66. 200 =>
  67. Operation.response("Array of notifications", "application/json", %Schema{
  68. type: :array,
  69. items: notification()
  70. }),
  71. 404 => Operation.response("Error", "application/json", ApiError)
  72. }
  73. }
  74. end
  75. def show_operation do
  76. %Operation{
  77. tags: ["Notifications"],
  78. summary: "Retrieve a notification",
  79. description: "View information about a notification with a given ID.",
  80. operationId: "NotificationController.show",
  81. security: [%{"oAuth" => ["read:notifications"]}],
  82. parameters: [id_param()],
  83. responses: %{
  84. 200 => Operation.response("Notification", "application/json", notification())
  85. }
  86. }
  87. end
  88. def clear_operation do
  89. %Operation{
  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()}
  96. }
  97. end
  98. def dismiss_operation do
  99. %Operation{
  100. tags: ["Notifications"],
  101. summary: "Dismiss a notification",
  102. description: "Clear a single notification from the server.",
  103. operationId: "NotificationController.dismiss",
  104. parameters: [id_param()],
  105. security: [%{"oAuth" => ["write:notifications"]}],
  106. responses: %{200 => empty_object_response()}
  107. }
  108. end
  109. def dismiss_via_body_operation do
  110. %Operation{
  111. tags: ["Notifications"],
  112. summary: "Dismiss a single notification",
  113. deprecated: true,
  114. description: "Clear a single notification from the server.",
  115. operationId: "NotificationController.dismiss_via_body",
  116. requestBody:
  117. request_body(
  118. "Parameters",
  119. %Schema{type: :object, properties: %{id: %Schema{type: :string}}},
  120. required: true
  121. ),
  122. security: [%{"oAuth" => ["write:notifications"]}],
  123. responses: %{200 => empty_object_response()}
  124. }
  125. end
  126. def destroy_multiple_operation do
  127. %Operation{
  128. tags: ["Notifications"],
  129. summary: "Dismiss multiple notifications",
  130. operationId: "NotificationController.destroy_multiple",
  131. security: [%{"oAuth" => ["write:notifications"]}],
  132. parameters: [
  133. Operation.parameter(
  134. :ids,
  135. :query,
  136. %Schema{type: :array, items: %Schema{type: :string}},
  137. "Array of notification IDs to dismiss",
  138. required: true
  139. )
  140. ],
  141. responses: %{200 => empty_object_response()}
  142. }
  143. end
  144. def notification do
  145. %Schema{
  146. title: "Notification",
  147. description: "Response schema for a notification",
  148. type: :object,
  149. properties: %{
  150. id: %Schema{type: :string},
  151. group_key: %Schema{
  152. type: :string,
  153. description: "Group key shared by similar notifications"
  154. },
  155. type: notification_type(),
  156. created_at: %Schema{type: :string, format: :"date-time"},
  157. account: %Schema{
  158. allOf: [Account],
  159. description: "The account that performed the action that generated the notification."
  160. },
  161. status: %Schema{
  162. allOf: [Status],
  163. description:
  164. "Status that was the object of the notification, e.g. in mentions, reblogs, favourites, or polls.",
  165. nullable: true
  166. },
  167. pleroma: %Schema{
  168. type: :object,
  169. properties: %{
  170. is_seen: %Schema{type: :boolean},
  171. is_muted: %Schema{type: :boolean}
  172. }
  173. }
  174. },
  175. example: %{
  176. "id" => "34975861",
  177. "group-key" => "ungrouped-34975861",
  178. "type" => "mention",
  179. "created_at" => "2019-11-23T07:49:02.064Z",
  180. "account" => Account.schema().example,
  181. "status" => Status.schema().example,
  182. "pleroma" => %{"is_seen" => false, "is_muted" => false}
  183. }
  184. }
  185. end
  186. defp notification_type do
  187. %Schema{
  188. type: :string,
  189. enum: [
  190. "follow",
  191. "favourite",
  192. "reblog",
  193. "mention",
  194. "pleroma:emoji_reaction",
  195. "pleroma:chat_mention",
  196. "pleroma:report",
  197. "move",
  198. "follow_request",
  199. "poll",
  200. "status",
  201. "update",
  202. "admin.sign_up",
  203. "admin.report"
  204. ],
  205. description: """
  206. The type of event that resulted in the notification.
  207. - `follow` - Someone followed you
  208. - `mention` - Someone mentioned you in their status
  209. - `reblog` - Someone boosted one of your statuses
  210. - `favourite` - Someone favourited one of your statuses
  211. - `poll` - A poll you have voted in or created has ended
  212. - `move` - Someone moved their account
  213. - `pleroma:emoji_reaction` - Someone reacted with emoji to your status
  214. - `pleroma:chat_mention` - Someone mentioned you in a chat message
  215. - `pleroma:report` - Someone was reported
  216. - `status` - Someone you are subscribed to created a status
  217. - `update` - A status you boosted has been edited
  218. - `admin.sign_up` - Someone signed up (optionally sent to admins)
  219. - `admin.report` - A new report has been filed
  220. """
  221. }
  222. end
  223. defp id_param do
  224. Operation.parameter(:id, :path, :string, "Notification ID",
  225. example: "123",
  226. required: true
  227. )
  228. end
  229. end