From 576c3ff590db1861d6458483cbaf33cd84857160 Mon Sep 17 00:00:00 2001 From: Marius Halden Date: Mon, 21 Mar 2016 13:55:32 +0100 Subject: Add server-time capability --- irc.h | 1 + irc_cap.c | 1 + irc_im.c | 26 +++++++++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/irc.h b/irc.h index 5b7ad757..bc184216 100644 --- a/irc.h +++ b/irc.h @@ -73,6 +73,7 @@ typedef enum { CAP_EXTENDED_JOIN = (1 << 2), CAP_AWAY_NOTIFY = (1 << 3), CAP_USERHOST_IN_NAMES = (1 << 4), + CAP_SERVER_TIME = (1 << 5), } irc_cap_flag_t; struct irc_user; diff --git a/irc_cap.c b/irc_cap.c index af1215e0..79f39256 100644 --- a/irc_cap.c +++ b/irc_cap.c @@ -42,6 +42,7 @@ static const cap_info_t supported_caps[] = { {"extended-join", CAP_EXTENDED_JOIN}, {"away-notify", CAP_AWAY_NOTIFY}, {"userhost-in-names", CAP_USERHOST_IN_NAMES}, + {"server-time", CAP_SERVER_TIME}, {NULL}, }; diff --git a/irc_im.c b/irc_im.c index c6de8684..64c45f51 100644 --- a/irc_im.c +++ b/irc_im.c @@ -225,9 +225,16 @@ static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, g char *wrapped, *ts = NULL; char *msg = g_strdup(msg_); char *message_type = "PRIVMSG"; + char *tags = NULL; GSList *l; - - if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) { + struct tm msg_time; + + if (sent_at > 0 && (irc->caps & CAP_SERVER_TIME)) { + gmtime_r(&sent_at, &msg_time); + tags = g_strdup_printf("time=%04d-%02d-%02dT%02d:%02d:%02d.000Z", + msg_time.tm_year + 1900, msg_time.tm_mon + 1, msg_time.tm_mday, + msg_time.tm_hour, msg_time.tm_min, msg_time.tm_sec); + } else if (sent_at > 0 && set_getbool(&irc->b->set, "display_timestamps")) { ts = irc_format_timestamp(irc, sent_at); } @@ -300,13 +307,14 @@ static gboolean bee_irc_user_msg(bee_t *bee, bee_user_t *bu, const char *msg_, g } wrapped = word_wrap(msg, IRC_WORD_WRAP); - irc_send_msg(src_iu, message_type, dst, wrapped, prefix); + irc_send_tagged_msg(src_iu, message_type, dst, wrapped, prefix, tags); g_free(wrapped); cleanup: g_free(prefix); g_free(msg); g_free(ts); + g_free(tags); return TRUE; } @@ -660,19 +668,27 @@ static gboolean bee_irc_chat_msg(bee_t *bee, struct groupchat *c, bee_user_t *bu irc_user_t *iu = flags & OPT_SELFMESSAGE ? irc->user : bu->ui_data; irc_channel_t *ic = c->ui_data; char *wrapped, *ts = NULL; + char *tags = NULL; + struct tm msg_time; if (ic == NULL) { return FALSE; } - if (sent_at > 0 && set_getbool(&bee->set, "display_timestamps")) { + if (sent_at > 0 && (irc->caps & CAP_SERVER_TIME)) { + gmtime_r(&sent_at, &msg_time); + tags = g_strdup_printf("time=%04d-%02d-%02dT%02d:%02d:%02d.000Z", + msg_time.tm_year + 1900, msg_time.tm_mon + 1, msg_time.tm_mday, + msg_time.tm_hour, msg_time.tm_min, msg_time.tm_sec); + } else if (sent_at > 0 && set_getbool(&bee->set, "display_timestamps")) { ts = irc_format_timestamp(irc, sent_at); } wrapped = word_wrap(msg, IRC_WORD_WRAP); - irc_send_msg(iu, "PRIVMSG", ic->name, wrapped, ts); + irc_send_tagged_msg(iu, "PRIVMSG", ic->name, wrapped, ts, tags); g_free(ts); g_free(wrapped); + g_free(tags); return TRUE; } -- cgit v1.2.3