hirc

IRC client
Log | Files | Refs

commit 9c6dcccf309f9773d9df54c5355ee413c8f11789
parent 983644d22ecffbe26f5c9aaf146546d59b335c40
Author: hhvn <dev@hhvn.uk>
Date:   Sun,  6 Mar 2022 11:55:42 +0000

Track and display priviledges in channel messages

Diffstat:
Msrc/config.c | 4++--
Msrc/handle.c | 2+-
Msrc/hirc.h | 2+-
Msrc/hist.c | 41+++++++++++++++++++++++++++++------------
Msrc/ui.c | 12+++++++++++-
5 files changed, 44 insertions(+), 17 deletions(-)

diff --git a/src/config.c b/src/config.c @@ -408,7 +408,7 @@ struct Config config[] = { .description = { "Used for horizontal line separating input and main window", NULL}}, {"format.privmsg", 1, Val_string, - .str = "%{nick:${nick}}${nick}%{o}%{=}${2}", + .str = "%{nick:${nick}}${priv}${nick}%{o}%{=}${2}", .strhandle = config_redraws, .description = { "Format of messages", NULL}}, @@ -428,7 +428,7 @@ struct Config config[] = { .description = { "Format of CTCP answers", NULL}}, {"format.notice", 1, Val_string, - .str = "%{nick:${nick}}-${nick}-%{o}%{=}${2}", + .str = "%{nick:${nick}}-${priv}${nick}-%{o}%{=}${2}", .strhandle = config_redraws, .description = { "Format of notices", NULL}}, diff --git a/src/handle.c b/src/handle.c @@ -624,6 +624,6 @@ handle(struct Server *server, char *msg) { } /* add it to server->history if there is no handler */ - hist_add(server->history, NULL, msg, Activity_status, timestamp, HIST_DFL); + hist_add(server->history, msg, Activity_status, timestamp, HIST_DFL); param_free(params); } diff --git a/src/hirc.h b/src/hirc.h @@ -89,7 +89,7 @@ struct History *hist_create(struct HistInfo *histinfo, struct Nick *from, char * struct History *hist_addp(struct HistInfo *histinfo, struct History *p, enum Activity activity, enum HistOpt options); struct History *hist_add(struct HistInfo *histinfo, - struct Nick *from, char *msg, enum Activity activity, + char *msg, enum Activity activity, time_t timestamp, enum HistOpt options); struct History *hist_format(struct HistInfo *history, enum Activity activity, enum HistOpt options, char *format, ...); diff --git a/src/hist.c b/src/hist.c @@ -56,6 +56,8 @@ struct History * hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, enum Activity activity, time_t timestamp, enum HistOpt options) { struct History *new; + struct Nick *np; + char *nick; new = emalloc(sizeof(struct History)); new->prev = new->next = NULL; @@ -67,12 +69,22 @@ hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, new->options = options; new->origin = histinfo; - if (from) + if (from) { new->from = nick_dup(from, histinfo->server); - else if (**new->_params == ':') - new->from = nick_create(*new->_params, ' ', histinfo->server); - else + } else if (**new->_params == ':') { + np = NULL; + if (histinfo->channel) { + prefix_tokenize(*new->_params, &nick, NULL, NULL); + np = nick_get(&histinfo->channel->nicks, nick); + } + + if (np) + new->from = nick_dup(np, histinfo->server); + else + new->from = nick_create(*new->_params, ' ', histinfo->server); + } else { new->from = NULL; + } if (**new->_params == ':') new->params++; @@ -82,30 +94,35 @@ hist_create(struct HistInfo *histinfo, struct Nick *from, char *msg, struct History * hist_addp(struct HistInfo *histinfo, struct History *p, enum Activity activity, enum HistOpt options) { - return hist_add(histinfo, p->from, p->raw, activity, p->timestamp, options); + return hist_add(histinfo, p->raw, activity, p->timestamp, options); } struct History * -hist_add(struct HistInfo *histinfo, struct Nick *from, - char *msg, enum Activity activity, +hist_add(struct HistInfo *histinfo, + char *msg, enum Activity activity, time_t timestamp, enum HistOpt options) { + struct Nick *from = NULL; struct History *new, *p; int i; if (options & HIST_MAIN) { if (options & HIST_TMP && histinfo == main_buf) { - hist_add(main_buf, from, msg, activity, timestamp, HIST_SHOW); + hist_add(main_buf, msg, activity, timestamp, HIST_SHOW); new = NULL; goto ui; } else if (histinfo != main_buf) { - hist_add(main_buf, from, msg, activity, timestamp, HIST_SHOW); + hist_add(main_buf, msg, activity, timestamp, HIST_SHOW); } else { ui_error("HIST_MAIN specified, but history is &main_buf", NULL); } } - if (options & HIST_SELF && histinfo->server) - from = histinfo->server->self; + if (options & HIST_SELF && histinfo->server) { + if (histinfo->channel && histinfo->channel->nicks) + from = nick_get(&histinfo->channel->nicks, histinfo->server->self->nick); + if (!from) + from = histinfo->server->self; + } new = hist_create(histinfo, from, msg, activity, timestamp, options); @@ -189,7 +206,7 @@ hist_format(struct HistInfo *histinfo, enum Activity activity, enum HistOpt opti params = param_create(msg); - return hist_add(histinfo, NULL, msg, Activity_status, 0, options); + return hist_add(histinfo, msg, Activity_status, 0, options); } int diff --git a/src/ui.c b/src/ui.c @@ -1231,6 +1231,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { char *content, *p, *p2; char *ts, *save; char colourbuf[2][3]; + char priv[2]; char chs[2]; size_t len; enum { @@ -1239,6 +1240,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { sub_nick, sub_ident, sub_host, + sub_priv, sub_channel, sub_topic, sub_server, @@ -1253,6 +1255,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { [sub_nick] = {"nick", NULL}, [sub_ident] = {"ident", NULL}, [sub_host] = {"host", NULL}, + [sub_priv] = {"priv", NULL}, [sub_channel] = {"channel", NULL}, [sub_topic] = {"topic", NULL}, [sub_server] = {"server", NULL}, @@ -1272,6 +1275,12 @@ ui_format(struct Window *window, char *format, struct History *hist) { subs[sub_ident].val = hist->from ? hist->from->ident : NULL; subs[sub_host].val = hist->from ? hist->from->host : NULL; + if (hist->from) { + priv[0] = hist->from->priv; + priv[1] = '\0'; + subs[sub_priv].val = priv; + } + if (hist->origin) { if (hist->origin->channel) { if (!recursive) @@ -1303,6 +1312,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { } for (escape = 0, rc = 0; format && *format && rc < sizeof(ret); ) { +outcont: if (!escape && *format == '$' && *(format+1) == '{' && strchr(format, '}')) { escape = 0; content = ui_format_get_content(format+2, 0); @@ -1350,7 +1360,7 @@ ui_format(struct Window *window, char *format, struct History *hist) { if (subs[i].val) rc += snprintf(&ret[rc], sizeof(ret) - rc, "%s", subs[i].val); format = strchr(format, '}') + 1; - continue; + goto outcont; /* unfortunately, need to use a goto as we are already in a loop */ } } }