aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Smeding <tom.smeding@gmail.com>2020-10-13 20:47:57 +0200
committerTom Smeding <tom.smeding@gmail.com>2021-01-28 22:20:13 +0100
commit5c762eaf2310d72b7c5c7d2ba497d94c6441126a (patch)
tree6b8034d2a13c74f7ed39af466227471492da440c
parentb75f78e092414d39a6d33210eab40fe7742c0b37 (diff)
rust: Understand _push leave
-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 {