cae18c75813c39841bee8107ab64f46f18f8b2c5
[akkoma] / lib / pleroma / web / api_spec / operations / timeline_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.TimelineOperation do
6 alias OpenApiSpex.Operation
7 alias OpenApiSpex.Schema
8 alias Pleroma.Web.ApiSpec.Schemas.ApiError
9 alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
10 alias Pleroma.Web.ApiSpec.Schemas.Status
11 alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
12
13 import Pleroma.Web.ApiSpec.Helpers
14
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
18 end
19
20 def home_operation do
21 %Operation{
22 tags: ["Timelines"],
23 summary: "Home timeline",
24 description: "View statuses from followed users",
25 security: [%{"oAuth" => ["read:statuses"]}],
26 parameters: [
27 local_param(),
28 remote_param(),
29 only_media_param(),
30 with_muted_param(),
31 exclude_visibilities_param(),
32 reply_visibility_param() | pagination_params()
33 ],
34 operationId: "TimelineController.home",
35 responses: %{
36 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
37 }
38 }
39 end
40
41 def direct_operation do
42 %Operation{
43 tags: ["Timelines"],
44 summary: "Direct timeline",
45 description:
46 "View statuses with a “direct” scope addressed to the account. Using this endpoint is discouraged, please use [conversations](#tag/Conversations) or [chats](#tag/Chats).",
47 parameters: [with_muted_param() | pagination_params()],
48 security: [%{"oAuth" => ["read:statuses"]}],
49 operationId: "TimelineController.direct",
50 responses: %{
51 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
52 }
53 }
54 end
55
56 def public_operation do
57 %Operation{
58 tags: ["Timelines"],
59 summary: "Public timeline",
60 security: [%{"oAuth" => ["read:statuses"]}],
61 parameters: [
62 local_param(),
63 instance_param(),
64 only_media_param(),
65 remote_param(),
66 with_muted_param(),
67 exclude_visibilities_param(),
68 reply_visibility_param() | pagination_params()
69 ],
70 operationId: "TimelineController.public",
71 responses: %{
72 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
73 401 => Operation.response("Error", "application/json", ApiError)
74 }
75 }
76 end
77
78 def hashtag_operation do
79 %Operation{
80 tags: ["Timelines"],
81 summary: "Hashtag timeline",
82 description: "View public statuses containing the given hashtag",
83 security: [%{"oAuth" => ["read:statuses"]}],
84 parameters: [
85 Operation.parameter(
86 :tag,
87 :path,
88 %Schema{type: :string},
89 "Content of a #hashtag, not including # symbol.",
90 required: true
91 ),
92 Operation.parameter(
93 :any,
94 :query,
95 %Schema{type: :array, items: %Schema{type: :string}},
96 "Statuses that also includes any of these tags"
97 ),
98 Operation.parameter(
99 :all,
100 :query,
101 %Schema{type: :array, items: %Schema{type: :string}},
102 "Statuses that also includes all of these tags"
103 ),
104 Operation.parameter(
105 :none,
106 :query,
107 %Schema{type: :array, items: %Schema{type: :string}},
108 "Statuses that do not include these tags"
109 ),
110 local_param(),
111 only_media_param(),
112 remote_param(),
113 with_muted_param(),
114 exclude_visibilities_param() | pagination_params()
115 ],
116 operationId: "TimelineController.hashtag",
117 responses: %{
118 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
119 }
120 }
121 end
122
123 def list_operation do
124 %Operation{
125 tags: ["Timelines"],
126 summary: "List timeline",
127 description: "View statuses in the given list timeline",
128 security: [%{"oAuth" => ["read:lists"]}],
129 parameters: [
130 Operation.parameter(
131 :list_id,
132 :path,
133 %Schema{type: :string},
134 "Local ID of the list in the database",
135 required: true
136 ),
137 with_muted_param(),
138 local_param(),
139 remote_param(),
140 only_media_param(),
141 exclude_visibilities_param() | pagination_params()
142 ],
143 operationId: "TimelineController.list",
144 responses: %{
145 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
146 }
147 }
148 end
149
150 defp array_of_statuses do
151 %Schema{
152 title: "ArrayOfStatuses",
153 type: :array,
154 items: Status,
155 example: [Status.schema().example]
156 }
157 end
158
159 defp local_param do
160 Operation.parameter(
161 :local,
162 :query,
163 %Schema{allOf: [BooleanLike], default: false},
164 "Show only local statuses?"
165 )
166 end
167
168 defp instance_param do
169 Operation.parameter(
170 :instance,
171 :query,
172 %Schema{type: :string},
173 "Show only statuses from the given domain"
174 )
175 end
176
177 defp with_muted_param do
178 Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users")
179 end
180
181 defp exclude_visibilities_param do
182 Operation.parameter(
183 :exclude_visibilities,
184 :query,
185 %Schema{type: :array, items: VisibilityScope},
186 "Exclude the statuses with the given visibilities"
187 )
188 end
189
190 defp reply_visibility_param do
191 Operation.parameter(
192 :reply_visibility,
193 :query,
194 %Schema{type: :string, enum: ["following", "self"]},
195 "Filter replies. Possible values: without parameter (default) shows all replies, `following` - replies directed to you or users you follow, `self` - replies directed to you."
196 )
197 end
198
199 defp only_media_param do
200 Operation.parameter(
201 :only_media,
202 :query,
203 %Schema{allOf: [BooleanLike], default: false},
204 "Show only statuses with media attached?"
205 )
206 end
207
208 defp remote_param do
209 Operation.parameter(
210 :remote,
211 :query,
212 %Schema{allOf: [BooleanLike], default: false},
213 "Show only remote statuses?"
214 )
215 end
216 end