1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
use std::ops::{Deref, DerefMut};
use filamento::{chat::Chat, user::User};
use jid::BareJID;
use reactive_stores::ArcStore;
use leptos::prelude::*;
use crate::{state_store::{StateListener, StateStore}, user::{ArcMacawUser, MacawUser}};
#[derive(Clone, Copy)]
pub struct MacawChat {
pub chat: ArenaItem<StateListener<BareJID, ArcStore<Chat>>>,
pub user: MacawUser,
// user: StateListener<BareJID, ArcStore<User>>,
}
impl MacawChat {
pub fn get(&self) -> ArcStore<Chat> {
self.try_get_value().unwrap().get()
}
}
impl Deref for MacawChat {
type Target = ArenaItem<StateListener<BareJID, ArcStore<Chat>>>;
fn deref(&self) -> &Self::Target {
&self.chat
}
}
impl DerefMut for MacawChat {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.chat
}
}
impl From<ArcMacawChat> for MacawChat {
fn from(value: ArcMacawChat) -> Self {
Self {
chat: ArenaItem::new_with_storage(value.chat),
user: value.user.into(),
}
}
}
impl From<MacawChat> for ArcMacawChat {
fn from(value: MacawChat) -> Self {
Self {
chat: value.chat.try_get_value().unwrap(),
user: value.user.into(),
}
}
}
#[derive(Clone)]
pub struct ArcMacawChat {
pub chat: StateListener<BareJID, ArcStore<Chat>>,
pub user: ArcMacawUser,
}
impl ArcMacawChat {
pub fn got_chat_and_user(chat: Chat, user: User) -> Self {
let chat_state_store: StateStore<BareJID, ArcStore<Chat>> =
use_context().expect("no chat state store");
let chat = chat_state_store.store(chat.correspondent.clone(), ArcStore::new(chat));
let user = ArcMacawUser::got_user(user);
Self { chat, user }
}
}
impl Deref for ArcMacawChat {
type Target = StateListener<BareJID, ArcStore<Chat>>;
fn deref(&self) -> &Self::Target {
&self.chat
}
}
impl DerefMut for ArcMacawChat {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.chat
}
}
|