2020-05-11 11:24:59 +00:00
# Pleroma: A lightweight social networking server
2021-01-13 06:49:20 +00:00
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
2020-05-11 11:24:59 +00: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 11:09:23 +00:00
remote_param ( ) ,
2021-01-26 11:35:31 +00:00
only_media_param ( ) ,
2020-05-11 11:24:59 +00:00
with_muted_param ( ) ,
exclude_visibilities_param ( ) ,
2020-05-13 15:56:45 +00:00
reply_visibility_param ( ) | pagination_params ( )
2020-05-11 11:24:59 +00: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 :
2021-02-03 12:38:59 +00:00
" View statuses with a “direct” scope addressed to the account. Using this endpoint is discouraged, please use [conversations]( # tag/Conversations) or [chats]( # tag/Chats). " ,
2020-05-18 16:00:00 +00:00
parameters : [ with_muted_param ( ) | pagination_params ( ) ] ,
2020-05-11 11:24:59 +00: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-02 02:12:59 +00:00
instance_param ( ) ,
2020-05-11 11:24:59 +00:00
only_media_param ( ) ,
2021-02-01 11:09:23 +00:00
remote_param ( ) ,
2020-05-11 11:24:59 +00:00
with_muted_param ( ) ,
exclude_visibilities_param ( ) ,
2020-05-13 15:56:45 +00:00
reply_visibility_param ( ) | pagination_params ( )
2020-05-11 11:24:59 +00:00
] ,
operationId : " TimelineController.public " ,
responses : %{
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) ) ,
401 = > Operation . response ( " Error " , " application/json " , ApiError )
}
}
end
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 11:09:23 +00:00
remote_param ( ) ,
2020-05-11 11:24:59 +00:00
with_muted_param ( ) ,
2020-05-13 15:56:45 +00:00
exclude_visibilities_param ( ) | pagination_params ( )
2020-05-11 11:24:59 +00:00
] ,
operationId : " TimelineController.hashtag " ,
responses : %{
2021-02-16 22:23:35 +00:00
200 = > Operation . response ( " Array of Status " , " application/json " , array_of_statuses ( ) ) ,
401 = > Operation . response ( " Error " , " application/json " , ApiError )
2020-05-11 11:24:59 +00: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 13:55:44 +00:00
local_param ( ) ,
2021-02-01 11:09:23 +00:00
remote_param ( ) ,
2021-01-26 13:55:44 +00:00
only_media_param ( ) ,
2020-05-13 15:56:45 +00:00
exclude_visibilities_param ( ) | pagination_params ( )
2020-05-11 11:24:59 +00: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-02 02:12:59 +00:00
defp instance_param do
Operation . parameter (
:instance ,
:query ,
% Schema { type : :string } ,
" Show only statuses from the given domain "
)
end
2020-05-11 11:24:59 +00:00
defp with_muted_param do
2020-08-05 19:33:51 +00:00
Operation . parameter ( :with_muted , :query , BooleanLike , " Include activities by muted users " )
2020-05-11 11:24:59 +00: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 08:58:54 +00:00
2021-02-01 11:09:23 +00:00
defp remote_param do
2021-01-26 08:58:54 +00:00
Operation . parameter (
2021-02-01 11:09:23 +00:00
:remote ,
2021-01-26 08:58:54 +00:00
:query ,
% Schema { allOf : [ BooleanLike ] , default : false } ,
" Show only remote statuses? "
)
end
2020-05-11 11:24:59 +00:00
end