Key chatter buckets by lowercase channel
This commit is contained in:
parent
dc148dde69
commit
d6e74dd7c7
1 changed files with 10 additions and 10 deletions
|
|
@ -171,24 +171,24 @@ impl Engine {
|
||||||
|
|
||||||
// Get (or lazily create) a speaker's counters in a channel. get_mut avoids
|
// Get (or lazily create) a speaker's counters in a channel. get_mut avoids
|
||||||
// any allocation for a channel/user already being tracked.
|
// any allocation for a channel/user already being tracked.
|
||||||
|
// Keyed by lowercase channel so insert (here) and removal (forget_chatter)
|
||||||
|
// always match, even if the ircd ever varies the channel's case.
|
||||||
fn chatter_entry(&mut self, channel: &str, from: &str) -> &mut ChatterState {
|
fn chatter_entry(&mut self, channel: &str, from: &str) -> &mut ChatterState {
|
||||||
if !self.chatter.contains_key(channel) {
|
self.chatter
|
||||||
self.chatter.insert(channel.to_string(), HashMap::new());
|
.entry(channel.to_ascii_lowercase())
|
||||||
}
|
.or_default()
|
||||||
let bucket = self.chatter.get_mut(channel).unwrap();
|
.entry(from.to_string())
|
||||||
if !bucket.contains_key(from) {
|
.or_default()
|
||||||
bucket.insert(from.to_string(), ChatterState::default());
|
|
||||||
}
|
|
||||||
bucket.get_mut(from).unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drop a user's chatter counters for a channel (on part), and the channel's
|
// Drop a user's chatter counters for a channel (on part), and the channel's
|
||||||
// bucket once empty, so kicker state never outlives the people it tracks.
|
// bucket once empty, so kicker state never outlives the people it tracks.
|
||||||
pub(crate) fn forget_chatter(&mut self, channel: &str, uid: &str) {
|
pub(crate) fn forget_chatter(&mut self, channel: &str, uid: &str) {
|
||||||
if let Some(bucket) = self.chatter.get_mut(channel) {
|
let channel = channel.to_ascii_lowercase();
|
||||||
|
if let Some(bucket) = self.chatter.get_mut(&channel) {
|
||||||
bucket.remove(uid);
|
bucket.remove(uid);
|
||||||
if bucket.is_empty() {
|
if bucket.is_empty() {
|
||||||
self.chatter.remove(channel);
|
self.chatter.remove(&channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue