Skip to content

Commit bf201e3

Browse files
committed
feat(multiverse): Add a /leave command
1 parent fe11fda commit bf201e3

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

labs/multiverse/src/widgets/room_view/input.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct Cli {
1515
#[derive(Debug, Subcommand)]
1616
pub enum Command {
1717
Invite { user_id: String },
18+
Leave,
1819
}
1920

2021
pub enum MessageOrCommand {

labs/multiverse/src/widgets/room_view/mod.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,28 @@ impl RoomView {
300300
}
301301
}
302302

303+
async fn leave_room(&mut self) {
304+
let Some(room) = self
305+
.selected_room
306+
.as_deref()
307+
.and_then(|room_id| self.ui_rooms.lock().get(room_id).cloned())
308+
else {
309+
self.status_handle
310+
.set_message(format!("Coulnd't find the room object to leave the room"));
311+
return;
312+
};
313+
314+
let _ = room.leave().await.inspect_err(|e| {
315+
self.status_handle.set_message(format!("Couldn't leave the room {e:?}"))
316+
});
317+
318+
self.input.clear();
319+
}
320+
303321
async fn handle_command(&mut self, command: input::Command) {
304322
match command {
305323
input::Command::Invite { user_id } => self.invite_member(&user_id).await,
324+
input::Command::Leave => self.leave_room().await,
306325
}
307326
}
308327

0 commit comments

Comments
 (0)