use join() instead of looping over the Vec
This commit is contained in:
parent
304f800b4d
commit
772c84d7d5
12
src/main.rs
12
src/main.rs
|
@ -81,20 +81,14 @@ async fn connection_handler(
|
|||
break;
|
||||
}
|
||||
if buf.starts_with("MSG") {
|
||||
let mut msg_send = String::new();
|
||||
let mut msg = buf.split_whitespace().collect::<Vec<&str>>();
|
||||
|
||||
if msg.len() < 2 {
|
||||
cm_sender.send(ClientMessage::ERR(format!("Can't send empty messages")))?;
|
||||
} else {
|
||||
msg.remove(0);
|
||||
for w in msg {
|
||||
msg_send.push_str(w);
|
||||
msg_send.push_str(" ");
|
||||
}
|
||||
|
||||
msg_send.push_str("\n");
|
||||
br_sender.send(BroadcastMessage::MSG(nick.clone(), msg_send, id.clone()))?;
|
||||
br_sender.send(BroadcastMessage::MSG(nick.clone(), msg.join(" "), id.clone()))?;
|
||||
}
|
||||
} else if buf.starts_with("NICK") {
|
||||
let old_nick = nick.clone();
|
||||
|
@ -132,7 +126,7 @@ async fn connection_handler(
|
|||
BroadcastMessage::MSG(nick, msg, sender) => {
|
||||
if sender != id {
|
||||
tracing::info!("{}: {:?}", nick, msg);
|
||||
tx.write_all(format!("{} MSG {}", nick, msg).as_bytes()).await?;
|
||||
tx.write_all(format!("{} MSG {}\n", nick, msg).as_bytes()).await?;
|
||||
}
|
||||
},
|
||||
BroadcastMessage::NICK(old_nick, new_nick, sender) => {
|
||||
|
@ -143,13 +137,11 @@ async fn connection_handler(
|
|||
},
|
||||
BroadcastMessage::JOIN(sender) => {
|
||||
if sender != nick {
|
||||
tracing::info!("{} joined", sender);
|
||||
tx.write_all(format!("JOIN {}\n", sender).as_bytes()).await?;
|
||||
}
|
||||
},
|
||||
BroadcastMessage::LEAVE(sender) => {
|
||||
if sender != nick {
|
||||
tracing::info!("{} joined", sender);
|
||||
tx.write_all(format!("LEAVE {}\n", sender).as_bytes()).await?;
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue