logo

pleroma

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

emoji_reaction_operation.ex (3516B)


  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.EmojiReactionOperation do
  5. alias OpenApiSpex.Operation
  6. alias OpenApiSpex.Schema
  7. alias Pleroma.Web.ApiSpec.Schemas.Account
  8. alias Pleroma.Web.ApiSpec.Schemas.ApiError
  9. alias Pleroma.Web.ApiSpec.Schemas.FlakeID
  10. alias Pleroma.Web.ApiSpec.Schemas.Status
  11. def open_api_operation(action) do
  12. operation = String.to_existing_atom("#{action}_operation")
  13. apply(__MODULE__, operation, [])
  14. end
  15. def index_operation do
  16. %Operation{
  17. tags: ["Emoji reactions"],
  18. summary:
  19. "Get an object of emoji to account mappings with accounts that reacted to the post",
  20. parameters: [
  21. Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", required: true),
  22. Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji",
  23. required: nil
  24. ),
  25. Operation.parameter(
  26. :with_muted,
  27. :query,
  28. :boolean,
  29. "Include reactions from muted acccounts."
  30. )
  31. ],
  32. security: [%{"oAuth" => ["read:statuses"]}],
  33. operationId: "EmojiReactionController.index",
  34. responses: %{
  35. 200 => array_of_reactions_response()
  36. }
  37. }
  38. end
  39. def create_operation do
  40. %Operation{
  41. tags: ["Emoji reactions"],
  42. summary: "React to a post with a unicode emoji",
  43. parameters: [
  44. Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", required: true),
  45. Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
  46. required: true
  47. )
  48. ],
  49. security: [%{"oAuth" => ["write:statuses"]}],
  50. operationId: "EmojiReactionController.create",
  51. responses: %{
  52. 200 => Operation.response("Status", "application/json", Status),
  53. 400 => Operation.response("Bad Request", "application/json", ApiError)
  54. }
  55. }
  56. end
  57. def delete_operation do
  58. %Operation{
  59. tags: ["Emoji reactions"],
  60. summary: "Remove a reaction to a post with a unicode emoji",
  61. parameters: [
  62. Operation.parameter(:id, :path, FlakeID.schema(), "Status ID", required: true),
  63. Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
  64. required: true
  65. )
  66. ],
  67. security: [%{"oAuth" => ["write:statuses"]}],
  68. operationId: "EmojiReactionController.delete",
  69. responses: %{
  70. 200 => Operation.response("Status", "application/json", Status)
  71. }
  72. }
  73. end
  74. defp array_of_reactions_response do
  75. Operation.response("Array of Emoji reactions", "application/json", %Schema{
  76. type: :array,
  77. items: emoji_reaction(),
  78. example: [emoji_reaction().example]
  79. })
  80. end
  81. defp emoji_reaction do
  82. %Schema{
  83. title: "EmojiReaction",
  84. type: :object,
  85. properties: %{
  86. name: %Schema{type: :string, description: "Emoji"},
  87. count: %Schema{type: :integer, description: "Count of reactions with this emoji"},
  88. me: %Schema{type: :boolean, description: "Did I react with this emoji?"},
  89. accounts: %Schema{
  90. type: :array,
  91. items: Account,
  92. description: "Array of accounts reacted with this emoji"
  93. }
  94. },
  95. example: %{
  96. "name" => "😱",
  97. "count" => 1,
  98. "me" => false,
  99. "accounts" => [Account.schema().example]
  100. }
  101. }
  102. end
  103. end