From baa7f416bb0778e452878d4b097f76cdbd78134d Mon Sep 17 00:00:00 2001 From: dasman Date: Mon, 3 Jun 2024 04:58:23 +0300 Subject: [PATCH] bin/darkirc: get history outside join command if needed --- bin/darkirc/src/irc/client.rs | 2 +- bin/darkirc/src/irc/command.rs | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/bin/darkirc/src/irc/client.rs b/bin/darkirc/src/irc/client.rs index 6847427d7..3feb037fc 100644 --- a/bin/darkirc/src/irc/client.rs +++ b/bin/darkirc/src/irc/client.rs @@ -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?, diff --git a/bin/darkirc/src/irc/command.rs b/bin/darkirc/src/irc/command.rs index 2f2015af3..732fa30ae 100644 --- a/bin/darkirc/src/irc/command.rs +++ b/bin/darkirc/src/irc/command.rs @@ -243,7 +243,7 @@ impl Client { /// Makes the client join the channels in the list ``. /// Passwords can be used in the list ``. If the channels do not /// exist, they will be created. - pub async fn handle_cmd_join(&self, args: &str) -> Result> { + pub async fn handle_cmd_join(&self, args: &str, hist: bool) -> Result> { 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 = 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 }