Merge branch 'feature/2438-users-posts-total-count' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_conversation_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ApiSpec.PleromaConversationOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.Conversation
9 alias Pleroma.Web.ApiSpec.Schemas.FlakeID
10 alias Pleroma.Web.ApiSpec.StatusOperation
11
12 import Pleroma.Web.ApiSpec.Helpers
13
14 def open_api_operation(action) do
15 operation = String.to_existing_atom("#{action}_operation")
16 apply(__MODULE__, operation, [])
17 end
18
19 def show_operation do
20 %Operation{
21 tags: ["Conversations"],
22 summary: "Conversation",
23 parameters: [
24 Operation.parameter(:id, :path, :string, "Conversation ID",
25 example: "123",
26 required: true
27 )
28 ],
29 security: [%{"oAuth" => ["read:statuses"]}],
30 operationId: "PleromaAPI.ConversationController.show",
31 responses: %{
32 200 => Operation.response("Conversation", "application/json", Conversation)
33 }
34 }
35 end
36
37 def statuses_operation do
38 %Operation{
39 tags: ["Conversations"],
40 summary: "Timeline for conversation",
41 parameters: [
42 Operation.parameter(:id, :path, :string, "Conversation ID",
43 example: "123",
44 required: true
45 )
46 | pagination_params()
47 ],
48 security: [%{"oAuth" => ["read:statuses"]}],
49 operationId: "PleromaAPI.ConversationController.statuses",
50 responses: %{
51 200 =>
52 Operation.response(
53 "Array of Statuses",
54 "application/json",
55 StatusOperation.array_of_statuses()
56 )
57 }
58 }
59 end
60
61 def update_operation do
62 %Operation{
63 tags: ["Conversations"],
64 summary: "Update conversation",
65 description: "Change set of recipients for the conversation.",
66 parameters: [
67 Operation.parameter(:id, :path, :string, "Conversation ID",
68 example: "123",
69 required: true
70 ),
71 Operation.parameter(
72 :recipients,
73 :query,
74 %Schema{type: :array, items: FlakeID},
75 "A list of ids of users that should receive posts to this conversation. This will replace the current list of recipients, so submit the full list. The owner of owner of the conversation will always be part of the set of recipients, though.",
76 required: true
77 )
78 ],
79 security: [%{"oAuth" => ["write:conversations"]}],
80 operationId: "PleromaAPI.ConversationController.update",
81 responses: %{
82 200 => Operation.response("Conversation", "application/json", Conversation)
83 }
84 }
85 end
86
87 def mark_as_read_operation do
88 %Operation{
89 tags: ["Conversations"],
90 summary: "Marks all conversations as read",
91 security: [%{"oAuth" => ["write:conversations"]}],
92 operationId: "PleromaAPI.ConversationController.mark_as_read",
93 responses: %{
94 200 =>
95 Operation.response(
96 "Array of Conversations that were marked as read",
97 "application/json",
98 %Schema{
99 type: :array,
100 items: Conversation,
101 example: [Conversation.schema().example]
102 }
103 )
104 }
105 }
106 end
107 end