1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
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
13 import Pleroma.Web.ApiSpec.Helpers
15 def open_api_operation(action) do
16 operation = String.to_existing_atom("#{action}_operation")
17 apply(__MODULE__, operation, [])
23 summary: "Home timeline",
24 description: "View statuses from followed users",
25 security: [%{"oAuth" => ["read:statuses"]}],
29 exclude_visibilities_param(),
30 reply_visibility_param() | pagination_params()
32 operationId: "TimelineController.home",
34 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
39 def direct_operation do
42 summary: "Direct timeline",
44 "View statuses with a “direct” privacy, from your account or in your notifications",
46 parameters: [with_muted_param() | pagination_params()],
47 security: [%{"oAuth" => ["read:statuses"]}],
48 operationId: "TimelineController.direct",
50 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
55 def public_operation do
58 summary: "Public timeline",
59 security: [%{"oAuth" => ["read:statuses"]}],
65 exclude_visibilities_param(),
66 reply_visibility_param() | pagination_params()
68 operationId: "TimelineController.public",
70 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
71 401 => Operation.response("Error", "application/json", ApiError)
76 def hashtag_operation do
79 summary: "Hashtag timeline",
80 description: "View public statuses containing the given hashtag",
81 security: [%{"oAuth" => ["read:statuses"]}],
86 %Schema{type: :string},
87 "Content of a #hashtag, not including # symbol.",
93 %Schema{type: :array, items: %Schema{type: :string}},
94 "Statuses that also includes any of these tags"
99 %Schema{type: :array, items: %Schema{type: :string}},
100 "Statuses that also includes all of these tags"
105 %Schema{type: :array, items: %Schema{type: :string}},
106 "Statuses that do not include these tags"
111 exclude_visibilities_param() | pagination_params()
113 operationId: "TimelineController.hashtag",
115 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
120 def list_operation do
123 summary: "List timeline",
124 description: "View statuses in the given list timeline",
125 security: [%{"oAuth" => ["read:lists"]}],
130 %Schema{type: :string},
131 "Local ID of the list in the database",
135 exclude_visibilities_param() | pagination_params()
137 operationId: "TimelineController.list",
139 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
144 defp array_of_statuses do
146 title: "ArrayOfStatuses",
149 example: [Status.schema().example]
157 %Schema{allOf: [BooleanLike], default: false},
158 "Show only local statuses?"
162 defp instance_param do
166 %Schema{type: :string},
167 "Show only statuses from the given domain"
171 defp with_muted_param do
172 Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users")
175 defp exclude_visibilities_param do
177 :exclude_visibilities,
179 %Schema{type: :array, items: VisibilityScope},
180 "Exclude the statuses with the given visibilities"
184 defp reply_visibility_param do
188 %Schema{type: :string, enum: ["following", "self"]},
189 "Filter replies. Possible values: without parameter (default) shows all replies, `following` - replies directed to you or users you follow, `self` - replies directed to you."
193 defp only_media_param do
197 %Schema{allOf: [BooleanLike], default: false},
198 "Show only statuses with media attached?"