chore (backend-rs): rename partial note structs
This commit is contained in:
parent
2e44357665
commit
9ad284bd67
6 changed files with 28 additions and 27 deletions
10
packages/backend-rs/index.d.ts
vendored
10
packages/backend-rs/index.d.ts
vendored
|
@ -385,11 +385,11 @@ export function isAllowedServer(host: string): Promise<boolean>
|
||||||
*
|
*
|
||||||
* # Arguments
|
* # 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_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
|
* * `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 getFullApAccount(username: string, host?: string | undefined | null): string
|
||||||
export function isSelfHost(host?: string | undefined | null): boolean
|
export function isSelfHost(host?: string | undefined | null): boolean
|
||||||
export function isSameOrigin(uri: string): boolean
|
export function isSameOrigin(uri: string): boolean
|
||||||
|
@ -407,7 +407,7 @@ export interface ImageSize {
|
||||||
height: number
|
height: number
|
||||||
}
|
}
|
||||||
export function getImageSizeFromUrl(url: string): Promise<ImageSize>
|
export function getImageSizeFromUrl(url: string): Promise<ImageSize>
|
||||||
export interface NoteLikeForAllTexts {
|
export interface PartialNoteToElaborate {
|
||||||
fileIds: Array<string>
|
fileIds: Array<string>
|
||||||
userId: string
|
userId: string
|
||||||
text: string | null
|
text: string | null
|
||||||
|
@ -415,13 +415,13 @@ export interface NoteLikeForAllTexts {
|
||||||
renoteId: string | null
|
renoteId: string | null
|
||||||
replyId: string | null
|
replyId: string | null
|
||||||
}
|
}
|
||||||
export interface NoteLikeForGetNoteSummary {
|
export interface PartialNoteToSummarize {
|
||||||
fileIds: Array<string>
|
fileIds: Array<string>
|
||||||
text: string | null
|
text: string | null
|
||||||
cw: string | null
|
cw: string | null
|
||||||
hasPoll: boolean
|
hasPoll: boolean
|
||||||
}
|
}
|
||||||
export function getNoteSummary(note: NoteLikeForGetNoteSummary): string
|
export function getNoteSummary(note: PartialNoteToSummarize): string
|
||||||
export function isQuote(note: Note): boolean
|
export function isQuote(note: Note): boolean
|
||||||
export function isSafeUrl(url: string): boolean
|
export function isSafeUrl(url: string): boolean
|
||||||
/** Returns the latest Firefish version. */
|
/** Returns the latest Firefish version. */
|
||||||
|
|
|
@ -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 once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use sea_orm::DbErr;
|
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
|
/// * `muted_patterns` : list of JavaScript-style (e.g., `/foo/i`) regular expressions
|
||||||
#[crate::export]
|
#[crate::export]
|
||||||
pub async fn check_word_mute(
|
pub async fn check_word_mute(
|
||||||
note: NoteLike,
|
note: PartialNoteToElaborate,
|
||||||
muted_words: &[String],
|
muted_words: &[String],
|
||||||
muted_patterns: &[String],
|
muted_patterns: &[String],
|
||||||
) -> Result<bool, DbErr> {
|
) -> Result<bool, DbErr> {
|
||||||
|
|
|
@ -2,9 +2,8 @@ use crate::database::db_conn;
|
||||||
use crate::model::entity::{drive_file, note};
|
use crate::model::entity::{drive_file, note};
|
||||||
use sea_orm::{prelude::*, QuerySelect};
|
use sea_orm::{prelude::*, QuerySelect};
|
||||||
|
|
||||||
// TODO?: handle name collisions
|
#[crate::export(object)]
|
||||||
#[crate::export(object, js_name = "NoteLikeForAllTexts")]
|
pub struct PartialNoteToElaborate {
|
||||||
pub struct NoteLike {
|
|
||||||
pub file_ids: Vec<String>,
|
pub file_ids: Vec<String>,
|
||||||
pub user_id: String,
|
pub user_id: String,
|
||||||
pub text: Option<String>,
|
pub text: Option<String>,
|
||||||
|
@ -16,11 +15,14 @@ pub struct NoteLike {
|
||||||
/// Returns [`Vec<String>`] containing the post text, content warning,
|
/// Returns [`Vec<String>`] containing the post text, content warning,
|
||||||
/// those of the "parent" (replied/quoted) posts, and alt texts of attached files.
|
/// 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
|
/// * `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 db = db_conn().await?;
|
||||||
|
|
||||||
let mut texts: Vec<String> = vec![];
|
let mut texts: Vec<String> = vec![];
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
// TODO?: handle name collisions
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
#[crate::export(object, js_name = "NoteLikeForGetNoteSummary")]
|
#[crate::export(object)]
|
||||||
pub struct NoteLike {
|
pub struct PartialNoteToSummarize {
|
||||||
pub file_ids: Vec<String>,
|
pub file_ids: Vec<String>,
|
||||||
pub text: Option<String>,
|
pub text: Option<String>,
|
||||||
pub cw: Option<String>,
|
pub cw: Option<String>,
|
||||||
|
@ -12,7 +11,7 @@ pub struct NoteLike {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[crate::export]
|
#[crate::export]
|
||||||
pub fn get_note_summary(note: NoteLike) -> String {
|
pub fn get_note_summary(note: PartialNoteToSummarize) -> String {
|
||||||
let mut buf: Vec<String> = vec![];
|
let mut buf: Vec<String> = vec![];
|
||||||
|
|
||||||
if let Some(cw) = note.cw {
|
if let Some(cw) = note.cw {
|
||||||
|
@ -36,12 +35,12 @@ pub fn get_note_summary(note: NoteLike) -> String {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod unit_test {
|
mod unit_test {
|
||||||
use super::{get_note_summary, NoteLike};
|
use super::{get_note_summary, PartialNoteToSummarize};
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_note_summary() {
|
fn test_note_summary() {
|
||||||
let note = NoteLike {
|
let note = PartialNoteToSummarize {
|
||||||
file_ids: vec![],
|
file_ids: vec![],
|
||||||
text: Some("Hello world!".to_string()),
|
text: Some("Hello world!".to_string()),
|
||||||
cw: None,
|
cw: None,
|
||||||
|
@ -49,7 +48,7 @@ mod unit_test {
|
||||||
};
|
};
|
||||||
assert_eq!(get_note_summary(note), "Hello world!");
|
assert_eq!(get_note_summary(note), "Hello world!");
|
||||||
|
|
||||||
let note_with_cw = NoteLike {
|
let note_with_cw = PartialNoteToSummarize {
|
||||||
file_ids: vec![],
|
file_ids: vec![],
|
||||||
text: Some("Hello world!".to_string()),
|
text: Some("Hello world!".to_string()),
|
||||||
cw: Some("Content warning".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");
|
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()],
|
file_ids: vec!["9s7fmcqogiq4igin".to_string()],
|
||||||
text: None,
|
text: None,
|
||||||
cw: Some("Selfie, no ec".to_string()),
|
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 📎");
|
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![
|
file_ids: vec![
|
||||||
"9s7fmcqogiq4igin".to_string(),
|
"9s7fmcqogiq4igin".to_string(),
|
||||||
"9s7qrld5u14cey98".to_string(),
|
"9s7qrld5u14cey98".to_string(),
|
||||||
|
@ -78,7 +77,7 @@ mod unit_test {
|
||||||
};
|
};
|
||||||
assert_eq!(get_note_summary(note_with_files_only), "📎 (4)");
|
assert_eq!(get_note_summary(note_with_files_only), "📎 (4)");
|
||||||
|
|
||||||
let note_all = NoteLike {
|
let note_all = PartialNoteToSummarize {
|
||||||
file_ids: vec![
|
file_ids: vec![
|
||||||
"9s7fmcqogiq4igin".to_string(),
|
"9s7fmcqogiq4igin".to_string(),
|
||||||
"9s7qrld5u14cey98".to_string(),
|
"9s7qrld5u14cey98".to_string(),
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use crate::database::{cache, db_conn, redis_conn, redis_key, RedisConnError};
|
use crate::database::{cache, db_conn, redis_conn, redis_key, RedisConnError};
|
||||||
use crate::federation::acct::Acct;
|
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::model::entity::{antenna, note};
|
||||||
use crate::service::antenna::check_hit::{check_hit_antenna, AntennaCheckError};
|
use crate::service::antenna::check_hit::{check_hit_antenna, AntennaCheckError};
|
||||||
use crate::service::stream;
|
use crate::service::stream;
|
||||||
|
@ -53,7 +53,7 @@ pub async fn update_antennas_on_new_note(
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let note_cloned = note.clone();
|
let note_cloned = note.clone();
|
||||||
let note_all_texts = all_texts(
|
let note_all_texts = all_texts(
|
||||||
NoteLike {
|
PartialNoteToElaborate {
|
||||||
file_ids: note.file_ids,
|
file_ids: note.file_ids,
|
||||||
user_id: note.user_id,
|
user_id: note.user_id,
|
||||||
text: note.text,
|
text: note.text,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::database::db_conn;
|
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::misc::meta::fetch_meta;
|
||||||
use crate::model::entity::sw_subscription;
|
use crate::model::entity::sw_subscription;
|
||||||
use crate::util::http_client;
|
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 text = get_note_summary(note_like);
|
||||||
|
|
||||||
let note_object = note.as_object_mut().unwrap();
|
let note_object = note.as_object_mut().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue