2020-05-05 13:40:00 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-05-05 13:40:00 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ApiSpec.FollowRequestOperation do
|
|
|
|
alias OpenApiSpex.Operation
|
|
|
|
alias OpenApiSpex.Schema
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.Account
|
|
|
|
alias Pleroma.Web.ApiSpec.Schemas.AccountRelationship
|
|
|
|
|
|
|
|
def open_api_operation(action) do
|
|
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
|
|
apply(__MODULE__, operation, [])
|
|
|
|
end
|
|
|
|
|
|
|
|
def index_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Follow requests"],
|
|
|
|
summary: "Retrieve follow requests",
|
2020-05-05 13:40:00 +00:00
|
|
|
security: [%{"oAuth" => ["read:follows", "follow"]}],
|
|
|
|
operationId: "FollowRequestController.index",
|
2023-02-04 20:51:17 +00:00
|
|
|
parameters: pagination_params(),
|
2020-05-05 13:40:00 +00:00
|
|
|
responses: %{
|
|
|
|
200 =>
|
|
|
|
Operation.response("Array of Account", "application/json", %Schema{
|
|
|
|
type: :array,
|
|
|
|
items: Account,
|
|
|
|
example: [Account.schema().example]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Follow requests"],
|
|
|
|
summary: "Accept follow request",
|
2020-05-05 13:40:00 +00:00
|
|
|
operationId: "FollowRequestController.authorize",
|
|
|
|
parameters: [id_param()],
|
|
|
|
security: [%{"oAuth" => ["follow", "write:follows"]}],
|
|
|
|
responses: %{
|
|
|
|
200 => Operation.response("Relationship", "application/json", AccountRelationship)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def reject_operation do
|
|
|
|
%Operation{
|
2021-02-03 12:38:59 +00:00
|
|
|
tags: ["Follow requests"],
|
|
|
|
summary: "Reject follow request",
|
2020-05-05 13:40:00 +00:00
|
|
|
operationId: "FollowRequestController.reject",
|
|
|
|
parameters: [id_param()],
|
|
|
|
security: [%{"oAuth" => ["follow", "write:follows"]}],
|
|
|
|
responses: %{
|
|
|
|
200 => Operation.response("Relationship", "application/json", AccountRelationship)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
defp id_param do
|
|
|
|
Operation.parameter(:id, :path, :string, "Conversation ID",
|
|
|
|
example: "123",
|
|
|
|
required: true
|
|
|
|
)
|
|
|
|
end
|
2023-02-04 20:51:17 +00:00
|
|
|
|
|
|
|
defp pagination_params do
|
|
|
|
[
|
|
|
|
Operation.parameter(:max_id, :query, :string, "Return items older than this ID"),
|
|
|
|
Operation.parameter(
|
|
|
|
:since_id,
|
|
|
|
:query,
|
|
|
|
:string,
|
|
|
|
"Return the oldest items newer than this ID"
|
|
|
|
),
|
|
|
|
Operation.parameter(
|
|
|
|
:limit,
|
|
|
|
:query,
|
|
|
|
%Schema{type: :integer, default: 20},
|
|
|
|
"Maximum number of items to return. Will be ignored if it's more than 40"
|
|
|
|
)
|
|
|
|
]
|
|
|
|
end
|
2020-05-05 13:40:00 +00:00
|
|
|
end
|