Merge branch 'issue/2068' into 'develop'
[akkoma] / lib / pleroma / web / api_spec / operations / pleroma_conversation_operation.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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: "The conversation with the given ID",
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 a given 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 a conversation. Used to change the set of recipients.",
65 parameters: [
66 Operation.parameter(:id, :path, :string, "Conversation ID",
67 example: "123",
68 required: true
69 ),
70 Operation.parameter(
71 :recipients,
72 :query,
73 %Schema{type: :array, items: FlakeID},
74 "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.",
75 required: true
76 )
77 ],
78 security: [%{"oAuth" => ["write:conversations"]}],
79 operationId: "PleromaAPI.ConversationController.update",
80 responses: %{
81 200 => Operation.response("Conversation", "application/json", Conversation)
82 }
83 }
84 end
85
86 def mark_as_read_operation do
87 %Operation{
88 tags: ["Conversations"],
89 summary: "Marks all user's conversations as read",
90 security: [%{"oAuth" => ["write:conversations"]}],
91 operationId: "PleromaAPI.ConversationController.mark_as_read",
92 responses: %{
93 200 =>
94 Operation.response(
95 "Array of Conversations that were marked as read",
96 "application/json",
97 %Schema{
98 type: :array,
99 items: Conversation,
100 example: [Conversation.schema().example]
101 }
102 )
103 }
104 }
105 end
106 end