diff options
Diffstat (limited to '')
| -rw-r--r-- | src/contact.rs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/contact.rs b/src/contact.rs new file mode 100644 index 0000000..b7f57fa --- /dev/null +++ b/src/contact.rs @@ -0,0 +1,67 @@ +// SPDX-FileCopyrightText: 2025 cel <cel@bunny.garden> +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +use std::ops::{Deref, DerefMut}; + +use filamento::{roster::Contact, user::User}; +use reactive_stores::Store; + +use crate::user::{ArcMacawUser, MacawUser}; + +#[derive(Clone, Copy)] +pub struct MacawContact { + pub contact: Store<Contact>, + pub user: MacawUser, +} + +impl Deref for MacawContact { + type Target = Store<Contact>; + + fn deref(&self) -> &Self::Target { + &self.contact + } +} + +impl DerefMut for MacawContact { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.contact + } +} + +impl From<ArcMacawContact> for MacawContact { + fn from(value: ArcMacawContact) -> Self { + Self { + contact: value.contact, + user: value.user.into(), + } + } +} + +#[derive(Clone)] +pub struct ArcMacawContact { + pub contact: Store<Contact>, + pub user: ArcMacawUser, +} + +impl ArcMacawContact { + pub async fn got_contact_and_user(contact: Contact, user: User) -> Self { + let contact = Store::new(contact); + let user = ArcMacawUser::got_user(user).await; + Self { contact, user } + } +} + +impl Deref for ArcMacawContact { + type Target = Store<Contact>; + + fn deref(&self) -> &Self::Target { + &self.contact + } +} + +impl DerefMut for ArcMacawContact { + fn deref_mut(&mut self) -> &mut Self::Target { + &mut self.contact + } +} |
