fix (backend-rs): don't check quoted post in antennas

This commit is contained in:
naskya 2024-05-24 22:11:56 +09:00
parent a7e5abf67d
commit 0e9d7f388a
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
2 changed files with 20 additions and 6 deletions

View file

@ -2,7 +2,7 @@ use crate::database::db_conn;
use crate::model::entity::{drive_file, note};
use sea_orm::{prelude::*, QuerySelect};
/// TODO: handle name collisions better
// TODO?: handle name collisions
#[crate::export(object, js_name = "NoteLikeForAllTexts")]
pub struct NoteLike {
pub file_ids: Vec<String>,
@ -13,14 +13,26 @@ pub struct NoteLike {
pub reply_id: Option<String>,
}
pub async fn all_texts(note: NoteLike, include_in_reply_to: bool) -> Result<Vec<String>, DbErr> {
/// Returns [Vec<String>] containing the post text, content warning,
/// those of the "parent" (replied/quoted) posts, and alt texts of attached files.
///
/// ## Arguments
///
/// * `note` - [NoteLike] object
/// * `include_parent` - whether to take the reply-to post and quoted post into account
pub async fn all_texts(note: NoteLike, include_parent: bool) -> Result<Vec<String>, DbErr> {
let db = db_conn().await?;
let mut texts: Vec<String> = vec![];
let is_renote: bool;
if let Some(text) = note.text {
is_renote = false;
texts.push(text);
} else {
is_renote = true;
}
if let Some(cw) = note.cw {
texts.push(cw);
}
@ -37,8 +49,10 @@ pub async fn all_texts(note: NoteLike, include_in_reply_to: bool) -> Result<Vec<
.flatten(),
);
if let Some(renote_id) = &note.renote_id {
if let Some((text, cw)) = note::Entity::find_by_id(renote_id)
if note.renote_id.is_some() && (include_parent || is_renote) {
let renote_id = note.renote_id.unwrap();
if let Some((text, cw)) = note::Entity::find_by_id(&renote_id)
.select_only()
.columns([note::Column::Text, note::Column::Cw])
.into_tuple::<(Option<String>, Option<String>)>()
@ -56,7 +70,7 @@ pub async fn all_texts(note: NoteLike, include_in_reply_to: bool) -> Result<Vec<
}
}
if include_in_reply_to && note.reply_id.is_some() {
if include_parent && note.reply_id.is_some() {
if let Some((text, cw)) = note::Entity::find_by_id(note.reply_id.as_ref().unwrap())
.select_only()
.columns([note::Column::Text, note::Column::Cw])

View file

@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
// TODO: handle name collisions in a better way
// TODO?: handle name collisions
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
#[crate::export(object, js_name = "NoteLikeForGetNoteSummary")]