Bladeren bron

darkirc: remove redundant checks and edit comments

dasman 1 jaar geleden
bovenliggende
commit
f861a0d4ed
1 gewijzigde bestanden met toevoegingen van 29 en 38 verwijderingen
  1. 29 38
      bin/darkirc/src/irc/client.rs

+ 29 - 38
bin/darkirc/src/irc/client.rs

@@ -41,7 +41,7 @@ use smol::{
 };
 
 use super::{
-    server::{IrcServer, MAX_MSG_LEN, MAX_NICK_LEN},
+    server::{IrcServer, MAX_MSG_LEN},
     Msg, NickServ, OldPrivmsg, SERVER_NAME,
 };
 
@@ -245,9 +245,10 @@ impl Client {
                         continue
                     }
 
-                    // If the privmsg is intented for any of the given
-                    // channels, contacts or oursleves, add it as a reply and
-                    // mark it as seen in the seen_events tree.
+                    // If the privmsg is not intented for any of the given
+                    // channels or contacts, ignore it
+                    // otherwise add it as a reply and mark it as seen
+                    // in the seen_events tree.
                     let channels = self.channels.read().await;
                     let contacts = self.server.contacts.read().await;
                     if !channels.contains(&privmsg.channel) &&
@@ -256,45 +257,35 @@ impl Client {
                         continue
                     }
 
-                    // If we have this channel, or it's a DM, forward it to the client.
-                    // As a DM, we consider something that is <= MAX_NICK_LEN, and does not
-                    // start with the '#' character. With ChaCha, the ciphertext should be
-                    // longer than our MAX_NICK_LEN, so in case it is garbled, it should be
-                    // skipped by this code.
-                    let have_channel = channels.contains(&privmsg.channel);
-                    let is_dm = !privmsg.channel.starts_with('#') && privmsg.channel.len() <= MAX_NICK_LEN;
-
-                    if have_channel || is_dm {
-                        // Add the nickname to the list of nicks on the channel, if it's a channel.
-                        let mut chans_lock = self.server.channels.write().await;
-                        if let Some(chan) = chans_lock.get_mut(&privmsg.channel) {
-                            chan.nicks.insert(privmsg.nick.clone());
-                        }
-                        drop(chans_lock);
+                    // Add the nickname to the list of nicks on the channel, if it's a channel.
+                    let mut chans_lock = self.server.channels.write().await;
+                    if let Some(chan) = chans_lock.get_mut(&privmsg.channel) {
+                        chan.nicks.insert(privmsg.nick.clone());
+                    }
+                    drop(chans_lock);
 
-                        // Handle message lines individually
-                        for line in privmsg.msg.lines() {
-                            // Skip empty lines
-                            if line.is_empty() {
-                                continue
-                            }
+                    // Handle message lines individually
+                    for line in privmsg.msg.lines() {
+                        // Skip empty lines
+                        if line.is_empty() {
+                            continue
+                        }
 
-                            // Format the message
-                            let msg = format!("PRIVMSG {} :{}", privmsg.channel, line);
+                        // Format the message
+                        let msg = format!("PRIVMSG {} :{}", privmsg.channel, line);
 
-                            // Send it to the client
-                            let reply = ReplyType::Client((privmsg.nick.clone(), msg));
-                            if let Err(e) = self.reply(&mut writer, &reply).await {
-                                error!("[IRC CLIENT] Failed writing PRIVMSG to client: {}", e);
-                                continue
-                            }
+                        // Send it to the client
+                        let reply = ReplyType::Client((privmsg.nick.clone(), msg));
+                        if let Err(e) = self.reply(&mut writer, &reply).await {
+                            error!("[IRC CLIENT] Failed writing PRIVMSG to client: {}", e);
+                            continue
                         }
+                    }
 
-                        // Mark the message as seen for this USER
-                        if let Err(e) = self.mark_seen(&event_id).await {
-                            error!("[IRC CLIENT] (multiplex_connection) self.mark_seen({}) failed: {}", event_id, e);
-                            return Err(e)
-                        }
+                    // Mark the message as seen for this USER
+                    if let Err(e) = self.mark_seen(&event_id).await {
+                        error!("[IRC CLIENT] (multiplex_connection) self.mark_seen({}) failed: {}", event_id, e);
+                        return Err(e)
                     }
                 }
             }