Change /api/v1/{status_id}/context response format to match Mastodon API

This commit is contained in:
silverpill 2023-02-12 23:15:28 +00:00
parent 23b44ce0db
commit 1d16fb45a5
4 changed files with 49 additions and 1 deletions

View file

@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Allow `instance_uri` configuration value to contain URI scheme. - Allow `instance_uri` configuration value to contain URI scheme.
- Changed `Content-Security-Policy` header value in nginx config examples. - Changed `Content-Security-Policy` header value in nginx config examples.
- Changed `/api/v1/{status_id}/context` response format to match Mastodon API.
## [1.13.1] - 2023-02-09 ## [1.13.1] - 2023-02-09

View file

@ -943,6 +943,31 @@ paths:
description: Post does not belong to user description: Post does not belong to user
404: 404:
description: Post not found description: Post not found
/api/v1/statuses/{status_id}/context:
get:
summary: View statuses above and below this status in the thread.
parameters:
- $ref: '#/components/parameters/status_id'
responses:
200:
description: Successful operation.
content:
application/json:
schema:
type: object
properties:
ancestors:
description: Parents in the thread.
type: array
items:
$ref: '#/components/schemas/Status'
descendants:
description: Parents in the thread.
type: array
items:
$ref: '#/components/schemas/Status'
404:
description: Post not found
/api/v1/statuses/{status_id}/thread: /api/v1/statuses/{status_id}/thread:
get: get:
summary: Get thread that contains given post. summary: Get thread that contains given post.

View file

@ -188,6 +188,12 @@ impl StatusPreview {
} }
} }
#[derive(Serialize)]
pub struct Context {
pub ancestors: Vec<Status>,
pub descendants: Vec<Status>,
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct TransactionData { pub struct TransactionData {
pub transaction_id: String, pub transaction_id: String,

View file

@ -56,6 +56,7 @@ use super::helpers::{
PostContent, PostContent,
}; };
use super::types::{ use super::types::{
Context,
Status, Status,
StatusData, StatusData,
StatusPreview, StatusPreview,
@ -302,7 +303,22 @@ async fn get_context(
maybe_current_user.as_ref(), maybe_current_user.as_ref(),
posts, posts,
).await?; ).await?;
Ok(HttpResponse::Ok().json(statuses)) let mut ancestors = vec![];
let mut descendants = vec![];
let mut is_ancestor = true;
for status in statuses {
if is_ancestor {
if status.id == *status_id {
is_ancestor = false;
continue;
};
ancestors.push(status);
} else {
descendants.push(status);
};
};
let context = Context { ancestors, descendants };
Ok(HttpResponse::Ok().json(context))
} }
#[get("/{status_id}/thread")] #[get("/{status_id}/thread")]