2020-05-11 05:24:59 -06:00
# Pleroma: A lightweight social networking server
2021-01-12 23:49:20 -07:00
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
2020-05-11 05:24:59 -06:00
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ApiSpec.TimelineOperation do
alias OpenApiSpex.Operation
alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.ApiError
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
alias Pleroma.Web.ApiSpec.Schemas.Status
alias Pleroma.Web.ApiSpec.Schemas.VisibilityScope
import Pleroma.Web.ApiSpec.Helpers
def open_api_operation ( action ) do
operation = String . to_existing_atom ( " #{ action } _operation " )
apply ( __MODULE__ , operation , [ ] )
end
def home_operation do
% Operation {
tags : [ " Timelines " ] ,
summary : " Home timeline " ,
description : " View statuses from followed users " ,
security : [ %{ " oAuth " = > [ " read:statuses " ] } ] ,
parameters : [
local_param ( ) ,
2021-02-01 04:09:23 -07:00
remote_param ( ) ,
2021-01-26 04:35:31 -07:00
only_media_param ( ) ,
2020-05-11 05:24:59 -06:00
with_muted_param ( ) ,
exclude_visibilities_param ( ) ,
2020-05-13 09:56:45 -06:00
reply_visibility_param ( ) | pagination_params ( )
2020-05-11 05:24:59 -06:00
] ,
operationId : " TimelineController.home " ,
responses : %{
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) )
}
}
end
def direct_operation do
% Operation {
tags : [ " Timelines " ] ,
summary : " Direct timeline " ,
description :
2022-07-21 04:29:28 -06:00
" View statuses with a “direct” scope addressed to the account. Using this endpoint is discouraged, please use [conversations]( # tag/Conversations). " ,
2020-05-18 10:00:00 -06:00
parameters : [ with_muted_param ( ) | pagination_params ( ) ] ,
2020-05-11 05:24:59 -06:00
security : [ %{ " oAuth " = > [ " read:statuses " ] } ] ,
operationId : " TimelineController.direct " ,
responses : %{
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) )
}
}
end
def public_operation do
% Operation {
tags : [ " Timelines " ] ,
summary : " Public timeline " ,
security : [ %{ " oAuth " = > [ " read:statuses " ] } ] ,
parameters : [
local_param ( ) ,
2020-07-01 20:12:59 -06:00
instance_param ( ) ,
2020-05-11 05:24:59 -06:00
only_media_param ( ) ,
2021-02-01 04:09:23 -07:00
remote_param ( ) ,
2020-05-11 05:24:59 -06:00
with_muted_param ( ) ,
exclude_visibilities_param ( ) ,
2020-05-13 09:56:45 -06:00
reply_visibility_param ( ) | pagination_params ( )
2020-05-11 05:24:59 -06:00
] ,
operationId : " TimelineController.public " ,
responses : %{
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) ) ,
2023-03-17 09:33:28 -06:00
401 = > Operation . response ( " Error " , " application/json " , ApiError ) ,
404 = > Operation . response ( " Error " , " application/json " , ApiError )
2020-05-11 05:24:59 -06:00
}
}
end
2022-07-22 08:55:38 -06:00
def bubble_operation do
% Operation {
tags : [ " Timelines " ] ,
summary : " Bubble timeline " ,
security : [ %{ " oAuth " = > [ " read:statuses " ] } ] ,
parameters : [
only_media_param ( ) ,
remote_param ( ) ,
with_muted_param ( ) ,
exclude_visibilities_param ( ) ,
reply_visibility_param ( ) | pagination_params ( )
] ,
operationId : " TimelineController.bubble " ,
responses : %{
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) ) ,
401 = > Operation . response ( " Error " , " application/json " , ApiError )
}
}
end
2020-05-11 05:24:59 -06:00
def hashtag_operation do
% Operation {
tags : [ " Timelines " ] ,
summary : " Hashtag timeline " ,
description : " View public statuses containing the given hashtag " ,
security : [ %{ " oAuth " = > [ " read:statuses " ] } ] ,
parameters : [
Operation . parameter (
:tag ,
:path ,
% Schema { type : :string } ,
" Content of a # hashtag, not including # symbol. " ,
required : true
) ,
Operation . parameter (
:any ,
:query ,
% Schema { type : :array , items : % Schema { type : :string } } ,
" Statuses that also includes any of these tags "
) ,
Operation . parameter (
:all ,
:query ,
% Schema { type : :array , items : % Schema { type : :string } } ,
" Statuses that also includes all of these tags "
) ,
Operation . parameter (
:none ,
:query ,
% Schema { type : :array , items : % Schema { type : :string } } ,
" Statuses that do not include these tags "
) ,
local_param ( ) ,
only_media_param ( ) ,
2021-02-01 04:09:23 -07:00
remote_param ( ) ,
2020-05-11 05:24:59 -06:00
with_muted_param ( ) ,
2020-05-13 09:56:45 -06:00
exclude_visibilities_param ( ) | pagination_params ( )
2020-05-11 05:24:59 -06:00
] ,
operationId : " TimelineController.hashtag " ,
responses : %{
2021-02-16 15:23:35 -07:00
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) ) ,
401 = > Operation . response ( " Error " , " application/json " , ApiError )
2020-05-11 05:24:59 -06:00
}
}
end
def list_operation do
% Operation {
tags : [ " Timelines " ] ,
summary : " List timeline " ,
description : " View statuses in the given list timeline " ,
security : [ %{ " oAuth " = > [ " read:lists " ] } ] ,
parameters : [
Operation . parameter (
:list_id ,
:path ,
% Schema { type : :string } ,
" Local ID of the list in the database " ,
required : true
) ,
with_muted_param ( ) ,
2021-01-26 06:55:44 -07:00
local_param ( ) ,
2021-02-01 04:09:23 -07:00
remote_param ( ) ,
2021-01-26 06:55:44 -07:00
only_media_param ( ) ,
2020-05-13 09:56:45 -06:00
exclude_visibilities_param ( ) | pagination_params ( )
2020-05-11 05:24:59 -06:00
] ,
operationId : " TimelineController.list " ,
responses : %{
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) )
}
}
end
defp array_of_statuses do
% Schema {
title : " ArrayOfStatuses " ,
type : :array ,
items : Status ,
example : [ Status . schema ( ) . example ]
}
end
defp local_param do
Operation . parameter (
:local ,
:query ,
% Schema { allOf : [ BooleanLike ] , default : false } ,
" Show only local statuses? "
)
end
2020-07-01 20:12:59 -06:00
defp instance_param do
Operation . parameter (
:instance ,
:query ,
% Schema { type : :string } ,
" Show only statuses from the given domain "
)
end
2020-05-11 05:24:59 -06:00
defp with_muted_param do
2020-08-05 13:33:51 -06:00
Operation . parameter ( :with_muted , :query , BooleanLike , " Include activities by muted users " )
2020-05-11 05:24:59 -06:00
end
defp exclude_visibilities_param do
Operation . parameter (
:exclude_visibilities ,
:query ,
% Schema { type : :array , items : VisibilityScope } ,
" Exclude the statuses with the given visibilities "
)
end
defp reply_visibility_param do
Operation . parameter (
:reply_visibility ,
:query ,
% Schema { type : :string , enum : [ " following " , " self " ] } ,
" Filter replies. Possible values: without parameter (default) shows all replies, `following` - replies directed to you or users you follow, `self` - replies directed to you. "
)
end
defp only_media_param do
Operation . parameter (
:only_media ,
:query ,
% Schema { allOf : [ BooleanLike ] , default : false } ,
" Show only statuses with media attached? "
)
end
2021-01-26 01:58:54 -07:00
2021-02-01 04:09:23 -07:00
defp remote_param do
2021-01-26 01:58:54 -07:00
Operation . parameter (
2021-02-01 04:09:23 -07:00
:remote ,
2021-01-26 01:58:54 -07:00
:query ,
% Schema { allOf : [ BooleanLike ] , default : false } ,
" Show only remote statuses? "
)
end
2020-05-11 05:24:59 -06:00
end