Skip to content

Commit 5b7ff22

Browse files
committed
Simplify mentions
1 parent 2af70c7 commit 5b7ff22

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/components/Chat.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,12 @@ const useStyles = makeStyles((theme) => ({
8484

8585
const makeMentionRE = (username) => {
8686
username = username.toLowerCase().replace(/[\\^$.*+?()[\]{}|]/g, "\\$&");
87-
var anon = "";
88-
const anonIdx = username.indexOf("anonymous ");
89-
if (anonIdx !== -1) {
90-
anon = `(${username.slice(0, anonIdx + 10)})?`;
91-
username = username.slice(anonIdx + 10);
92-
}
93-
const parts = username.split(/\s+/).filter((s) => s);
94-
return new RegExp(`(\\W|^)@(all|${anon}(${parts.join("|")}))(\\W|$)`, "iu");
87+
username = username.replace(
88+
/(?<!(^|\W)anonymous)\s(?!(.*\W)?anonymous).*$/,
89+
""
90+
);
91+
username = username.replace(/^(.*\W)?anonymous /, "($&)?");
92+
return new RegExp(`(\\W|^)@(all|${username})(\\W|$)`, "iu");
9593
};
9694

9795
const emojiRE = /:([a-z0-9_+-]+):/g;

0 commit comments

Comments
 (0)