summaryrefslogtreecommitdiffstats
path: root/src/components/roster_list/roster_list_item.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/roster_list/roster_list_item.rs')
-rw-r--r--src/components/roster_list/roster_list_item.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/components/roster_list/roster_list_item.rs b/src/components/roster_list/roster_list_item.rs
new file mode 100644
index 0000000..46ac1cc
--- /dev/null
+++ b/src/components/roster_list/roster_list_item.rs
@@ -0,0 +1,62 @@
+use std::ops::Deref;
+
+use filamento::{chat::Chat, roster::{Contact, ContactStoreFields}, user::{User, UserStoreFields}};
+use leptos::prelude::*;
+use reactive_stores::{ArcStore, Store};
+use tracing::debug;
+
+use crate::{chat::MacawChat, components::{avatar::AvatarWithPresence, sidebar::Open}, contact::MacawContact, open_chats::{OpenChatsPanel, OpenChatsPanelStoreFields}, user::get_name};
+
+#[component]
+pub fn RosterListItem(contact: MacawContact) -> impl IntoView {
+ let contact_contact: Store<Contact> = contact.contact;
+ let contact_user: Store<User> =
+ <ArcStore<filamento::user::User> as Clone>::clone(&contact.user).into();
+ let name = move || get_name(contact_user, false);
+
+ let open_chats: Store<OpenChatsPanel> =
+ use_context().expect("no open chats panel store in context");
+
+ // TODO: why can this not be in the closure?????
+ // TODO: not good, as overwrites preexisting chat state with possibly incorrect one...
+ let chat = Chat {
+ correspondent: contact_user.jid().get(),
+ have_chatted: false,
+ };
+ let chat = MacawChat::got_chat_and_user(chat, contact_user.get());
+
+ let open_chat = move |_| {
+ debug!("opening chat");
+ open_chats.update(|open_chats| open_chats.open(chat.clone()));
+ };
+
+ let open = move || {
+ if let Some(open_chat) = &*open_chats.chat_view().read() {
+ debug!("got open chat: {:?}", open_chat);
+ if *open_chat == *contact_user.jid().read() {
+ return Open::Focused;
+ }
+ }
+ if let Some(_backgrounded_chat) = open_chats
+ .chats()
+ .read()
+ .get(contact_user.jid().read().deref())
+ {
+ return Open::Open;
+ }
+ Open::Closed
+ };
+ let focused = move || open().is_focused();
+ let open = move || open().is_open();
+
+ view! {
+ <div class="roster-list-item" class:open=move || open() class:focused=move || focused() on:click=open_chat>
+ <AvatarWithPresence user=contact_user />
+ <div class="item-info">
+ <div class="main-info"><p class="name">{name}<span class="jid"> - {move || contact_contact.user_jid().read().to_string()}</span></p></div>
+ <div class="sub-info">{move || contact_contact.subscription().read().to_string()}</div>
+ </div>
+ </div>
+ }
+}
+