2f44cb70d9c2bd88f7d3fb72d11c5d19b5fdf7a4
[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 with_muted_param(),
30 exclude_visibilities_param(),
31 reply_visibility_param() | pagination_params()
32 ],
33 operationId: "TimelineController.home",
34 responses: %{
35 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
36 }
37 }
38 end
39
40 def direct_operation do
41 %Operation{
42 tags: ["Timelines"],
43 summary: "Direct timeline",
44 description:
45 "View statuses with a “direct” privacy, from your account or in your notifications",
46 deprecated: true,
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 with_muted_param(),
66 exclude_visibilities_param(),
67 reply_visibility_param() | pagination_params()
68 ],
69 operationId: "TimelineController.public",
70 responses: %{
71 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
72 401 => Operation.response("Error", "application/json", ApiError)
73 }
74 }
75 end
76
77 def hashtag_operation do
78 %Operation{
79 tags: ["Timelines"],
80 summary: "Hashtag timeline",
81 description: "View public statuses containing the given hashtag",
82 security: [%{"oAuth" => ["read:statuses"]}],
83 parameters: [
84 Operation.parameter(
85 :tag,
86 :path,
87 %Schema{type: :string},
88 "Content of a #hashtag, not including # symbol.",
89 required: true
90 ),
91 Operation.parameter(
92 :any,
93 :query,
94 %Schema{type: :array, items: %Schema{type: :string}},
95 "Statuses that also includes any of these tags"
96 ),
97 Operation.parameter(
98 :all,
99 :query,
100 %Schema{type: :array, items: %Schema{type: :string}},
101 "Statuses that also includes all of these tags"
102 ),
103 Operation.parameter(
104 :none,
105 :query,
106 %Schema{type: :array, items: %Schema{type: :string}},
107 "Statuses that do not include these tags"
108 ),
109 local_param(),
110 only_media_param(),
111 with_muted_param(),
112 exclude_visibilities_param() | pagination_params()
113 ],
114 operationId: "TimelineController.hashtag",
115 responses: %{
116 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
117 }
118 }
119 end
120
121 def list_operation do
122 %Operation{
123 tags: ["Timelines"],
124 summary: "List timeline",
125 description: "View statuses in the given list timeline",
126 security: [%{"oAuth" => ["read:lists"]}],
127 parameters: [
128 Operation.parameter(
129 :list_id,
130 :path,
131 %Schema{type: :string},
132 "Local ID of the list in the database",
133 required: true
134 ),
135 with_muted_param(),
136 exclude_visibilities_param() | pagination_params()
137 ],
138 operationId: "TimelineController.list",
139 responses: %{
140 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
141 }
142 }
143 end
144
145 defp array_of_statuses do
146 %Schema{
147 title: "ArrayOfStatuses",
148 type: :array,
149 items: Status,
150 example: [Status.schema().example]
151 }
152 end
153
154 defp local_param do
155 Operation.parameter(
156 :local,
157 :query,
158 %Schema{allOf: [BooleanLike], default: false},
159 "Show only local statuses?"
160 )
161 end
162
163 defp instance_param do
164 Operation.parameter(
165 :instance,
166 :query,
167 %Schema{type: :string},
168 "Show only statuses from the given domain"
169 )
170 end
171
172 defp with_muted_param do
173 Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users")
174 end
175
176 defp exclude_visibilities_param do
177 Operation.parameter(
178 :exclude_visibilities,
179 :query,
180 %Schema{type: :array, items: VisibilityScope},
181 "Exclude the statuses with the given visibilities"
182 )
183 end
184
185 defp reply_visibility_param do
186 Operation.parameter(
187 :reply_visibility,
188 :query,
189 %Schema{type: :string, enum: ["following", "self"]},
190 "Filter replies. Possible values: without parameter (default) shows all replies, `following` - replies directed to you or users you follow, `self` - replies directed to you."
191 )
192 end
193
194 defp only_media_param do
195 Operation.parameter(
196 :only_media,
197 :query,
198 %Schema{allOf: [BooleanLike], default: false},
199 "Show only statuses with media attached?"
200 )
201 end
202
203 defp remote_param do
204 Operation.parameter(
205 :only_remote,
206 :query,
207 %Schema{allOf: [BooleanLike], default: false},
208 "Show only remote statuses?"
209 )
210 end
211 end