Properly remove users from channels on quit

This commit is contained in:
TheMightyBuzzard 2017-06-05 16:02:00 -05:00
parent d03d61dcec
commit c6efd4d9f0

View file

@ -10,7 +10,7 @@ use std::thread::{spawn, sleep};
use std::time::Duration as StdDuration;
use client::conn::{Connection, NetConnection};
use client::data::{Command, Config, Message, Response, User};
use client::data::Command::{JOIN, NICK, NICKSERV, PART, PING, PONG, PRIVMSG, MODE};
use client::data::Command::{JOIN, NICK, NICKSERV, PART, PING, PONG, PRIVMSG, MODE, QUIT};
use client::server::utils::ServerExt;
use time::{Duration, Timespec, Tm, now};
@ -369,6 +369,7 @@ impl IrcServer {
PONG(ref pingdata, None) => self.state.check_pong(&pingdata),
JOIN(ref chan, _, _) => self.handle_join(msg.source_nickname().unwrap_or(""), chan),
PART(ref chan, _) => self.handle_part(msg.source_nickname().unwrap_or(""), chan),
QUIT(_) => self.handle_quit(msg.source_nickname().unwrap_or("")),
NICK(ref new_nick) => self.handle_nick_change(msg.source_nickname().unwrap_or(""), new_nick),
MODE(ref chan, ref mode, Some(ref user)) => self.handle_mode(chan, mode, user),
PRIVMSG(ref target, ref body) => if body.starts_with('\u{001}') {
@ -475,6 +476,22 @@ impl IrcServer {
}
}
#[cfg(feature = "nochanlists")]
fn handle_quit(&self, _: &str) {}
#[cfg(not(feature = "nochanlists"))]
fn handle_quit(&self, src: &str) {
if src.is_empty() { return; }
let mut chanlists = self.chanlists().lock().unwrap();
for channel in chanlists.clone().keys() {
if let Some(vec) = chanlists.get_mut(&channel.to_owned()) {
if let Some(p) = vec.iter().position(|x| x.get_nickname() == src) {
vec.swap_remove(p);
}
}
}
}
#[cfg(feature = "nochanlists")]
fn handle_nick_change(&self, _: &str, _: &str) {}