Skip to content

Commit

Permalink
fix(api_mastodon): check in_reply_to_id
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Feb 2, 2024
1 parent 95bf9d9 commit 3be0336
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 3 additions & 2 deletions crates/api_mastodon/src/entities/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::entities::{Account, CustomEmoji};
#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct Status {
pub id: Url,
pub in_reply_to_id: Option<Url>,
// pub in_reply_to_id: Option<Url>,
pub in_reply_to_id: Option<String>,
pub uri: Url,
pub url: Url,
pub account: Account,
Expand All @@ -36,7 +37,7 @@ impl Status {

Ok(Self {
id: note.id.clone().into(),
in_reply_to_id: note.in_reply_to.map(std::convert::Into::into),
in_reply_to_id: note.in_reply_to.map(|url| url.to_string()),
// TODO: replace
uri: note.id.clone().into(),
// TODO: replace
Expand Down
18 changes: 16 additions & 2 deletions crates/api_mastodon/src/routes/statuses/status_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use activitypub_federation::config::Data;
use axum::{debug_handler, extract::Path, Json};
use hatsu_utils::{AppData, AppError};

use crate::entities::Context;
use crate::entities::{Context, Status};

/// Get parent and child statuses in context
///
Expand Down Expand Up @@ -31,7 +31,21 @@ pub async fn status_context(
Ok(url) if url.starts_with("https://") => {
let object_url = hatsu_utils::url::generate_object_url(data.domain(), url)?;
let context = Context::find_by_id(object_url.to_string(), &data).await?;
Ok(Json(context))

Ok(Json(Context {
descendants: context
.descendants
.into_iter()
.map(|status| match status.in_reply_to_id {
Some(id) if id == object_url.to_string() => Status {
in_reply_to_id: Some(base64_url.clone()),
..status
},
_ => status,
})
.collect(),
..context
}))
}
_ => Err(AppError::not_found("Record", &base64_url)),
},
Expand Down

0 comments on commit 3be0336

Please sign in to comment.