Skip to content

Commit

Permalink
Only highlight if user nick isn't part of another word
Browse files Browse the repository at this point in the history
  • Loading branch information
casperstorm committed Sep 25, 2024
1 parent fd2efb1 commit ca4516c
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions data/src/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1061,11 +1061,16 @@ fn monitored_targets_text(targets: Vec<String>) -> Option<String> {
}

pub fn reference_user(sender: NickRef, own_nick: NickRef, message: &Message) -> bool {
let contains_nick = |text: &str, nick: &str| {
text.split(|c: char| !c.is_alphanumeric())
.any(|word| word == nick)
};

let has_nick = match &message.content {
Content::Plain(text) => text.contains(own_nick.as_ref()),
Content::Plain(text) => contains_nick(text, own_nick.as_ref()),
Content::Fragments(fragments) => fragments
.iter()
.any(|f| f.as_str().contains(own_nick.as_ref())),
.any(|f| contains_nick(f.as_str(), own_nick.as_ref())),
};

sender != own_nick && has_nick
Expand Down

0 comments on commit ca4516c

Please sign in to comment.