summaryrefslogtreecommitdiffstats
path: root/src/user.rs
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2025-06-02 19:50:45 +0100
committerLibravatar cel 🌸 <cel@bunny.garden>2025-06-02 19:50:45 +0100
commitab654372e4d3766c8df17623a6de8922fc2a1960 (patch)
tree59ff88ab5da68af23ad84bc2310730e29eb89410 /src/user.rs
parent6ee4190a26f32bfa953302ee363ad3bb6c384ebb (diff)
downloadmacaw-web-ab654372e4d3766c8df17623a6de8922fc2a1960.tar.gz
macaw-web-ab654372e4d3766c8df17623a6de8922fc2a1960.tar.bz2
macaw-web-ab654372e4d3766c8df17623a6de8922fc2a1960.zip
feat: make `MacawUser`, `MacawChat` and `MacawMessage` arena-allocated
Diffstat (limited to 'src/user.rs')
-rw-r--r--src/user.rs49
1 files changed, 45 insertions, 4 deletions
diff --git a/src/user.rs b/src/user.rs
index f55c0dd..e62ebea 100644
--- a/src/user.rs
+++ b/src/user.rs
@@ -7,12 +7,53 @@ use leptos::prelude::*;
use crate::{client::Client, roster::{Roster, RosterStoreFields}, state_store::{StateListener, StateStore}};
-#[derive(Clone)]
+#[derive(Clone, Copy)]
pub struct MacawUser {
- pub user: StateListener<BareJID, ArcStore<User>>,
+ pub user: ArenaItem<ArcMacawUser>,
+ // TODO: just store avatar src in user
+ // pub avatar: String,
}
impl MacawUser {
+ pub fn get(&self) -> ArcStore<User> {
+ self.try_get_value().unwrap().get()
+ }
+}
+
+impl Deref for MacawUser {
+ type Target = ArenaItem<ArcMacawUser>;
+
+ fn deref(&self) -> &Self::Target {
+ &self.user
+ }
+}
+
+impl DerefMut for MacawUser {
+ fn deref_mut(&mut self) -> &mut Self::Target {
+ &mut self.user
+ }
+}
+
+impl From<ArcMacawUser> for MacawUser {
+ fn from(value: ArcMacawUser) -> Self {
+ Self {
+ user: ArenaItem::new_with_storage(value),
+ }
+ }
+}
+
+impl From<MacawUser> for ArcMacawUser {
+ fn from(value: MacawUser) -> Self {
+ value.user.try_get_value().unwrap()
+ }
+}
+
+#[derive(Clone)]
+pub struct ArcMacawUser {
+ pub user: StateListener<BareJID, ArcStore<User>>,
+}
+
+impl ArcMacawUser {
pub fn got_user(user: User) -> Self {
let user_state_store: StateStore<BareJID, ArcStore<User>> =
@@ -22,7 +63,7 @@ impl MacawUser {
}
}
-impl Deref for MacawUser {
+impl Deref for ArcMacawUser {
type Target = StateListener<BareJID, ArcStore<User>>;
fn deref(&self) -> &Self::Target {
@@ -30,7 +71,7 @@ impl Deref for MacawUser {
}
}
-impl DerefMut for MacawUser {
+impl DerefMut for ArcMacawUser {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.user
}