Skip to content

Commit

Permalink
ui: unify chat update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick committed Oct 6, 2024
1 parent 96f0908 commit 96b8e77
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/gui/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,22 +286,25 @@ impl UIState {
}

pub fn mark_all_as_disconnected(&mut self) {
for chat in self.chats.iter_mut() {
chat.set_state(
let open_chats: Vec<String> = self.chats.iter().map(|ch| ch.name.clone()).collect();
for chat_name in open_chats {
self.set_chat_state(
&chat_name,
ChatState::Left,
Some("You have left the chat (disconnected)"),
);
}
}

pub fn mark_all_as_connected(&mut self) {
for chat in self.chats.iter_mut() {
let (new_state, reason) = match chat.name.is_channel() {
let open_chats: Vec<String> = self.chats.iter().map(|ch| ch.name.clone()).collect();
for chat_name in open_chats {
let (new_state, reason) = match chat_name.is_channel() {
// Joins are handled by the app server
true => (ChatState::JoinInProgress, None),
false => (ChatState::Joined, Some("You are online")),
};
chat.set_state(new_state, reason);
self.set_chat_state(&chat_name, new_state, reason);
}
}
}

0 comments on commit 96b8e77

Please sign in to comment.