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"]}],
30 exclude_visibilities_param(),
31 reply_visibility_param() | pagination_params()
33 operationId: "TimelineController.home",
35 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
40 def direct_operation do
43 summary: "Direct timeline",
45 "View statuses with a “direct” privacy, from your account or in your notifications",
47 parameters: [with_muted_param() | pagination_params()],
48 security: [%{"oAuth" => ["read:statuses"]}],
49 operationId: "TimelineController.direct",
51 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
56 def public_operation do
59 summary: "Public timeline",
60 security: [%{"oAuth" => ["read:statuses"]}],
66 exclude_visibilities_param(),
67 reply_visibility_param() | pagination_params()
69 operationId: "TimelineController.public",
71 200 => Operation.response("Array of Status", "application/json", array_of_statuses()),
72 401 => Operation.response("Error", "application/json", ApiError)
77 def hashtag_operation do
80 summary: "Hashtag timeline",
81 description: "View public statuses containing the given hashtag",
82 security: [%{"oAuth" => ["read:statuses"]}],
87 %Schema{type: :string},
88 "Content of a #hashtag, not including # symbol.",
94 %Schema{type: :array, items: %Schema{type: :string}},
95 "Statuses that also includes any of these tags"
100 %Schema{type: :array, items: %Schema{type: :string}},
101 "Statuses that also includes all of these tags"
106 %Schema{type: :array, items: %Schema{type: :string}},
107 "Statuses that do not include these tags"
112 exclude_visibilities_param() | pagination_params()
114 operationId: "TimelineController.hashtag",
116 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
121 def list_operation do
124 summary: "List timeline",
125 description: "View statuses in the given list timeline",
126 security: [%{"oAuth" => ["read:lists"]}],
131 %Schema{type: :string},
132 "Local ID of the list in the database",
136 exclude_visibilities_param() | pagination_params()
138 operationId: "TimelineController.list",
140 200 => Operation.response("Array of Status", "application/json", array_of_statuses())
145 defp array_of_statuses do
147 title: "ArrayOfStatuses",
150 example: [Status.schema().example]
158 %Schema{allOf: [BooleanLike], default: false},
159 "Show only local statuses?"
163 defp instance_param do
167 %Schema{type: :string},
168 "Show only statuses from the given domain"
172 defp with_muted_param do
173 Operation.parameter(:with_muted, :query, BooleanLike, "Include activities by muted users")
176 defp exclude_visibilities_param do
178 :exclude_visibilities,
180 %Schema{type: :array, items: VisibilityScope},
181 "Exclude the statuses with the given visibilities"
185 defp reply_visibility_param do
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."
194 defp only_media_param do
198 %Schema{allOf: [BooleanLike], default: false},
199 "Show only statuses with media attached?"
207 %Schema{allOf: [BooleanLike], default: false},
208 "Show only remote statuses?"