Skip to content

Commit

Permalink
Review
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm committed Sep 9, 2024
1 parent 3645172 commit 07c940a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
14 changes: 5 additions & 9 deletions data/src/config/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,29 +84,25 @@ impl Default for ServerMessage {
}

impl ServerMessage {
pub fn should_send_message(&self, channel: Option<&str>) -> bool {
pub fn should_send_message(&self, channel: &str) -> bool {
// Server Message is not enabled.
if !self.enabled {
return false;
}

let is_channel_filtered = |list: &Vec<String>, channel: Option<&str>| -> bool {
let is_channel_filtered = |list: &Vec<String>, channel: &str| -> bool {
let wildcards = ["*", "all"];
channel.map_or(false, |channel| {

list.iter()
.any(|item| wildcards.contains(&item.as_str()) || item == channel)
})

};

let channel_included = is_channel_filtered(&self.include, channel);
let channel_excluded = is_channel_filtered(&self.exclude, channel);

// If the channel is included, it has precedence over excluded.
if channel_included || !channel_excluded {
return true;
}

false
channel_included || !channel_excluded
}
}

Expand Down
12 changes: 5 additions & 7 deletions data/src/history/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,11 @@ impl Data {
.filter(|message| match message.target.source() {
message::Source::Server(Some(source)) => {
if let Some(server_message) = buffer_config.server_messages.get(source) {
let channel = match &message.target {
message::Target::Channel { channel, .. } => Some(channel.as_ref()),
_ => None,
};

if !server_message.should_send_message(channel) {
return false;
// Check if target is a channel, and if included/excluded.
if let message::Target::Channel { channel, .. } = &message.target {
if !server_message.should_send_message(channel.as_ref()) {
return false;
}
}

if let Some(seconds) = server_message.smart {
Expand Down

0 comments on commit 07c940a

Please sign in to comment.