Skip to content

Commit

Permalink
IRC: unify disconnect logic and return an error when server shuts down
Browse files Browse the repository at this point in the history
  • Loading branch information
TicClick committed Apr 8, 2024
1 parent 95ea9ce commit f1fbbb9
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/core/irc/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl IRCActor {
.unwrap();
*irc_stream_sender.lock().unwrap() = Some(clt.sender());

let mut disconnected_by_user = false;
let mut stream = clt.stream().unwrap();
loop {
let (lock, cv) = &*arc;
Expand All @@ -130,10 +131,7 @@ impl IRCActor {
if *g {
*g = false;
clt.send_quit("").unwrap();
tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected { by_user: true },
))
.unwrap();
disconnected_by_user = true;
break;
}
}
Expand All @@ -148,25 +146,28 @@ impl IRCActor {
)),
))
.unwrap();
tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected { by_user: false },
))
.unwrap();
break;
}
Ok(msg) => {
event_handler::dispatch_message(&tx, msg, &own_username);
}
},
None => {
tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected { by_user: false },
))
tx.blocking_send(AppMessageIn::ChatError(IRCError::FatalError(
"remote server has closed the connection, probably because it went offline".to_owned(),
)))
.unwrap();
break;
}
}
}

tx.blocking_send(AppMessageIn::ConnectionChanged(
ConnectionStatus::Disconnected {
by_user: disconnected_by_user,
},
))
.unwrap();
}
}
}));
Expand Down

0 comments on commit f1fbbb9

Please sign in to comment.