diff options
author | June McEnroe <june@causal.agency> | 2022-08-02 20:46:25 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2022-08-02 20:46:25 -0400 |
commit | adfd1d2d8de2798501c7cec248e6b59b9cba362a (patch) | |
tree | 41694550fe655d4c633e590bd988ecbd3bc57691 | |
parent | Move cache color to an Entry struct (diff) | |
download | catgirl-adfd1d2d8de2798501c7cec248e6b59b9cba362a.tar.gz catgirl-adfd1d2d8de2798501c7cec248e6b59b9cba362a.zip |
Track prefix bits
-rw-r--r-- | chat.h | 1 | ||||
-rw-r--r-- | handle.c | 16 |
2 files changed, 17 insertions, 0 deletions
diff --git a/chat.h b/chat.h index aa2e6ab..628d416 100644 --- a/chat.h +++ b/chat.h @@ -398,6 +398,7 @@ int bufferReflow( struct Entry { enum Color color; + uint prefixBits; }; struct Cursor { uint gen; diff --git a/handle.c b/handle.c index 4b5ff7f..f5e4f32 100644 --- a/handle.c +++ b/handle.c @@ -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) { require(msg, false, 4); uint id = idFor(msg->params[2]); @@ -571,8 +577,13 @@ static void handleReplyNames(struct Message *msg) { char *nick = &prefixes[strspn(prefixes, network.prefixes)]; char *user = strsep(&name, "@"); 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); if (user) entry->color = color; + entry->prefixBits = bits; if (!replies[ReplyNames] && !replies[ReplyNamesAuto]) continue; ptr = seprintf( 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[ strchr(network.prefixModes, *ch) - network.prefixModes ]; + if (set) { + cacheInsert(false, id, nick)->prefixBits |= prefixBit(prefix); + } else { + cacheInsert(false, id, nick)->prefixBits &= ~prefixBit(prefix); + } uiFormat( id, Cold, tagTime(msg), "\3%02d%s\3\t%s \3%02d%c%s\3 %s%s in \3%02d%s\3", |