mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-24 16:28:05 -05:00
Detect highlights
This commit is contained in:
parent
ed6dccbb58
commit
abece1e3fd
4 changed files with 55 additions and 1 deletions
|
@ -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);
|
||||
|
|
44
lib/irc.js
44
lib/irc.js
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
2
state.js
2
state.js
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue