hirc

IRC client
Log | Files | Refs

commit d63af8754621da0e328d0cd84a43db37ad57c544
parent 0cdf7515f9ea0f56d622a7d68cd4b49e7719c4fd
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 23 Apr 2022 15:35:47 +0100

Use time of disconnect for SELF_LOG_RESTORE

Diffstat:
Msrc/hist.c | 6+++++-
Msrc/serv.c | 8+++++++-
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/hist.c b/src/hist.c @@ -331,6 +331,7 @@ hist_log(struct History *hist) { struct History * hist_loadlog(struct HistInfo *hist, char *server, char *channel) { struct History *head = NULL, *p, *prev; + struct stat st; char filename[2048]; char *logdir; FILE *f; @@ -360,6 +361,9 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { else snprintf(filename, sizeof(filename), "%s/%s.log", logdir, server); + if (stat(filename, &st) == -1) + return NULL; + if (!(f = fopen(filename, "rb"))) return NULL; @@ -428,7 +432,7 @@ hist_loadlog(struct HistInfo *hist, char *server, char *channel) { fclose(f); if (head) { - p = hist_format(NULL, Activity_none, HIST_SHOW|HIST_RLOG, "SELF_LOG_RESTORE %lld :log restored up to", (long long)head->timestamp); + p = hist_format(NULL, Activity_none, HIST_SHOW|HIST_RLOG, "SELF_LOG_RESTORE %lld :log restored up to", (long long)st.st_mtime); p->origin = hist; p->next = head; head->prev = p; diff --git a/src/serv.c b/src/serv.c @@ -514,8 +514,14 @@ serv_disconnect(struct Server *server, int reconnect, char *msg) { server->lastconnected = time(NULL); server->reconnect = reconnect; - for (chan = server->channels; chan; chan = chan->next) + /* Create a history item for disconnect: + * - shows up in the log + * - updates the file's mtime, so hist_laodlog knows when we disconnected */ + hist_format(server->history, Activity_none, HIST_LOG, "SELF_DISCONNECT"); + for (chan = server->channels; chan; chan = chan->next) { chan_setold(chan, 1); + hist_format(chan->history, Activity_none, HIST_LOG, "SELF_DISCONNECT"); + } windows[Win_buflist].refresh = 1; }