🚧 Add an interface to the ChatsWindows to drive its behavior
For now, only the ChatsWindow tabs are toggled on clicks on room names (from ContactsSection).
This commit is contained in:
@@ -1,8 +1,7 @@
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use dioxus::prelude::to_owned;
|
||||
use dioxus::prelude::*;
|
||||
use tokio::sync::broadcast::Sender;
|
||||
use tokio::sync::mpsc::{unbounded_channel, UnboundedReceiver};
|
||||
use tokio::sync::{broadcast, oneshot};
|
||||
@@ -157,12 +156,10 @@ impl Client {
|
||||
|
||||
async fn on_original_sync_room_member_event(
|
||||
_ev: OriginalSyncRoomMemberEvent,
|
||||
room: MatrixRoom,
|
||||
_room: MatrixRoom,
|
||||
_client: MatrixClient,
|
||||
) {
|
||||
debug!("== on_original_sync_room_member_event ==");
|
||||
let room_id = room.room_id();
|
||||
dbg!(room_id);
|
||||
|
||||
// let mut store = store_ctx.read().unwrap().to_owned();
|
||||
// dbg!(store.rooms.keys());
|
||||
@@ -403,11 +400,11 @@ impl Client {
|
||||
WorkerTask::Init(reply) => {
|
||||
assert!(!self.initialized);
|
||||
self.init();
|
||||
reply.send(());
|
||||
reply.send(()).await;
|
||||
}
|
||||
WorkerTask::Login(style, reply) => {
|
||||
assert!(self.initialized);
|
||||
reply.send(self.login_and_sync(style).await);
|
||||
reply.send(self.login_and_sync(style).await).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,15 +1,15 @@
|
||||
use std::cell::RefCell;
|
||||
use std::sync::Arc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use matrix_sdk::Client as MatrixClient;
|
||||
use tokio::sync::broadcast::Receiver;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
|
||||
use super::client::RoomTopicEvent;
|
||||
use super::worker_tasks::{oneshot, LoginStyle, WorkerTask};
|
||||
use super::worker_tasks::{LoginStyle, WorkerTask};
|
||||
use crate::base::Room;
|
||||
use crate::utils::oneshot;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Receivers {
|
||||
pub rooms_receiver: RefCell<Receiver<Room>>,
|
||||
pub room_topic_receiver: RefCell<Receiver<RoomTopicEvent>>,
|
||||
@@ -24,7 +24,6 @@ impl Clone for Receivers {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Requester {
|
||||
pub matrix_client: Arc<MatrixClient>,
|
||||
pub tx: UnboundedSender<WorkerTask>,
|
||||
@@ -32,15 +31,23 @@ pub struct Requester {
|
||||
}
|
||||
|
||||
impl Requester {
|
||||
pub fn init(&self) {
|
||||
let (reply, response) = oneshot();
|
||||
pub async fn init(&self) -> anyhow::Result<()> {
|
||||
let (reply, mut response) = oneshot();
|
||||
// TODO: Handle error case.
|
||||
self.tx.send(WorkerTask::Init(reply)).unwrap();
|
||||
response.recv()
|
||||
match response.recv().await {
|
||||
Some(result) => Ok(result),
|
||||
None => Err(anyhow::Error::msg("TBD")),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn login(&self, style: LoginStyle) -> anyhow::Result<()> {
|
||||
let (reply, response) = oneshot();
|
||||
pub async fn login(&self, style: LoginStyle) -> anyhow::Result<()> {
|
||||
let (reply, mut response) = oneshot();
|
||||
// TODO: Handle error case.
|
||||
self.tx.send(WorkerTask::Login(style, reply)).unwrap();
|
||||
response.recv()
|
||||
match response.recv().await {
|
||||
Some(result) => result,
|
||||
None => Err(anyhow::Error::msg("TBD")),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,31 +1,6 @@
|
||||
use std::fmt::{Debug, Formatter};
|
||||
|
||||
use std::sync::mpsc::{sync_channel, Receiver, SyncSender};
|
||||
|
||||
pub struct ClientResponse<T>(Receiver<T>);
|
||||
pub struct ClientReply<T>(SyncSender<T>);
|
||||
|
||||
impl<T> ClientResponse<T> {
|
||||
pub(super) fn recv(self) -> T {
|
||||
self.0
|
||||
.recv()
|
||||
.expect("failed to receive response from client thread")
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ClientReply<T> {
|
||||
pub(super) fn send(self, t: T) {
|
||||
self.0.send(t).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn oneshot<T>() -> (ClientReply<T>, ClientResponse<T>) {
|
||||
let (tx, rx) = sync_channel(1);
|
||||
let reply = ClientReply(tx);
|
||||
let response = ClientResponse(rx);
|
||||
|
||||
(reply, response)
|
||||
}
|
||||
use crate::utils::Sender;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum LoginStyle {
|
||||
@@ -36,9 +11,9 @@ pub enum LoginStyle {
|
||||
pub enum WorkerTask {
|
||||
// Init(AsyncProgramStore, ClientReply<()>),
|
||||
// Init(ClientReply<()>),
|
||||
Init(ClientReply<()>),
|
||||
Init(Sender<()>),
|
||||
//Login(LoginStyle, ClientReply<EditInfo>),
|
||||
Login(LoginStyle, ClientReply<anyhow::Result<()>>),
|
||||
Login(LoginStyle, Sender<anyhow::Result<()>>),
|
||||
}
|
||||
|
||||
impl Debug for WorkerTask {
|
||||
|
Reference in New Issue
Block a user