bin/darkirc: get history outside join command if needed

This commit is contained in:
dasman
2024-06-03 04:58:23 +03:00
parent b4f435d315
commit baa7f416bb
2 changed files with 13 additions and 16 deletions

View File

@@ -334,7 +334,7 @@ impl Client {
"ADMIN" => self.handle_cmd_admin(&args).await?,
"CAP" => self.handle_cmd_cap(&args).await?,
"INFO" => self.handle_cmd_info(&args).await?,
"JOIN" => self.handle_cmd_join(&args).await?,
"JOIN" => self.handle_cmd_join(&args, true).await?,
"LIST" => self.handle_cmd_list(&args).await?,
"MODE" => self.handle_cmd_mode(&args).await?,
"MOTD" => self.handle_cmd_motd(&args).await?,

View File

@@ -243,7 +243,7 @@ impl Client {
/// Makes the client join the channels in the list `<channels>`.
/// Passwords can be used in the list `<keys>`. If the channels do not
/// exist, they will be created.
pub async fn handle_cmd_join(&self, args: &str) -> Result<Vec<ReplyType>> {
pub async fn handle_cmd_join(&self, args: &str, hist: bool) -> Result<Vec<ReplyType>> {
if !self.registered.load(SeqCst) {
self.penalty.fetch_add(1, SeqCst);
return Ok(vec![ReplyType::Server((
@@ -325,17 +325,6 @@ impl Client {
// Create the replies
replies.push(ReplyType::Client((nick.clone(), format!("JOIN :{}", channel))));
////////////////////
// replies.push(ReplyType::Server((
// RPL_NAMREPLY,
// format!("{} = {} :{}", nick, channel, nick),
// )));
// replies.push(ReplyType::Server((
// RPL_ENDOFNAMES,
// format!("{} {} :End of NAMES list", nick, channel),
// )));
////////////////////
if let Some(chan) = server_channels.get(channel) {
if !chan.topic.is_empty() {
replies.push(ReplyType::Client((
@@ -350,8 +339,10 @@ impl Client {
drop(active_channels);
drop(server_channels);
// Potentially extend the replies with channel history
replies.extend(self.get_history(&channels).await.unwrap());
if hist {
// Potentially extend the replies with channel history
replies.extend(self.get_history(&channels).await.unwrap());
}
Ok(replies)
}
@@ -892,11 +883,13 @@ impl Client {
// Append the MOTD
replies.append(&mut self.handle_cmd_motd("").await.unwrap());
let mut channels = HashSet::new();
// If we have any configured autojoin channels, let's join the user
// and set their topics, if any. And request NAMES list.
if !*self.caps.read().await.get("no-autojoin").unwrap() {
for channel in self.server.autojoin.read().await.iter() {
replies.extend(self.handle_cmd_join(channel).await.unwrap());
replies.extend(self.handle_cmd_join(channel, false).await.unwrap());
if let Some(chan) = self.server.channels.read().await.get(channel) {
let nicks: Vec<String> = chan.nicks.iter().cloned().collect();
@@ -911,9 +904,13 @@ impl Client {
RPL_ENDOFNAMES,
format!("{} {} :End of NAMES list", nick, channel),
)));
channels.insert(channel.to_string());
}
}
// Potentially extend the replies with channel history
replies.extend(self.get_history(&channels).await.unwrap());
replies
}