logo

pleroma

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

timeline_operation.ex (6375B)


  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.TimelineOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  8. alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
  9. alias Pleroma.Web.ApiSpec.Schemas.Status
  10. alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
  11. import Pleroma.Web.ApiSpec.Helpers
  12. def open_api_operation(action) do
  13. operation = String.to_existing_atom("#{action}_operation")
  14. apply(__MODULE__, operation, [])
  15. end
  16. def home_operation do
  17. %Operation{
  18. tags: ["Timelines"],
  19. summary: "Home timeline",
  20. description: "View statuses from followed users",
  21. security: [%{"oAuth" => ["read:statuses"]}],
  22. parameters: [
  23. local_param(),
  24. remote_param(),
  25. only_media_param(),
  26. with_muted_param(),
  27. exclude_visibilities_param(),
  28. reply_visibility_param() | pagination_params()
  29. ],
  30. operationId: "TimelineController.home",
  31. responses: %{
  32. 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
  33. }
  34. }
  35. end
  36. def direct_operation do
  37. %Operation{
  38. tags: ["Timelines"],
  39. summary: "Direct timeline",
  40. description:
  41. "View statuses with a “direct” scope addressed to the account. Using this endpoint is discouraged, please use [conversations](#tag/Conversations) or [chats](#tag/Chats).",
  42. parameters: [with_muted_param() | pagination_params()],
  43. security: [%{"oAuth" => ["read:statuses"]}],
  44. operationId: "TimelineController.direct",
  45. responses: %{
  46. 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
  47. }
  48. }
  49. end
  50. def public_operation do
  51. %Operation{
  52. tags: ["Timelines"],
  53. summary: "Public timeline",
  54. security: [%{"oAuth" => ["read:statuses"]}],
  55. parameters: [
  56. local_param(),
  57. instance_param(),
  58. only_media_param(),
  59. remote_param(),
  60. with_muted_param(),
  61. exclude_visibilities_param(),
  62. reply_visibility_param() | pagination_params()
  63. ],
  64. operationId: "TimelineController.public",
  65. responses: %{
  66. 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
  67. 401 => Operation.response("Error", "application/json", ApiError)
  68. }
  69. }
  70. end
  71. def hashtag_operation do
  72. %Operation{
  73. tags: ["Timelines"],
  74. summary: "Hashtag timeline",
  75. description: "View public statuses containing the given hashtag",
  76. security: [%{"oAuth" => ["read:statuses"]}],
  77. parameters: [
  78. Operation.parameter(
  79. :tag,
  80. :path,
  81. %Schema{type: :string},
  82. "Content of a #hashtag, not including # symbol.",
  83. required: true
  84. ),
  85. Operation.parameter(
  86. :any,
  87. :query,
  88. %Schema{type: :array, items: %Schema{type: :string}},
  89. "Statuses that also includes any of these tags"
  90. ),
  91. Operation.parameter(
  92. :all,
  93. :query,
  94. %Schema{type: :array, items: %Schema{type: :string}},
  95. "Statuses that also includes all of these tags"
  96. ),
  97. Operation.parameter(
  98. :none,
  99. :query,
  100. %Schema{type: :array, items: %Schema{type: :string}},
  101. "Statuses that do not include these tags"
  102. ),
  103. local_param(),
  104. only_media_param(),
  105. remote_param(),
  106. with_muted_param(),
  107. exclude_visibilities_param() | pagination_params()
  108. ],
  109. operationId: "TimelineController.hashtag",
  110. responses: %{
  111. 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
  112. 401 => Operation.response("Error", "application/json", ApiError)
  113. }
  114. }
  115. end
  116. def list_operation do
  117. %Operation{
  118. tags: ["Timelines"],
  119. summary: "List timeline",
  120. description: "View statuses in the given list timeline",
  121. security: [%{"oAuth" => ["read:lists"]}],
  122. parameters: [
  123. Operation.parameter(
  124. :list_id,
  125. :path,
  126. %Schema{type: :string},
  127. "Local ID of the list in the database",
  128. required: true
  129. ),
  130. with_muted_param(),
  131. local_param(),
  132. remote_param(),
  133. only_media_param(),
  134. exclude_visibilities_param() | pagination_params()
  135. ],
  136. operationId: "TimelineController.list",
  137. responses: %{
  138. 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
  139. }
  140. }
  141. end
  142. defp array_of_statuses do
  143. %Schema{
  144. title: "ArrayOfStatuses",
  145. type: :array,
  146. items: Status,
  147. example: [Status.schema().example]
  148. }
  149. end
  150. defp local_param do
  151. Operation.parameter(
  152. :local,
  153. :query,
  154. %Schema{allOf: [BooleanLike], default: false},
  155. "Show only local statuses?"
  156. )
  157. end
  158. defp instance_param do
  159. Operation.parameter(
  160. :instance,
  161. :query,
  162. %Schema{type: :string},
  163. "Show only statuses from the given domain"
  164. )
  165. end
  166. defp with_muted_param do
  167. Operation.parameter(
  168. :with_muted,
  169. :query,
  170. BooleanLike.schema(),
  171. "Include activities by muted users"
  172. )
  173. end
  174. defp exclude_visibilities_param do
  175. Operation.parameter(
  176. :exclude_visibilities,
  177. :query,
  178. %Schema{type: :array, items: VisibilityScope},
  179. "Exclude the statuses with the given visibilities"
  180. )
  181. end
  182. defp reply_visibility_param do
  183. Operation.parameter(
  184. :reply_visibility,
  185. :query,
  186. %Schema{type: :string, enum: ["following", "self"]},
  187. "Filter replies. Possible values: without parameter (default) shows all replies, `following` - replies directed to you or users you follow, `self` - replies directed to you."
  188. )
  189. end
  190. defp only_media_param do
  191. Operation.parameter(
  192. :only_media,
  193. :query,
  194. %Schema{allOf: [BooleanLike], default: false},
  195. "Show only statuses with media attached?"
  196. )
  197. end
  198. defp remote_param do
  199. Operation.parameter(
  200. :remote,
  201. :query,
  202. %Schema{allOf: [BooleanLike], default: false},
  203. "Show only remote statuses?"
  204. )
  205. end
  206. end