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_im.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'irc_im.c') 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