Track prefix bits

weechat-hashes
June McEnroe 2022-08-02 20:46:25 -04:00
parent 93e841b29e
commit adfd1d2d8d
2 changed files with 17 additions and 0 deletions

1
chat.h
View File

@ -398,6 +398,7 @@ int bufferReflow(
struct Entry { struct Entry {
enum Color color; enum Color color;
uint prefixBits;
}; };
struct Cursor { struct Cursor {
uint gen; uint gen;

View File

@ -560,6 +560,12 @@ static void handleErrorUserOnChannel(struct Message *msg) {
); );
} }
static uint prefixBit(char p) {
char *s = strchr(network.prefixes, p);
if (!s) return 0;
return 1 << (s - network.prefixes);
}
static void handleReplyNames(struct Message *msg) { static void handleReplyNames(struct Message *msg) {
require(msg, false, 4); require(msg, false, 4);
uint id = idFor(msg->params[2]); uint id = idFor(msg->params[2]);
@ -571,8 +577,13 @@ static void handleReplyNames(struct Message *msg) {
char *nick = &prefixes[strspn(prefixes, network.prefixes)]; char *nick = &prefixes[strspn(prefixes, network.prefixes)];
char *user = strsep(&name, "@"); char *user = strsep(&name, "@");
enum Color color = (user ? hash(user) : Default); enum Color color = (user ? hash(user) : Default);
uint bits = 0;
for (char *p = prefixes; p < nick; ++p) {
bits |= prefixBit(*p);
}
struct Entry *entry = cacheInsert(false, id, nick); struct Entry *entry = cacheInsert(false, id, nick);
if (user) entry->color = color; if (user) entry->color = color;
entry->prefixBits = bits;
if (!replies[ReplyNames] && !replies[ReplyNamesAuto]) continue; if (!replies[ReplyNames] && !replies[ReplyNamesAuto]) continue;
ptr = seprintf( ptr = seprintf(
ptr, end, "%s\3%02d%s\3", (ptr > buf ? ", " : ""), color, prefixes ptr, end, "%s\3%02d%s\3", (ptr > buf ? ", " : ""), color, prefixes
@ -894,6 +905,11 @@ static void handleMode(struct Message *msg) {
char prefix = network.prefixes[ char prefix = network.prefixes[
strchr(network.prefixModes, *ch) - network.prefixModes strchr(network.prefixModes, *ch) - network.prefixModes
]; ];
if (set) {
cacheInsert(false, id, nick)->prefixBits |= prefixBit(prefix);
} else {
cacheInsert(false, id, nick)->prefixBits &= ~prefixBit(prefix);
}
uiFormat( uiFormat(
id, Cold, tagTime(msg), id, Cold, tagTime(msg),
"\3%02d%s\3\t%s \3%02d%c%s\3 %s%s in \3%02d%s\3", "\3%02d%s\3\t%s \3%02d%c%s\3 %s%s in \3%02d%s\3",