✨ Add the capability to join a conversation
This commit is contained in:
@@ -776,6 +776,19 @@ impl Client {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
async fn join_room(&self, room_id: &RoomId) -> anyhow::Result<bool> {
|
||||
let client = self.client.as_ref().unwrap();
|
||||
|
||||
if let Some(room) = client.get_room(room_id) {
|
||||
return match room.join().await {
|
||||
Ok(_) => Ok(true),
|
||||
Err(err) => Err(err.into()),
|
||||
};
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn work(&mut self, mut rx: UnboundedReceiver<WorkerTask>) {
|
||||
while let Some(task) = rx.recv().await {
|
||||
self.run(task).await;
|
||||
@@ -820,6 +833,9 @@ impl Client {
|
||||
)
|
||||
.await;
|
||||
}
|
||||
WorkerTask::JoinRoom(id, reply) => {
|
||||
reply.send(self.join_room(&id).await).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -362,6 +362,10 @@ impl RoomMessagingProviderInterface for Requester {
|
||||
async fn get_avatar(&self, room_id: &RoomId) -> anyhow::Result<Option<Avatar>> {
|
||||
request_to_worker!(self, WorkerTask::GetRoomAvatar, room_id.clone())
|
||||
}
|
||||
|
||||
async fn join(&self, room_id: &RoomId) -> anyhow::Result<bool> {
|
||||
request_to_worker!(self, WorkerTask::JoinRoom, room_id.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait(?Send)]
|
||||
|
@@ -23,6 +23,7 @@ pub enum WorkerTask {
|
||||
OwnedUserId,
|
||||
Sender<anyhow::Result<Option<Vec<u8>>>>,
|
||||
),
|
||||
JoinRoom(OwnedRoomId, Sender<anyhow::Result<bool>>),
|
||||
}
|
||||
|
||||
impl Debug for WorkerTask {
|
||||
@@ -61,6 +62,10 @@ impl Debug for WorkerTask {
|
||||
.field(room_id)
|
||||
.field(user_id)
|
||||
.finish(),
|
||||
WorkerTask::JoinRoom(room_id, _) => f
|
||||
.debug_tuple("WorkerTask::JoinRoom")
|
||||
.field(room_id)
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user