✨ Add the capability to join a conversation
This commit is contained in:
@@ -2,6 +2,7 @@ use std::{rc::Rc, time::Duration};
|
||||
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use dioxus::prelude::*;
|
||||
use futures_util::StreamExt;
|
||||
use tracing::{debug, warn};
|
||||
|
||||
use super::{button::Button, icons::SearchIcon, text_input::TextInput};
|
||||
@@ -431,11 +432,16 @@ pub fn Search() -> Element {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
enum ConversationOptionsMenuActions {
|
||||
Join(RoomId),
|
||||
Close,
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn ConversationOptionsMenu(
|
||||
room_id: RoomId,
|
||||
on_close: EventHandler,
|
||||
on_join: EventHandler,
|
||||
callbacks: Coroutine<ConversationOptionsMenuActions>,
|
||||
) -> Element {
|
||||
let room = STORE.read().rooms().get(&room_id).unwrap().signal();
|
||||
|
||||
@@ -450,7 +456,7 @@ fn ConversationOptionsMenu(
|
||||
|
||||
div {
|
||||
class: ClassName::CONVERSATION_OPTIONS_MENU_INNER_AVATAR,
|
||||
ConversationAvatar { room_id }
|
||||
ConversationAvatar { room_id: room_id.clone() }
|
||||
}
|
||||
|
||||
div {
|
||||
@@ -477,7 +483,9 @@ fn ConversationOptionsMenu(
|
||||
div {
|
||||
class: ClassName::CONVERSATION_OPTIONS_MENU_INNER_CLOSE_BUTTON,
|
||||
RejectButton {
|
||||
onclick: move |_| on_close(())
|
||||
onclick: move |_| {
|
||||
callbacks.send(ConversationOptionsMenuActions::Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -485,8 +493,8 @@ fn ConversationOptionsMenu(
|
||||
class: ClassName::CONVERSATION_OPTIONS_MENU_INNER_JOIN_BUTTON,
|
||||
JoinButton {
|
||||
onclick: move |_| {
|
||||
on_join(());
|
||||
on_close(());
|
||||
callbacks.send(ConversationOptionsMenuActions::Join(room_id.clone()));
|
||||
callbacks.send(ConversationOptionsMenuActions::Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -498,26 +506,33 @@ fn ConversationOptionsMenu(
|
||||
pub fn Conversations() -> Element {
|
||||
let mut room_id = use_signal(|| None::<RoomId>);
|
||||
|
||||
let on_menu_close = move |_| {
|
||||
room_id.set(None);
|
||||
};
|
||||
|
||||
let on_menu_join = move |_| async move {
|
||||
let rooms = STORE.read().rooms();
|
||||
if let Some(room_id) = room_id.read().to_owned() {
|
||||
if let Some(room) = rooms.get(&room_id) {}
|
||||
}
|
||||
};
|
||||
|
||||
let on_pressed_conversation = move |id: RoomId| {
|
||||
room_id.set(Some(id));
|
||||
};
|
||||
|
||||
let callbacks = use_coroutine(
|
||||
move |mut rx: UnboundedReceiver<ConversationOptionsMenuActions>| async move {
|
||||
while let Some(action) = rx.next().await {
|
||||
match action {
|
||||
ConversationOptionsMenuActions::Join(room_id) => {
|
||||
let rooms = STORE.read().rooms();
|
||||
if let Some(room) = rooms.get(&room_id) {
|
||||
room.join().await;
|
||||
}
|
||||
}
|
||||
ConversationOptionsMenuActions::Close => {
|
||||
room_id.set(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let menu = match room_id.read().as_ref() {
|
||||
Some(room_id) => {
|
||||
let room_id = room_id.clone();
|
||||
rsx! {
|
||||
ConversationOptionsMenu { room_id, on_close: on_menu_close, on_join: on_menu_join }
|
||||
ConversationOptionsMenu { room_id, callbacks }
|
||||
}
|
||||
}
|
||||
None => VNode::empty(),
|
||||
|
@@ -33,7 +33,6 @@ pub struct Store {
|
||||
pub struct Room {
|
||||
store: RefCell<Store>,
|
||||
|
||||
#[allow(dead_code)]
|
||||
domain: Rc<dyn RoomStoreConsumerInterface>,
|
||||
}
|
||||
|
||||
@@ -57,6 +56,10 @@ impl Room {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn join(&self) {
|
||||
self.domain.join().await;
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn get_avatar(&self) -> Option<Avatar> {
|
||||
self.domain.avatar().await
|
||||
@@ -81,6 +84,11 @@ impl RoomStoreProviderInterface for Room {
|
||||
|
||||
fn on_new_member(&self, member: RoomMember) {
|
||||
let mut store = self.store.borrow_mut();
|
||||
|
||||
if member.is_account_user() {
|
||||
store.is_invited.set(false);
|
||||
}
|
||||
|
||||
store.members.write().push(member);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user