From 23b44ce0dbaa6262a406b0fa674bfe891bb10101 Mon Sep 17 00:00:00 2001 From: silverpill Date: Sun, 12 Feb 2023 23:24:28 +0000 Subject: [PATCH] Add /api/v1/{status_id}/thread API endpoint --- CHANGELOG.md | 1 + docs/openapi.yaml | 16 ++++++++++++++++ src/mastodon_api/statuses/views.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1cdfcc..3c2f0d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/openapi.yaml b/docs/openapi.yaml index d06cdce..c5c8a04 100644 --- a/docs/openapi.yaml +++ b/docs/openapi.yaml @@ -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 diff --git a/src/mastodon_api/statuses/views.rs b/src/mastodon_api/statuses/views.rs index d8c8c3d..96001b3 100644 --- a/src/mastodon_api/statuses/views.rs +++ b/src/mastodon_api/statuses/views.rs @@ -305,6 +305,32 @@ async fn get_context( Ok(HttpResponse::Ok().json(statuses)) } +#[get("/{status_id}/thread")] +async fn get_thread_view( + auth: Option, + config: web::Data, + db_pool: web::Data, + status_id: web::Path, +) -> Result { + 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)