hirc

IRC client
Log | Files | Refs

commit ea708ebb4324d16c9d4d801720214b51e7e6f7e2
parent bd399085fe51e44db44ec0f2e89bcba83929bcf8
Author: hhvn <dev@hhvn.uk>
Date:   Mon, 21 Mar 2022 19:21:37 +0000

Unread message indicator

Diffstat:
Msrc/config.c | 5+++++
Msrc/hist.c | 15++++++---------
Msrc/ui.c | 30+++++++++++++++++++++++++++++-
3 files changed, 40 insertions(+), 10 deletions(-)

diff --git a/src/config.c b/src/config.c @@ -330,6 +330,11 @@ struct Config config[] = { .strhandle = config_redraws, .description = { "Format of log restore footer.", NULL}}, + {"format.ui.unread", 1, Val_string, + .str = "%{c:93}---%{=}%{c:93}%{b}${1}%{b} unread ---", + .strhandle = config_redraws, + .description = { + "Format of unread message indicator.", NULL}}, {"format.ui.grep.start", 1, Val_string, .str = "%{b}%{c:94}Results of ${1}:", .strhandle = config_redraws, diff --git a/src/hist.c b/src/hist.c @@ -205,9 +205,10 @@ hist_format(struct HistInfo *histinfo, enum Activity activity, enum HistOpt opti vsnprintf(msg, sizeof(msg), format, ap); va_end(ap); - params = param_create(msg); - - return hist_add(histinfo, msg, Activity_status, 0, options); + if (histinfo) + return hist_add(histinfo, msg, Activity_status, 0, options); + else + return hist_create(histinfo, NULL, msg, Activity_status, 0, options); } int @@ -295,7 +296,6 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { char *prefix; size_t len; struct Nick *from; - char *format; if (!server || !hist) return NULL; @@ -369,11 +369,8 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { fclose(f); if (head) { - len = snprintf(format, 0, "SELF_LOG_RESTORE %lld :log restored up to", (long long)head->timestamp) + 1; - format = emalloc(len); - snprintf(format, len, "SELF_LOG_RESTORE %lld :log restored up to", (long long)head->timestamp); - p = hist_create(hist, NULL, format, Activity_status, time(NULL), HIST_SHOW|HIST_RLOG); - free(format); + p = hist_format(NULL, Activity_none, HIST_SHOW|HIST_RLOG, "SELF_LOG_RESTORE %lld :log restored up to", (long long)head->timestamp); + p->origin = hist; p->next = head; head->prev = p; head = p; diff --git a/src/ui.c b/src/ui.c @@ -96,6 +96,7 @@ struct { {"SELF_AUTOCMDS_LIST", "format.ui.autocmds"}, {"SELF_AUTOCMDS_END", "format.ui.autocmds.end"}, {"SELF_LOG_RESTORE", "format.ui.logrestore"}, + {"SELF_UNREAD", "format.ui.unread"}, /* Real commands/numerics from server */ {"PRIVMSG", "format.privmsg"}, {"NOTICE", "format.notice"}, @@ -1380,16 +1381,43 @@ ui_draw_main(void) { void ui_select(struct Server *server, struct Channel *channel) { + struct History *hp, *ind; + int i; + + if (selected.history) + hist_purgeopt(selected.history, HIST_TMP); + selected.channel = channel; selected.server = server; selected.history = channel ? channel->history : server ? server->history : main_buf; selected.name = channel ? channel->name : server ? server->name : "hirc"; selected.hasnicks = channel ? !channel->priv && !channel->old : 0; + if (selected.history->unread) { + for (i = 0, hp = selected.history->history; hp && hp->next; hp = hp->next, i++); + if (i == (HIST_MAX-1)) { + free(hp->next); + hp->next = NULL; + } + + for (i = 0, hp = selected.history->history; hp && hp->next && i < selected.history->unread; hp = hp->next) + if (hp->options & HIST_SHOW) + i++; + if (hp) { + ind = hist_format(NULL, Activity_none, HIST_SHOW|HIST_TMP, "SELF_UNREAD %d :unread", selected.history->unread); + ind->origin = selected.history; + ind->next = hp; + ind->prev = hp->prev; + if (hp->prev) + hp->prev->next = ind; + hp->prev = ind; + } + } + + selected.history->activity = Activity_none; selected.history->unread = 0; - hist_purgeopt(selected.history, HIST_TMP); if (!selected.hasnicks) windows[Win_nicklist].location = HIDDEN; else