From 24e3cb62bc6c85ea01bddee1e5e5b6907ff158a2 Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Mon, 29 Jul 2019 19:42:15 +0200 Subject: [PATCH] add preliminary timeformat to chat windows --- libdc/include/dc/message.h | 2 ++ libdc/src/message.c | 6 ++++++ ncdc/src/textview.c | 9 ++++++++- todo.org | 4 ++-- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libdc/include/dc/message.h b/libdc/include/dc/message.h index c792443..1dcbaf2 100644 --- a/libdc/include/dc/message.h +++ b/libdc/include/dc/message.h @@ -21,6 +21,7 @@ #include #include +#include #include @@ -37,6 +38,7 @@ char const *dc_message_channel_id(dc_message_t m); char const *dc_message_timestamp(dc_message_t m); char const *dc_message_content(dc_message_t m); dc_account_t dc_message_author(dc_message_t m); +time_t dc_message_unix_timestamp(dc_message_t m); int dc_message_compare(dc_message_t *a, dc_message_t *b); diff --git a/libdc/src/message.c b/libdc/src/message.c index 6203884..73428c9 100644 --- a/libdc/src/message.c +++ b/libdc/src/message.c @@ -153,6 +153,12 @@ static void dc_message_parse_timestamp(dc_message_t m) m->ts = timegm(&t); } +time_t dc_message_unix_timestamp(dc_message_t m) +{ + return_if_true(m == NULL, 0); + return m->ts; +} + int dc_message_compare(dc_message_t *a, dc_message_t *b) { return_if_true(a == NULL || *a == NULL || diff --git a/ncdc/src/textview.c b/ncdc/src/textview.c index 0d96d31..d245680 100644 --- a/ncdc/src/textview.c +++ b/ncdc/src/textview.c @@ -183,10 +183,13 @@ ncdc_textview_render_par(ncdc_textview_t v, WINDOW *win, int lines, int cols) static wchar_t *ncdc_textview_format(dc_message_t m) { wchar_t *c = NULL, *author = NULL, *message = NULL; + wchar_t timestamp[100] = {0}; size_t clen = 0; FILE *f = open_wmemstream(&c, &clen); wchar_t *ret = NULL; dc_account_t a = dc_message_author(m); + struct tm *tm = NULL; + time_t uts = 0; return_if_true(f == NULL, NULL); @@ -196,7 +199,11 @@ static wchar_t *ncdc_textview_format(dc_message_t m) message = s_convert(dc_message_content(m)); goto_if_true(message == NULL, cleanup); - fwprintf(f, L"< %ls> %ls", author, message); + uts = dc_message_unix_timestamp(m); + tm = gmtime(&uts); + wcsftime(timestamp, 99, L"%F/%H:%M", tm); + + fwprintf(f, L"%ls < %ls> %ls", timestamp, author, message); fclose(f); f = NULL; diff --git a/todo.org b/todo.org index 725a5bd..703a7bd 100644 --- a/todo.org +++ b/todo.org @@ -1,9 +1,9 @@ * General ** TODO move key handling away from the thread the event_loop thread -* Channels [3/4] +* Channels [4/4] ** DONE Automatically open window for 1:1 and 1:N ** DONE send v6/api/channels/$ID/ack for "I read that shit" -** TODO add timestamps from messages +** DONE add timestamps from messages ** DONE add message sending * Guilds [2/3] ** DONE Guild support code