From 9ad284bd67ab7eccdf03c7cf60fd2053a2373640 Mon Sep 17 00:00:00 2001 From: naskya Date: Fri, 31 May 2024 21:42:59 +0900 Subject: [PATCH] chore (backend-rs): rename partial note structs --- packages/backend-rs/index.d.ts | 10 +++++----- .../backend-rs/src/misc/check_word_mute.rs | 4 ++-- .../backend-rs/src/misc/get_note_all_texts.rs | 14 ++++++++------ .../backend-rs/src/misc/get_note_summary.rs | 19 +++++++++---------- .../src/service/antenna/process_new_note.rs | 4 ++-- .../src/service/push_notification.rs | 4 ++-- 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/packages/backend-rs/index.d.ts b/packages/backend-rs/index.d.ts index 5060e38bdb..21021c6bfc 100644 --- a/packages/backend-rs/index.d.ts +++ b/packages/backend-rs/index.d.ts @@ -385,11 +385,11 @@ export function isAllowedServer(host: string): Promise * * # 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, mutedPatterns: Array): Promise +export function checkWordMute(note: PartialNoteToElaborate, mutedWords: Array, mutedPatterns: Array): Promise 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 -export interface NoteLikeForAllTexts { +export interface PartialNoteToElaborate { fileIds: Array 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 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. */ diff --git a/packages/backend-rs/src/misc/check_word_mute.rs b/packages/backend-rs/src/misc/check_word_mute.rs index 4109cb9a36..154a9e8537 100644 --- a/packages/backend-rs/src/misc/check_word_mute.rs +++ b/packages/backend-rs/src/misc/check_word_mute.rs @@ -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 { diff --git a/packages/backend-rs/src/misc/get_note_all_texts.rs b/packages/backend-rs/src/misc/get_note_all_texts.rs index 8199085a53..7dc161665c 100644 --- a/packages/backend-rs/src/misc/get_note_all_texts.rs +++ b/packages/backend-rs/src/misc/get_note_all_texts.rs @@ -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, pub user_id: String, pub text: Option, @@ -16,11 +15,14 @@ pub struct NoteLike { /// Returns [`Vec`] 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, DbErr> { +pub async fn all_texts( + note: PartialNoteToElaborate, + include_parent: bool, +) -> Result, DbErr> { let db = db_conn().await?; let mut texts: Vec = vec![]; diff --git a/packages/backend-rs/src/misc/get_note_summary.rs b/packages/backend-rs/src/misc/get_note_summary.rs index 24d703a70f..ab2cc88713 100644 --- a/packages/backend-rs/src/misc/get_note_summary.rs +++ b/packages/backend-rs/src/misc/get_note_summary.rs @@ -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, pub text: Option, pub cw: Option, @@ -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 = 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(), diff --git a/packages/backend-rs/src/service/antenna/process_new_note.rs b/packages/backend-rs/src/service/antenna/process_new_note.rs index ba9ba10d78..1ec44f6e6b 100644 --- a/packages/backend-rs/src/service/antenna/process_new_note.rs +++ b/packages/backend-rs/src/service/antenna/process_new_note.rs @@ -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, diff --git a/packages/backend-rs/src/service/push_notification.rs b/packages/backend-rs/src/service/push_notification.rs index 09edb4fff9..2c06bc2d20 100644 --- a/packages/backend-rs/src/service/push_notification.rs +++ b/packages/backend-rs/src/service/push_notification.rs @@ -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();