Skip to content

Commit

Permalink
Add error to disconnected message
Browse files Browse the repository at this point in the history
  • Loading branch information
tarkah committed Jul 6, 2023
1 parent 71dabe9 commit 1b3268a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
8 changes: 6 additions & 2 deletions data/src/history/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ impl Manager {
.cloned();

let messages = match broadcast {
Broadcast::Disconnected => message::broadcast::disconnected(channels, queries),
Broadcast::Disconnected { error } => {
message::broadcast::disconnected(channels, queries, error)
}
Broadcast::Reconnected => message::broadcast::reconnected(channels, queries),
Broadcast::Quit {
user,
Expand Down Expand Up @@ -472,7 +474,9 @@ impl Data {

#[derive(Debug, Clone)]
pub enum Broadcast {
Disconnected,
Disconnected {
error: Option<String>,
},
Reconnected,
Quit {
user: User,
Expand Down
4 changes: 3 additions & 1 deletion data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,10 @@ pub(crate) mod broadcast {
pub fn disconnected(
channels: impl IntoIterator<Item = String>,
queries: impl IntoIterator<Item = Nick>,
error: Option<String>,
) -> Vec<Message> {
let text = " ∙ connection to server lost".into();
let error = error.map(|error| format!(" ({error})")).unwrap_or_default();
let text = format!(" ∙ connection to server lost{error}");
expand(channels, queries, true, text)
}

Expand Down
3 changes: 3 additions & 0 deletions data/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub enum Update {
Disconnected {
server: Server,
is_initial: bool,
error: Option<String>,
},
MessagesReceived(Server, Vec<message::Encoded>),
}
Expand Down Expand Up @@ -58,6 +59,7 @@ pub async fn run(server: server::Entry, mut sender: mpsc::Sender<Update>) -> Nev
.send(Update::Disconnected {
server: server.clone(),
is_initial,
error: None,
})
.await;

Expand Down Expand Up @@ -114,6 +116,7 @@ pub async fn run(server: server::Entry, mut sender: mpsc::Sender<Update>) -> Nev
.send(Update::Disconnected {
server: server.clone(),
is_initial,
error: Some(e.to_string()),
})
.await;
state = State::Disconnected {
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,19 @@ impl Application for Halloy {
Command::none()
}
Message::Stream(update) => match update {
stream::Update::Disconnected { server, is_initial } => {
stream::Update::Disconnected {
server,
is_initial,
error,
} => {
self.clients.disconnected(server.clone());

if !is_initial {
let Screen::Dashboard(dashboard) = &mut self.screen else {
return Command::none()
};

dashboard.broadcast_disconnected(&server);
dashboard.broadcast_disconnected(&server, error);
}

Command::none()
Expand Down
5 changes: 3 additions & 2 deletions src/screen/dashboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,8 +534,9 @@ impl Dashboard {
);
}

pub fn broadcast_disconnected(&mut self, server: &Server) {
self.history.broadcast(server, Broadcast::Disconnected);
pub fn broadcast_disconnected(&mut self, server: &Server, error: Option<String>) {
self.history
.broadcast(server, Broadcast::Disconnected { error });
}

pub fn broadcast_reconnected(&mut self, server: &Server) {
Expand Down

0 comments on commit 1b3268a

Please sign in to comment.