Skip to content

Commit

Permalink
Improve group_joins interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
andymandias committed Apr 23, 2024
1 parent e5fb7c0 commit cc87a04
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions data/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,10 @@ impl Client {
log::info!("[{}] logged in", self.server);

if !self.registration_required_channels.is_empty() {
for message in group_joins(&self.config, &self.registration_required_channels) {
for message in group_joins(
&self.registration_required_channels,
&self.config.channel_keys,
) {
let _ = self.handle.try_send(message);
}

Expand Down Expand Up @@ -616,7 +619,7 @@ impl Client {
}

// Send JOIN
for message in group_joins(&self.config, &self.config.channels) {
for message in group_joins(&self.config.channels, &self.config.channel_keys) {
let _ = self.handle.try_send(message);
}
}
Expand Down Expand Up @@ -1202,15 +1205,13 @@ pub enum WhoStatus {

/// Group channels together into as few JOIN messages as possible
fn group_joins<'a>(
config: &'a config::Server,
channels: &'a [String],
keys: &'a HashMap<String, String>,
) -> impl Iterator<Item = proto::Message> + 'a {
const MAX_LEN: usize = proto::format::BYTE_LIMIT - b"JOIN \r\n".len();

let (without_keys, with_keys): (Vec<_>, Vec<_>) = channels.iter().partition_map(|channel| {
config
.channel_keys
.get(channel)
keys.get(channel)
.map(|key| Either::Right((channel, key)))
.unwrap_or(Either::Left(channel))
});
Expand Down

0 comments on commit cc87a04

Please sign in to comment.