chore (backend-rs): PartialNoteToElaborate -> PartialNoteToCheckWordMute
Co-authored-by: sup39 <dev@sup39.dev>
This commit is contained in:
parent
9f16c00f0c
commit
839d4c4d14
4 changed files with 52 additions and 52 deletions
19
packages/backend-rs/index.d.ts
vendored
19
packages/backend-rs/index.d.ts
vendored
|
@ -378,6 +378,13 @@ export function isSilencedServer(host: string): Promise<boolean>
|
|||
* ```
|
||||
*/
|
||||
export function isAllowedServer(host: string): Promise<boolean>
|
||||
export interface PartialNoteToCheckWordMute {
|
||||
fileIds: Array<string>
|
||||
text: string | null
|
||||
cw: string | null
|
||||
renoteId: string | null
|
||||
replyId: string | null
|
||||
}
|
||||
/**
|
||||
* Returns whether `note` should be hard-muted.
|
||||
*
|
||||
|
@ -390,11 +397,11 @@ export function isAllowedServer(host: string): Promise<boolean>
|
|||
*
|
||||
* # Arguments
|
||||
*
|
||||
* * `note` : [PartialNoteToElaborate] object
|
||||
* * `note` : [PartialNoteToCheckWordMute] object
|
||||
* * `muted_words` : list of muted keyword lists (each array item is a space-separated keyword list that represents an AND condition)
|
||||
* * `muted_patterns` : list of JavaScript-style (e.g., `/foo/i`) regular expressions
|
||||
*/
|
||||
export function checkWordMute(note: PartialNoteToElaborate, mutedWords: Array<string>, mutedPatterns: Array<string>): Promise<boolean>
|
||||
export function checkWordMute(note: PartialNoteToCheckWordMute, mutedWords: Array<string>, mutedPatterns: Array<string>): Promise<boolean>
|
||||
export function getFullApAccount(username: string, host?: string | undefined | null): string
|
||||
export function isSelfHost(host?: string | undefined | null): boolean
|
||||
export function isSameOrigin(uri: string): boolean
|
||||
|
@ -412,14 +419,6 @@ export interface ImageSize {
|
|||
height: number
|
||||
}
|
||||
export function getImageSizeFromUrl(url: string): Promise<ImageSize>
|
||||
export interface PartialNoteToElaborate {
|
||||
fileIds: Array<string>
|
||||
userId: string
|
||||
text: string | null
|
||||
cw: string | null
|
||||
renoteId: string | null
|
||||
replyId: string | null
|
||||
}
|
||||
export interface PartialNoteToSummarize {
|
||||
fileIds: Array<string>
|
||||
text: string | null
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
use crate::misc::get_note_all_texts::{all_texts, PartialNoteToElaborate};
|
||||
use crate::misc::get_note_all_texts::all_texts;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
use sea_orm::DbErr;
|
||||
|
||||
#[crate::export(object)]
|
||||
pub struct PartialNoteToCheckWordMute {
|
||||
pub file_ids: Vec<String>,
|
||||
pub text: Option<String>,
|
||||
pub cw: Option<String>,
|
||||
pub renote_id: Option<String>,
|
||||
pub reply_id: Option<String>,
|
||||
}
|
||||
|
||||
fn convert_regex(js_regex: &str) -> String {
|
||||
static RE: Lazy<Regex> = Lazy::new(|| Regex::new(r"^/(.+)/(.*)$").unwrap());
|
||||
RE.replace(js_regex, "(?$2)$1").to_string()
|
||||
|
@ -37,12 +46,12 @@ fn check_word_mute_impl(
|
|||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `note` : [PartialNoteToElaborate] object
|
||||
/// * `note` : [PartialNoteToCheckWordMute] object
|
||||
/// * `muted_words` : list of muted keyword lists (each array item is a space-separated keyword list that represents an AND condition)
|
||||
/// * `muted_patterns` : list of JavaScript-style (e.g., `/foo/i`) regular expressions
|
||||
#[crate::export]
|
||||
pub async fn check_word_mute(
|
||||
note: PartialNoteToElaborate,
|
||||
note: PartialNoteToCheckWordMute,
|
||||
muted_words: &[String],
|
||||
muted_patterns: &[String],
|
||||
) -> Result<bool, DbErr> {
|
||||
|
@ -50,7 +59,15 @@ pub async fn check_word_mute(
|
|||
Ok(false)
|
||||
} else {
|
||||
Ok(check_word_mute_impl(
|
||||
&all_texts(note, true).await?,
|
||||
&all_texts(
|
||||
note.file_ids,
|
||||
note.text,
|
||||
note.cw,
|
||||
note.renote_id,
|
||||
note.reply_id,
|
||||
true,
|
||||
)
|
||||
.await?,
|
||||
muted_words,
|
||||
muted_patterns,
|
||||
))
|
||||
|
|
|
@ -4,48 +4,35 @@ use crate::{
|
|||
};
|
||||
use sea_orm::{prelude::*, QuerySelect};
|
||||
|
||||
#[crate::export(object)]
|
||||
pub struct PartialNoteToElaborate {
|
||||
pub file_ids: Vec<String>,
|
||||
pub user_id: String,
|
||||
pub text: Option<String>,
|
||||
pub cw: Option<String>,
|
||||
pub renote_id: Option<String>,
|
||||
pub reply_id: Option<String>,
|
||||
}
|
||||
|
||||
/// Returns [`Vec<String>`] containing the post text, content warning,
|
||||
/// those of the "parent" (replied/quoted) posts, and alt texts of attached files.
|
||||
///
|
||||
/// # Arguments
|
||||
///
|
||||
/// * `note` : [PartialNoteToElaborate] object
|
||||
/// * `file_ids` : IDs of attached files ([`drive_file::Model`])
|
||||
/// * `text`, `cw`, `renote_id`, `reply_id` : note ([`note::Model`]) fields
|
||||
/// * `include_parent` : whether to take the reply-to post and quoted post into account
|
||||
pub async fn all_texts(
|
||||
note: PartialNoteToElaborate,
|
||||
file_ids: Vec<String>,
|
||||
text: Option<String>,
|
||||
cw: Option<String>,
|
||||
renote_id: Option<String>,
|
||||
reply_id: Option<String>,
|
||||
include_parent: bool,
|
||||
) -> Result<Vec<String>, DbErr> {
|
||||
let db = db_conn().await?;
|
||||
|
||||
let mut texts: Vec<String> = vec![];
|
||||
let is_renote: bool;
|
||||
let is_renote = text.is_none();
|
||||
|
||||
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);
|
||||
}
|
||||
text.map(|text| texts.push(text));
|
||||
cw.map(|cw| texts.push(cw));
|
||||
|
||||
texts.extend(
|
||||
drive_file::Entity::find()
|
||||
.select_only()
|
||||
.column(drive_file::Column::Comment)
|
||||
.filter(drive_file::Column::Id.is_in(note.file_ids))
|
||||
.filter(drive_file::Column::Id.is_in(file_ids))
|
||||
.into_tuple::<Option<String>>()
|
||||
.all(db)
|
||||
.await?
|
||||
|
@ -53,8 +40,8 @@ pub async fn all_texts(
|
|||
.flatten(),
|
||||
);
|
||||
|
||||
if note.renote_id.is_some() && (include_parent || is_renote) {
|
||||
let renote_id = note.renote_id.unwrap();
|
||||
if renote_id.is_some() && (include_parent || is_renote) {
|
||||
let renote_id = renote_id.unwrap();
|
||||
|
||||
if let Some((text, cw)) = note::Entity::find_by_id(&renote_id)
|
||||
.select_only()
|
||||
|
@ -74,8 +61,8 @@ pub async fn all_texts(
|
|||
}
|
||||
}
|
||||
|
||||
if include_parent && note.reply_id.is_some() {
|
||||
if let Some((text, cw)) = note::Entity::find_by_id(note.reply_id.as_ref().unwrap())
|
||||
if include_parent && reply_id.is_some() {
|
||||
if let Some((text, cw)) = note::Entity::find_by_id(reply_id.as_ref().unwrap())
|
||||
.select_only()
|
||||
.columns([note::Column::Text, note::Column::Cw])
|
||||
.into_tuple::<(Option<String>, Option<String>)>()
|
||||
|
@ -89,7 +76,7 @@ pub async fn all_texts(
|
|||
texts.push(c);
|
||||
}
|
||||
} else {
|
||||
tracing::warn!("nonexistent reply id: {}", note.reply_id.unwrap());
|
||||
tracing::warn!("nonexistent reply id: {}", reply_id.unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use crate::{
|
||||
database::{cache, redis_conn, redis_key, RedisConnError},
|
||||
federation::acct::Acct,
|
||||
misc::get_note_all_texts::{all_texts, PartialNoteToElaborate},
|
||||
misc::get_note_all_texts::all_texts,
|
||||
model::entity::note,
|
||||
service::{
|
||||
antenna,
|
||||
|
@ -42,14 +42,11 @@ pub async fn update_antennas_on_new_note(
|
|||
note_muted_users: &[String],
|
||||
) -> Result<(), Error> {
|
||||
let note_all_texts = all_texts(
|
||||
PartialNoteToElaborate {
|
||||
file_ids: note.file_ids.to_owned(),
|
||||
user_id: note.user_id.to_owned(),
|
||||
text: note.text.to_owned(),
|
||||
cw: note.cw.to_owned(),
|
||||
renote_id: note.renote_id.to_owned(),
|
||||
reply_id: note.reply_id.to_owned(),
|
||||
},
|
||||
note.file_ids.to_owned(),
|
||||
note.text.to_owned(),
|
||||
note.cw.to_owned(),
|
||||
note.renote_id.to_owned(),
|
||||
note.reply_id.to_owned(),
|
||||
false,
|
||||
)
|
||||
.await?;
|
||||
|
|
Loading…
Reference in a new issue