chore (backend-rs): rename partial note structs

This commit is contained in:
naskya 2024-05-31 21:42:59 +09:00
parent 2e44357665
commit 9ad284bd67
No known key found for this signature in database
GPG key ID: 712D413B3A9FED5C
6 changed files with 28 additions and 27 deletions

View file

@ -385,11 +385,11 @@ export function isAllowedServer(host: string): Promise<boolean>
*
* # Arguments
*
* * `note` : [NoteLike] object
* * `note` : [PartialNoteToElaborate] 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: NoteLike, mutedWords: Array<string>, mutedPatterns: Array<string>): Promise<boolean>
export function checkWordMute(note: PartialNoteToElaborate, 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
@ -407,7 +407,7 @@ export interface ImageSize {
height: number
}
export function getImageSizeFromUrl(url: string): Promise<ImageSize>
export interface NoteLikeForAllTexts {
export interface PartialNoteToElaborate {
fileIds: Array<string>
userId: string
text: string | null
@ -415,13 +415,13 @@ export interface NoteLikeForAllTexts {
renoteId: string | null
replyId: string | null
}
export interface NoteLikeForGetNoteSummary {
export interface PartialNoteToSummarize {
fileIds: Array<string>
text: string | null
cw: string | null
hasPoll: boolean
}
export function getNoteSummary(note: NoteLikeForGetNoteSummary): string
export function getNoteSummary(note: PartialNoteToSummarize): string
export function isQuote(note: Note): boolean
export function isSafeUrl(url: string): boolean
/** Returns the latest Firefish version. */

View file

@ -1,4 +1,4 @@
use crate::misc::get_note_all_texts::{all_texts, NoteLike};
use crate::misc::get_note_all_texts::{all_texts, PartialNoteToElaborate};
use once_cell::sync::Lazy;
use regex::Regex;
use sea_orm::DbErr;
@ -42,7 +42,7 @@ fn check_word_mute_impl(
/// * `muted_patterns` : list of JavaScript-style (e.g., `/foo/i`) regular expressions
#[crate::export]
pub async fn check_word_mute(
note: NoteLike,
note: PartialNoteToElaborate,
muted_words: &[String],
muted_patterns: &[String],
) -> Result<bool, DbErr> {

View file

@ -2,9 +2,8 @@ use crate::database::db_conn;
use crate::model::entity::{drive_file, note};
use sea_orm::{prelude::*, QuerySelect};
// TODO?: handle name collisions
#[crate::export(object, js_name = "NoteLikeForAllTexts")]
pub struct NoteLike {
#[crate::export(object)]
pub struct PartialNoteToElaborate {
pub file_ids: Vec<String>,
pub user_id: String,
pub text: Option<String>,
@ -16,11 +15,14 @@ pub struct NoteLike {
/// Returns [`Vec<String>`] containing the post text, content warning,
/// those of the "parent" (replied/quoted) posts, and alt texts of attached files.
///
/// ## Arguments
/// # Arguments
///
/// * `note` : [NoteLike] object
/// * `note` : [PartialNoteToElaborate] 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> {
pub async fn all_texts(
note: PartialNoteToElaborate,
include_parent: bool,
) -> Result<Vec<String>, DbErr> {
let db = db_conn().await?;
let mut texts: Vec<String> = vec![];

View file

@ -1,10 +1,9 @@
use serde::Deserialize;
// TODO?: handle name collisions
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
#[crate::export(object, js_name = "NoteLikeForGetNoteSummary")]
pub struct NoteLike {
#[crate::export(object)]
pub struct PartialNoteToSummarize {
pub file_ids: Vec<String>,
pub text: Option<String>,
pub cw: Option<String>,
@ -12,7 +11,7 @@ pub struct NoteLike {
}
#[crate::export]
pub fn get_note_summary(note: NoteLike) -> String {
pub fn get_note_summary(note: PartialNoteToSummarize) -> String {
let mut buf: Vec<String> = vec![];
if let Some(cw) = note.cw {
@ -36,12 +35,12 @@ pub fn get_note_summary(note: NoteLike) -> String {
#[cfg(test)]
mod unit_test {
use super::{get_note_summary, NoteLike};
use super::{get_note_summary, PartialNoteToSummarize};
use pretty_assertions::assert_eq;
#[test]
fn test_note_summary() {
let note = NoteLike {
let note = PartialNoteToSummarize {
file_ids: vec![],
text: Some("Hello world!".to_string()),
cw: None,
@ -49,7 +48,7 @@ mod unit_test {
};
assert_eq!(get_note_summary(note), "Hello world!");
let note_with_cw = NoteLike {
let note_with_cw = PartialNoteToSummarize {
file_ids: vec![],
text: Some("Hello world!".to_string()),
cw: Some("Content warning".to_string()),
@ -57,7 +56,7 @@ mod unit_test {
};
assert_eq!(get_note_summary(note_with_cw), "Content warning");
let note_with_file_and_cw = NoteLike {
let note_with_file_and_cw = PartialNoteToSummarize {
file_ids: vec!["9s7fmcqogiq4igin".to_string()],
text: None,
cw: Some("Selfie, no ec".to_string()),
@ -65,7 +64,7 @@ mod unit_test {
};
assert_eq!(get_note_summary(note_with_file_and_cw), "Selfie, no ec 📎");
let note_with_files_only = NoteLike {
let note_with_files_only = PartialNoteToSummarize {
file_ids: vec![
"9s7fmcqogiq4igin".to_string(),
"9s7qrld5u14cey98".to_string(),
@ -78,7 +77,7 @@ mod unit_test {
};
assert_eq!(get_note_summary(note_with_files_only), "📎 (4)");
let note_all = NoteLike {
let note_all = PartialNoteToSummarize {
file_ids: vec![
"9s7fmcqogiq4igin".to_string(),
"9s7qrld5u14cey98".to_string(),

View file

@ -1,6 +1,6 @@
use crate::database::{cache, db_conn, redis_conn, redis_key, RedisConnError};
use crate::federation::acct::Acct;
use crate::misc::get_note_all_texts::{all_texts, NoteLike};
use crate::misc::get_note_all_texts::{all_texts, PartialNoteToElaborate};
use crate::model::entity::{antenna, note};
use crate::service::antenna::check_hit::{check_hit_antenna, AntennaCheckError};
use crate::service::stream;
@ -53,7 +53,7 @@ pub async fn update_antennas_on_new_note(
) -> Result<(), Error> {
let note_cloned = note.clone();
let note_all_texts = all_texts(
NoteLike {
PartialNoteToElaborate {
file_ids: note.file_ids,
user_id: note.user_id,
text: note.text,

View file

@ -1,5 +1,5 @@
use crate::database::db_conn;
use crate::misc::get_note_summary::{get_note_summary, NoteLike};
use crate::misc::get_note_summary::{get_note_summary, PartialNoteToSummarize};
use crate::misc::meta::fetch_meta;
use crate::model::entity::sw_subscription;
use crate::util::http_client;
@ -87,7 +87,7 @@ fn compact_content(
));
}
let note_like: NoteLike = serde_json::from_value(note.clone())?;
let note_like: PartialNoteToSummarize = serde_json::from_value(note.clone())?;
let text = get_note_summary(note_like);
let note_object = note.as_object_mut().unwrap();