From 873736df5c9e29ff286fce86d4ad1193e94c9bc4 Mon Sep 17 00:00:00 2001 From: Sean Qureshi Date: Fri, 2 Aug 2013 16:44:32 -0700 Subject: [PATCH] Adds timestamp to toxic, fixes issue #217 --- chat.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/chat.c b/chat.c index 854d381..10837aa 100644 --- a/chat.c +++ b/chat.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "../../core/Messenger.h" #include "../../core/network.h" @@ -26,11 +27,15 @@ typedef struct { extern void fix_name(uint8_t* name); - static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { ChatContext* ctx = (ChatContext*) self->x; uint8_t nick[MAX_NAME_LENGTH] = {0}; + time_t now; + time(&now); + struct tm * timeinfo; + timeinfo = localtime(&now); + if(ctx->friendnum != num) return; @@ -42,10 +47,21 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) fix_name(msg); fix_name(nick); + int inthour = timeinfo->tm_hour; + int intmin = timeinfo->tm_min; + char min[2]; + char hour[2]; + sprintf(hour,"%d",inthour); + sprintf(min,"%d",intmin); + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); + wprintw(ctx->history,":%s ",min); + wattron(ctx->history, COLOR_PAIR(4)); + wprintw(ctx->history, "%s: ", now); wattron(ctx->history, COLOR_PAIR(4)); wprintw(ctx->history, "%s: ", nick); wattroff(ctx->history, COLOR_PAIR(4)); - wprintw(ctx->history, "%s\n", msg); self->blink = true; @@ -74,6 +90,11 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1 static void chat_onKey(ToxWindow* self, int key) { ChatContext* ctx = (ChatContext*) self->x; + time_t now; + time(&now); + struct tm * timeinfo; + timeinfo = localtime(&now); + if(isprint(key)) { if(ctx->pos != sizeof(ctx->line)-1) { @@ -82,6 +103,17 @@ static void chat_onKey(ToxWindow* self, int key) { } } else if(key == '\n') { + + int inthour = timeinfo->tm_hour; //Pretty bad, but it gets the job done + int intmin = timeinfo->tm_min; + char min[2]; + char hour[2]; + sprintf(hour,"%d",inthour); + sprintf(min,"%d",intmin); + + wattron(ctx->history, COLOR_PAIR(2)); + wprintw(ctx->history,"%s",hour); + wprintw(ctx->history,":%s ",min); wattron(ctx->history, COLOR_PAIR(1)); wprintw(ctx->history, "you: ", ctx->line); wattroff(ctx->history, COLOR_PAIR(1));