2020-05-19 13:50:49 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-12 23:49:20 -07:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-19 13:50:49 -06:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.EmojiReactionOperation do
|
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.Account
|
2020-05-22 06:38:28 -06:00
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
2020-05-19 13:50:49 -06:00
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.FlakeID
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.Status
|
|
|
|
|
|
|
|
def open_api_operation(action) do
|
|
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
|
|
apply(__MODULE__, operation, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_operation do
|
|
|
|
%Operation{
|
|
|
|
tags: ["Emoji Reactions"],
|
|
|
|
summary:
|
|
|
|
"Get an object of emoji to account mappings with accounts that reacted to the post",
|
|
|
|
parameters: [
|
|
|
|
Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
|
|
|
|
Operation.parameter(:emoji, :path, :string, "Filter by a single unicode emoji",
|
2020-09-18 15:50:00 -06:00
|
|
|
required: nil
|
2020-11-16 11:23:25 -07:00
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:with_muted,
|
|
|
|
:query,
|
|
|
|
:boolean,
|
|
|
|
"Include reactions from muted acccounts."
|
2020-05-19 13:50:49 -06:00
|
|
|
)
|
|
|
|
],
|
|
|
|
security: [%{"oAuth" => ["read:statuses"]}],
|
|
|
|
operationId: "EmojiReactionController.index",
|
|
|
|
responses: %{
|
|
|
|
200 => array_of_reactions_response()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_operation do
|
|
|
|
%Operation{
|
|
|
|
tags: ["Emoji Reactions"],
|
|
|
|
summary: "React to a post with a unicode emoji",
|
|
|
|
parameters: [
|
|
|
|
Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
|
|
|
|
Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
|
|
|
|
required: true
|
|
|
|
)
|
|
|
|
],
|
|
|
|
security: [%{"oAuth" => ["write:statuses"]}],
|
|
|
|
operationId: "EmojiReactionController.create",
|
|
|
|
responses: %{
|
2020-05-22 06:38:28 -06:00
|
|
|
200 => Operation.response("Status", "application/json", Status),
|
|
|
|
400 => Operation.response("Bad Request", "application/json", ApiError)
|
2020-05-19 13:50:49 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def delete_operation do
|
|
|
|
%Operation{
|
|
|
|
tags: ["Emoji Reactions"],
|
|
|
|
summary: "Remove a reaction to a post with a unicode emoji",
|
|
|
|
parameters: [
|
|
|
|
Operation.parameter(:id, :path, FlakeID, "Status ID", required: true),
|
|
|
|
Operation.parameter(:emoji, :path, :string, "A single character unicode emoji",
|
|
|
|
required: true
|
|
|
|
)
|
|
|
|
],
|
|
|
|
security: [%{"oAuth" => ["write:statuses"]}],
|
|
|
|
operationId: "EmojiReactionController.delete",
|
|
|
|
responses: %{
|
|
|
|
200 => Operation.response("Status", "application/json", Status)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp array_of_reactions_response do
|
|
|
|
Operation.response("Array of Emoji Reactions", "application/json", %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: emoji_reaction(),
|
|
|
|
example: [emoji_reaction().example]
|
|
|
|
})
|
|
|
|
end
|
|
|
|
|
|
|
|
defp emoji_reaction do
|
|
|
|
%Schema{
|
|
|
|
title: "EmojiReaction",
|
|
|
|
type: :object,
|
|
|
|
properties: %{
|
|
|
|
name: %Schema{type: :string, description: "Emoji"},
|
|
|
|
count: %Schema{type: :integer, description: "Count of reactions with this emoji"},
|
|
|
|
me: %Schema{type: :boolean, description: "Did I react with this emoji?"},
|
|
|
|
accounts: %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: Account,
|
|
|
|
description: "Array of accounts reacted with this emoji"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
example: %{
|
|
|
|
"name" => "😱",
|
|
|
|
"count" => 1,
|
|
|
|
"me" => false,
|
|
|
|
"accounts" => [Account.schema().example]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|