logo

pleroma

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

marker_operation.ex (3971B)


  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.MarkerOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Helpers
  8. def open_api_operation(action) do
  9. operation = String.to_existing_atom("#{action}_operation")
  10. apply(__MODULE__, operation, [])
  11. end
  12. def index_operation do
  13. %Operation{
  14. tags: ["Markers"],
  15. summary: "Get saved timeline position",
  16. security: [%{"oAuth" => ["read:statuses"]}],
  17. operationId: "MarkerController.index",
  18. parameters: [
  19. Operation.parameter(
  20. :timeline,
  21. :query,
  22. %Schema{
  23. type: :array,
  24. items: %Schema{type: :string, enum: ["home", "notifications"]}
  25. },
  26. "Array of markers to fetch. If not provided, an empty object will be returned."
  27. )
  28. ],
  29. responses: %{
  30. 200 => Operation.response("Marker", "application/json", response()),
  31. 403 => Operation.response("Error", "application/json", api_error())
  32. }
  33. }
  34. end
  35. def upsert_operation do
  36. %Operation{
  37. tags: ["Markers"],
  38. summary: "Save position in timeline",
  39. operationId: "MarkerController.upsert",
  40. requestBody: Helpers.request_body("Parameters", upsert_request(), required: true),
  41. security: [%{"oAuth" => ["follow", "write:blocks"]}],
  42. responses: %{
  43. 200 => Operation.response("Marker", "application/json", response()),
  44. 403 => Operation.response("Error", "application/json", api_error())
  45. }
  46. }
  47. end
  48. defp marker do
  49. %Schema{
  50. title: "Marker",
  51. description: "Schema for a marker",
  52. type: :object,
  53. properties: %{
  54. last_read_id: %Schema{type: :string},
  55. version: %Schema{type: :integer},
  56. updated_at: %Schema{type: :string},
  57. pleroma: %Schema{
  58. type: :object,
  59. properties: %{
  60. unread_count: %Schema{type: :integer}
  61. }
  62. }
  63. },
  64. example: %{
  65. "last_read_id" => "35098814",
  66. "version" => 361,
  67. "updated_at" => "2019-11-26T22:37:25.239Z",
  68. "pleroma" => %{"unread_count" => 5}
  69. }
  70. }
  71. end
  72. defp response do
  73. %Schema{
  74. title: "MarkersResponse",
  75. description: "Response schema for markers",
  76. type: :object,
  77. properties: %{
  78. notifications: %Schema{allOf: [marker()], nullable: true},
  79. home: %Schema{allOf: [marker()], nullable: true}
  80. },
  81. items: %Schema{type: :string},
  82. example: %{
  83. "notifications" => %{
  84. "last_read_id" => "35098814",
  85. "version" => 361,
  86. "updated_at" => "2019-11-26T22:37:25.239Z",
  87. "pleroma" => %{"unread_count" => 0}
  88. },
  89. "home" => %{
  90. "last_read_id" => "103206604258487607",
  91. "version" => 468,
  92. "updated_at" => "2019-11-26T22:37:25.235Z",
  93. "pleroma" => %{"unread_count" => 10}
  94. }
  95. }
  96. }
  97. end
  98. defp upsert_request do
  99. %Schema{
  100. title: "MarkersUpsertRequest",
  101. description: "Request schema for marker upsert",
  102. type: :object,
  103. properties: %{
  104. notifications: %Schema{
  105. type: :object,
  106. nullable: true,
  107. properties: %{
  108. last_read_id: %Schema{nullable: true, type: :string}
  109. }
  110. },
  111. home: %Schema{
  112. type: :object,
  113. nullable: true,
  114. properties: %{
  115. last_read_id: %Schema{nullable: true, type: :string}
  116. }
  117. }
  118. },
  119. example: %{
  120. "home" => %{
  121. "last_read_id" => "103194548672408537",
  122. "version" => 462,
  123. "updated_at" => "2019-11-24T19:39:39.337Z"
  124. }
  125. }
  126. }
  127. end
  128. defp api_error do
  129. %Schema{
  130. type: :object,
  131. properties: %{error: %Schema{type: :string}}
  132. }
  133. end
  134. end