Add /api/v1/{status_id}/thread API endpoint

This commit is contained in:
silverpill 2023-02-12 23:24:28 +00:00
parent 9fd6724819
commit 23b44ce0db
3 changed files with 44 additions and 0 deletions

View file

@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Added OAuth authorization page.
- Support `authorization_code` OAuth grant type.
- Documented `http_cors_allowlist` configuration parameter.
- Added `/api/v1/{status_id}/thread` API endpoint (replaces `/api/v1/{status_id}/context`).
### Changed

View file

@ -943,6 +943,22 @@ paths:
description: Post does not belong to user
404:
description: Post not found
/api/v1/statuses/{status_id}/thread:
get:
summary: Get thread that contains given post.
parameters:
- $ref: '#/components/parameters/status_id'
responses:
200:
description: Successful operation.
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Status'
404:
description: Post not found
/api/v1/statuses/{status_id}/favourite:
post:
summary: Add post to your favourites list

View file

@ -305,6 +305,32 @@ async fn get_context(
Ok(HttpResponse::Ok().json(statuses))
}
#[get("/{status_id}/thread")]
async fn get_thread_view(
auth: Option<BearerAuth>,
config: web::Data<Config>,
db_pool: web::Data<DbPool>,
status_id: web::Path<Uuid>,
) -> Result<HttpResponse, HttpError> {
let db_client = &**get_database_client(&db_pool).await?;
let maybe_current_user = match auth {
Some(auth) => Some(get_current_user(db_client, auth.token()).await?),
None => None,
};
let posts = get_thread(
db_client,
&status_id,
maybe_current_user.as_ref().map(|user| &user.id),
).await?;
let statuses = build_status_list(
db_client,
&config.instance_url(),
maybe_current_user.as_ref(),
posts,
).await?;
Ok(HttpResponse::Ok().json(statuses))
}
#[post("/{status_id}/favourite")]
async fn favourite(
auth: BearerAuth,
@ -597,6 +623,7 @@ pub fn status_api_scope() -> Scope {
.service(get_status)
.service(delete_status)
.service(get_context)
.service(get_thread_view)
.service(favourite)
.service(unfavourite)
.service(reblog)