aboutsummaryrefslogtreecommitdiff
path: root/rust/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rust/src/main.rs')
-rw-r--r--rust/src/main.rs30
1 files changed, 30 insertions, 0 deletions
diff --git a/rust/src/main.rs b/rust/src/main.rs
index 0d5767f..f7a2660 100644
--- a/rust/src/main.rs
+++ b/rust/src/main.rs
@@ -252,6 +252,21 @@ impl App {
Ok(())
}
+ async fn leave_room(self: &Arc<Self>, room: &Word) -> io::Result<()> {
+ debug!("leave_room({})", room);
+
+ {
+ let mut state = self.state.lock().await;
+ if state.currentroom == *room {
+ state.currentroom = STATUS_ROOM.clone();
+ }
+ state.roomlist.retain(|r| r != room);
+ state.rooms.remove(room);
+ }
+
+ self.full_redraw().await
+ }
+
async fn put_members(self: &Arc<Self>, room: &Word, ms: Vec<Word>) -> io::Result<()> {
debug!("put_members {} #{}", room, ms.len());
let mut state = self.state.lock().await;
@@ -266,6 +281,13 @@ impl App {
state.full_redraw()
}
+ async fn remove_member(self: &Arc<Self>, room: &Word, user: Word) -> io::Result<()> {
+ debug!("remove_member {} {}", room, user);
+ let mut state = self.state.lock().await;
+ state.rooms.get_mut(room).unwrap().members.retain(|u| *u != user);
+ state.full_redraw()
+ }
+
async fn put_history(self: &Arc<Self>, room: &Word, hist: Vec<Message>) -> io::Result<()> {
debug!("put_history {} #{}", room, hist.len());
let mut state = self.state.lock().await;
@@ -335,6 +357,14 @@ impl App {
self.add_member(&room, username.clone()).await.unwrap();
self.append_history_item(&room, HItem::Service(format!("Join: <{}>", username), false)).await.unwrap();
}
+ PushMessage::Leave { roomname: room, username: user } => {
+ if user == self.username {
+ self.leave_room(&room).await.unwrap();
+ } else {
+ self.remove_member(&room, user.clone()).await.unwrap();
+ self.append_history_item(&room, HItem::Service(format!("Leave: <{}>", user), false)).await.unwrap();
+ }
+ }
PushMessage::Message(msg) => {
let mention = contains_mention(&msg.message, &self.username);
if self.decide_push_notify(&msg.roomname, mention).await {