diff --git a/magnetar_sdk/src/types/mod.rs b/magnetar_sdk/src/types/mod.rs index a3d7508..6920a5b 100644 --- a/magnetar_sdk/src/types/mod.rs +++ b/magnetar_sdk/src/types/mod.rs @@ -29,6 +29,11 @@ impl From<&str> for Id { } } +#[derive(Clone, Debug, Deserialize, Serialize, TS)] +#[ts(export)] +#[repr(transparent)] +pub struct MmXml(String); + #[derive(Copy, Clone, Debug, Deserialize, Serialize, TS)] #[ts(export)] pub enum NotificationType { diff --git a/magnetar_sdk/src/types/note.rs b/magnetar_sdk/src/types/note.rs index e5e5dbb..2942600 100644 --- a/magnetar_sdk/src/types/note.rs +++ b/magnetar_sdk/src/types/note.rs @@ -1,6 +1,6 @@ use crate::types::emoji::EmojiContext; use crate::types::user::PackUserBase; -use crate::types::Id; +use crate::types::{Id, MmXml}; use crate::{Packed, Required}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -52,9 +52,11 @@ pack!(PackPollBase, Required as id & Required as poll); pub struct NoteBase { pub created_at: DateTime, pub cw: Option, + pub cw_mm: Option, pub uri: Option, pub url: Option, pub text: String, + pub text_mm: MmXml, pub visibility: NoteVisibility, pub user: Box, pub parent_note_id: Option, @@ -63,10 +65,10 @@ pub struct NoteBase { pub renote_count: u64, pub hashtags: Vec, pub reactions: Vec, - pub emojis: EmojiContext, pub local_only: bool, pub has_poll: bool, pub file_ids: Vec, + pub emojis: EmojiContext, } pack!(PackNoteBase, Required as id & Required as note); diff --git a/magnetar_sdk/src/types/user.rs b/magnetar_sdk/src/types/user.rs index 6ff7e53..851a04a 100644 --- a/magnetar_sdk/src/types/user.rs +++ b/magnetar_sdk/src/types/user.rs @@ -1,5 +1,5 @@ use crate::types::emoji::EmojiContext; -use crate::types::{Id, NotificationSettings}; +use crate::types::{Id, MmXml, NotificationSettings}; use crate::{Packed, Required}; use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; @@ -29,6 +29,7 @@ pub enum SpeechTransform { pub struct ProfileField { name: String, value: String, + value_mm: Option, verified_at: Option>, } @@ -38,6 +39,7 @@ pub struct UserBase { pub acct: String, pub username: String, pub display_name: String, + pub display_name_mm: MmXml, pub host: Option, pub speech_transform: SpeechTransform, pub created_at: DateTime, @@ -61,6 +63,7 @@ pub struct UserProfileExt { pub is_suspended: bool, pub description: Option, + pub description_mm: Option, pub location: Option, pub birthday: Option>, pub fields: Vec, @@ -79,6 +82,7 @@ pub struct UserProfileExt { pub banner_blurhash: Option, pub has_public_reactions: bool, + pub emojis: EmojiContext, } #[derive(Clone, Debug, Deserialize, Serialize, TS)] diff --git a/src/model/data/note.rs b/src/model/data/note.rs index f2fcf83..987566b 100644 --- a/src/model/data/note.rs +++ b/src/model/data/note.rs @@ -6,6 +6,7 @@ use magnetar_sdk::types::{ emoji::EmojiContext, note::{NoteAttachmentExt, NoteBase, NoteVisibility, PackReactionBase, ReactionBase}, user::UserBase, + MmXml, }; use magnetar_sdk::{Packed, Required}; @@ -27,9 +28,11 @@ impl PackType<&ck::note_reaction::Model> for ReactionBase { pub struct NoteBaseSource<'a> { pub note: &'a ck::note::Model, + pub cw_mm: Option<&'a MmXml>, + pub text_mm: &'a MmXml, pub reactions: &'a Vec, - pub emojis: &'a EmojiContext, pub user: &'a UserBase, + pub emoji_context: &'a EmojiContext, } impl PackType> for NoteBase { @@ -37,18 +40,22 @@ impl PackType> for NoteBase { _context: &PackingContext, NoteBaseSource { note, + text_mm, + cw_mm, reactions, - emojis, user, + emoji_context, }: NoteBaseSource<'_>, ) -> Self { use ck::sea_orm_active_enums::NoteVisibilityEnum as NVE; NoteBase { created_at: note.created_at.into(), cw: note.cw.clone(), + cw_mm: cw_mm.cloned(), uri: note.uri.clone(), url: note.url.clone(), text: note.text.clone().unwrap_or_default(), + text_mm: text_mm.clone(), visibility: match note.visibility { NVE::Followers => NoteVisibility::Followers, NVE::Hidden => NoteVisibility::Direct, @@ -66,10 +73,10 @@ impl PackType> for NoteBase { renote_count: note.renote_count as u64, hashtags: note.tags.clone(), reactions: reactions.clone(), - emojis: emojis.clone(), local_only: note.local_only, has_poll: note.has_poll, file_ids: note.file_ids.clone(), + emojis: emoji_context.clone(), } } } diff --git a/src/model/data/user.rs b/src/model/data/user.rs index 5975976..03f033c 100644 --- a/src/model/data/user.rs +++ b/src/model/data/user.rs @@ -3,9 +3,10 @@ use magnetar_calckey_model::ck::sea_orm_active_enums::UserProfileFfvisibilityEnu use magnetar_sdk::types::emoji::{EmojiContext, PackEmojiBase}; use magnetar_sdk::types::note::PackNoteFull; use magnetar_sdk::types::user::{ - AvatarDecoration, PackSecurityKeyBase, SecurityKeyBase, SpeechTransform, UserBase, - UserDetailExt, UserProfileExt, UserProfilePinsEx, UserRelationExt, UserSecretsExt, + AvatarDecoration, PackSecurityKeyBase, ProfileField, SecurityKeyBase, SpeechTransform, + UserBase, UserDetailExt, UserProfileExt, UserProfilePinsEx, UserRelationExt, UserSecretsExt, }; +use magnetar_sdk::types::MmXml; use crate::model::{PackType, PackingContext}; @@ -15,14 +16,23 @@ impl PackType<&[PackEmojiBase]> for EmojiContext { } } -type UserBaseSource<'a> = ( - &'a ck::user::Model, - &'a Option, - &'a EmojiContext, -); +struct UserBaseSource<'a> { + user: &'a ck::user::Model, + username_mm: &'a MmXml, + avatar: &'a Option, + emoji_context: &'a EmojiContext, +} impl PackType> for UserBase { - fn extract(_context: &PackingContext, (user, avatar, emoji_context): UserBaseSource) -> Self { + fn extract( + _context: &PackingContext, + UserBaseSource { + user, + username_mm, + avatar, + emoji_context, + }: UserBaseSource, + ) -> Self { UserBase { acct: user .host @@ -31,6 +41,7 @@ impl PackType> for UserBase { .unwrap_or_else(|| format!("@{}", user.username)), username: user.username.clone(), display_name: user.name.clone().unwrap_or_else(|| user.username.clone()), + display_name_mm: username_mm.clone(), host: user.host.clone(), speech_transform: if user.is_cat && user.speak_as_cat { SpeechTransform::Cat @@ -54,14 +65,27 @@ impl PackType> for UserBase { } } -type UserProfileExtSource<'a> = ( - &'a ck::user::Model, - &'a ck::user_profile::Model, - Option<&'a UserRelationExt>, -); +struct UserProfileExtSource<'a> { + user: &'a ck::user::Model, + profile: &'a ck::user_profile::Model, + profile_fields: &'a Vec, + description_mm: Option<&'a MmXml>, + relation: Option<&'a UserRelationExt>, + emoji_context: &'a EmojiContext, +} impl PackType> for UserProfileExt { - fn extract(context: &PackingContext, (user, profile, relation): UserProfileExtSource) -> Self { + fn extract( + context: &PackingContext, + UserProfileExtSource { + user, + profile, + profile_fields, + description_mm, + relation, + emoji_context, + }: UserProfileExtSource, + ) -> Self { let follow_visibility = match profile.ff_visibility { UserProfileFfvisibilityEnum::Public => true, UserProfileFfvisibilityEnum::Followers => relation.is_some_and(|r| r.follows_you), @@ -73,12 +97,13 @@ impl PackType> for UserProfileExt { is_silenced: user.is_silenced, is_suspended: user.is_suspended, description: profile.description.clone(), + description_mm: description_mm.cloned(), location: profile.location.clone(), birthday: profile .birthday .clone() .and_then(|b| b.parse().map_or_else(|_| None, Some)), - fields: serde_json::from_value(profile.fields.clone()).unwrap_or_else(|_| Vec::new()), + fields: profile_fields.clone(), follower_count: follow_visibility.then_some(user.followers_count as u64), following_count: follow_visibility.then_some(user.following_count as u64), note_count: Some(user.notes_count as u64), @@ -89,6 +114,7 @@ impl PackType> for UserProfileExt { banner_color: None, banner_blurhash: None, has_public_reactions: profile.public_reactions, + emojis: emoji_context.clone(), } } } @@ -103,19 +129,26 @@ impl PackType<&ck::user::Model> for UserDetailExt { } } -type UserRelationExtSource<'a> = ( - Option<&'a ck::following::Model>, - Option<&'a ck::following::Model>, - Option<&'a ck::blocking::Model>, - Option<&'a ck::blocking::Model>, - Option<&'a ck::muting::Model>, - Option<&'a ck::renote_muting::Model>, -); +struct UserRelationExtSource<'a> { + follow_out: Option<&'a ck::following::Model>, + follow_in: Option<&'a ck::following::Model>, + block_out: Option<&'a ck::blocking::Model>, + block_in: Option<&'a ck::blocking::Model>, + mute: Option<&'a ck::muting::Model>, + renote_mute: Option<&'a ck::renote_muting::Model>, +} impl PackType> for UserRelationExt { fn extract( context: &PackingContext, - (follow_out, follow_in, block_out, block_in, mute, renote_mute): UserRelationExtSource, + UserRelationExtSource { + follow_out, + follow_in, + block_out, + block_in, + mute, + renote_mute, + }: UserRelationExtSource, ) -> Self { let self_user = context.self_user();