Detect highlights

This commit is contained in:
Simon Ser 2020-06-29 11:08:47 +02:00
parent ed6dccbb58
commit abece1e3fd
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 55 additions and 1 deletions

View file

@ -168,8 +168,13 @@ export default class App extends Component {
var msgUnread = Unread.NONE;
if (msg.command == "PRIVMSG" || msg.command == "NOTICE") {
var text = msg.params[1];
if (msg.prefix.name != this.client.nick && irc.isHighlight(text, this.client.nick)) {
msgUnread = Unread.HIGHLIGHT;
} else {
msgUnread = Unread.MESSAGE;
}
}
if (msg.prefix.name != this.client.nick && msg.command != "PART") {
this.createBuffer(bufName);

View file

@ -196,3 +196,47 @@ export function parseMembership(s) {
nick: s.slice(i),
};
}
const alphaNum = (() => {
try {
return new RegExp(/^\p{L}$/, "u");
} catch (e) {
return new RegExp(/^[a-zA-Z0-9]$/, "u");
}
})();
function isWordBoundary(ch) {
switch (ch) {
case "-":
case "_":
case "|":
return false;
case "\u00A0":
return true;
default:
return !alphaNum.test(ch);
}
}
export function isHighlight(text, nick) {
while (true) {
var i = text.indexOf(nick);
if (i < 0) {
return false;
}
// Detect word boundaries
var left = "\x00", right = "\x00";
if (i > 0) {
left = text[i - 1];
}
if (i < text.length) {
right = text[i + nick.length];
}
if (isWordBoundary(left) && isWordBoundary(right)) {
return true;
}
text = text.slice(i + nick.length);
}
}

View file

@ -13,11 +13,13 @@ export const Status = {
export const Unread = {
NONE: "",
MESSAGE: "message",
HIGHLIGHT: "highlight",
union: (a, b) => {
const priority = {
[Unread.None]: 0,
[Unread.MESSAGE]: 1,
[Unread.HIGHLIGHT]: 2,
};
return (priority[a] > priority[b]) ? a : b;
},

View file

@ -46,6 +46,9 @@ body {
#buffer-list li.unread-message a {
color: #b37400;
}
#buffer-list li.unread-highlight a {
color: #22009b;
}
#buffer-list .actions {
flex-shrink: 0;
text-align: center;