Skip to content

Commit

Permalink
feat: don't highlight mentions in links
Browse files Browse the repository at this point in the history
  • Loading branch information
vyneer committed Jan 14, 2024
1 parent 91f4264 commit 49128de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions assets/chat/js/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import makeSafeForRegex, {
nickregex,
nsfwregex,
nsflregex,
linkregex,
} from './regex';

import { HashLinkConverter, MISSING_ARG_ERROR } from './hashlinkconverter';
Expand Down Expand Up @@ -2345,7 +2346,7 @@ class Chat {
// Check current user nick against msg.message (if highlight setting is on)
((this.regexhighlightself &&
this.settings.get('highlight') &&
this.regexhighlightself.test(message.message)) ||
this.regexhighlightself.test(message.message.replace(linkregex, ''))) ||
// Check /highlight nicks against msg.nick
(this.regexhighlightnicks &&
this.regexhighlightnicks.test(message.user.username)) ||
Expand Down Expand Up @@ -2374,7 +2375,9 @@ class Chat {
}

extractNicks(text) {
const uniqueNicks = new Set(text.match(nickmessageregex));
const uniqueNicks = new Set(
text.replace(linkregex, '').match(nickmessageregex),
);
return [...uniqueNicks];
}

Expand Down
4 changes: 4 additions & 0 deletions assets/chat/js/regex.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import { UrlFormatter } from './formatters';

const regexslashcmd = /^\/([a-z0-9]+)[\s]?/i;
const regextime =
/(?<number>\d+)(?<unit>s(econds?)?$|m(inutes?)?$|h(ours?)?$|d(ays?)?$)?/i;
const nickmessageregex = /(?=@?)(\w{3,20})/g;
const nickregex = /^\w{3,20}$/;
const nsfwregex = /\bNSFW\b/i;
const nsflregex = /\bNSFL\b/i;
const { linkregex } = new UrlFormatter();

export {
regexslashcmd,
Expand All @@ -13,6 +16,7 @@ export {
nickregex,
nsfwregex,
nsflregex,
linkregex,
};

export default function makeSafeForRegex(str) {
Expand Down

0 comments on commit 49128de

Please sign in to comment.