logo

pleroma

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

notification_operation.ex (7355B)


  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. type: notification_type(),
  152. created_at: %Schema{type: :string, format: :"date-time"},
  153. account: %Schema{
  154. allOf: [Account],
  155. description: "The account that performed the action that generated the notification."
  156. },
  157. status: %Schema{
  158. allOf: [Status],
  159. description:
  160. "Status that was the object of the notification, e.g. in mentions, reblogs, favourites, or polls.",
  161. nullable: true
  162. },
  163. pleroma: %Schema{
  164. type: :object,
  165. properties: %{
  166. is_seen: %Schema{type: :boolean},
  167. is_muted: %Schema{type: :boolean}
  168. }
  169. }
  170. },
  171. example: %{
  172. "id" => "34975861",
  173. "type" => "mention",
  174. "created_at" => "2019-11-23T07:49:02.064Z",
  175. "account" => Account.schema().example,
  176. "status" => Status.schema().example,
  177. "pleroma" => %{"is_seen" => false, "is_muted" => false}
  178. }
  179. }
  180. end
  181. defp notification_type do
  182. %Schema{
  183. type: :string,
  184. enum: [
  185. "follow",
  186. "favourite",
  187. "reblog",
  188. "mention",
  189. "pleroma:emoji_reaction",
  190. "pleroma:chat_mention",
  191. "pleroma:report",
  192. "move",
  193. "follow_request",
  194. "poll"
  195. ],
  196. description: """
  197. The type of event that resulted in the notification.
  198. - `follow` - Someone followed you
  199. - `mention` - Someone mentioned you in their status
  200. - `reblog` - Someone boosted one of your statuses
  201. - `favourite` - Someone favourited one of your statuses
  202. - `poll` - A poll you have voted in or created has ended
  203. - `move` - Someone moved their account
  204. - `pleroma:emoji_reaction` - Someone reacted with emoji to your status
  205. - `pleroma:chat_mention` - Someone mentioned you in a chat message
  206. - `pleroma:report` - Someone was reported
  207. """
  208. }
  209. end
  210. defp id_param do
  211. Operation.parameter(:id, :path, :string, "Notification ID",
  212. example: "123",
  213. required: true
  214. )
  215. end
  216. end