Backend: Prep for MMM parser processing
This commit is contained in:
parent
42e68fffcd
commit
fc86f0e29c
|
@ -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 {
|
||||
|
|
|
@ -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<Id> as id & Required<PollBase> as poll);
|
|||
pub struct NoteBase {
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub cw: Option<String>,
|
||||
pub cw_mm: Option<MmXml>,
|
||||
pub uri: Option<String>,
|
||||
pub url: Option<String>,
|
||||
pub text: String,
|
||||
pub text_mm: MmXml,
|
||||
pub visibility: NoteVisibility,
|
||||
pub user: Box<PackUserBase>,
|
||||
pub parent_note_id: Option<String>,
|
||||
|
@ -63,10 +65,10 @@ pub struct NoteBase {
|
|||
pub renote_count: u64,
|
||||
pub hashtags: Vec<String>,
|
||||
pub reactions: Vec<PackReactionBase>,
|
||||
pub emojis: EmojiContext,
|
||||
pub local_only: bool,
|
||||
pub has_poll: bool,
|
||||
pub file_ids: Vec<String>,
|
||||
pub emojis: EmojiContext,
|
||||
}
|
||||
|
||||
pack!(PackNoteBase, Required<Id> as id & Required<NoteBase> as note);
|
||||
|
|
|
@ -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<MmXml>,
|
||||
verified_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
|
@ -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<String>,
|
||||
pub speech_transform: SpeechTransform,
|
||||
pub created_at: DateTime<Utc>,
|
||||
|
@ -61,6 +63,7 @@ pub struct UserProfileExt {
|
|||
pub is_suspended: bool,
|
||||
|
||||
pub description: Option<String>,
|
||||
pub description_mm: Option<MmXml>,
|
||||
pub location: Option<String>,
|
||||
pub birthday: Option<DateTime<Utc>>,
|
||||
pub fields: Vec<ProfileField>,
|
||||
|
@ -79,6 +82,7 @@ pub struct UserProfileExt {
|
|||
pub banner_blurhash: Option<String>,
|
||||
|
||||
pub has_public_reactions: bool,
|
||||
pub emojis: EmojiContext,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, TS)]
|
||||
|
|
|
@ -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<PackReactionBase>,
|
||||
pub emojis: &'a EmojiContext,
|
||||
pub user: &'a UserBase,
|
||||
pub emoji_context: &'a EmojiContext,
|
||||
}
|
||||
|
||||
impl PackType<NoteBaseSource<'_>> for NoteBase {
|
||||
|
@ -37,18 +40,22 @@ impl PackType<NoteBaseSource<'_>> 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<NoteBaseSource<'_>> 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(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ck::drive_file::Model>,
|
||||
&'a EmojiContext,
|
||||
);
|
||||
struct UserBaseSource<'a> {
|
||||
user: &'a ck::user::Model,
|
||||
username_mm: &'a MmXml,
|
||||
avatar: &'a Option<ck::drive_file::Model>,
|
||||
emoji_context: &'a EmojiContext,
|
||||
}
|
||||
|
||||
impl PackType<UserBaseSource<'_>> 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<UserBaseSource<'_>> 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<UserBaseSource<'_>> 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<ProfileField>,
|
||||
description_mm: Option<&'a MmXml>,
|
||||
relation: Option<&'a UserRelationExt>,
|
||||
emoji_context: &'a EmojiContext,
|
||||
}
|
||||
|
||||
impl PackType<UserProfileExtSource<'_>> 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<UserProfileExtSource<'_>> 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<UserProfileExtSource<'_>> 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<UserRelationExtSource<'_>> 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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue