1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-11-23 03:13:01 +01:00

Merge pull request #276 from stqism/master

Adds timestamp to toxic, fixes issue #217
This commit is contained in:
irungentoo 2013-08-03 13:33:27 -07:00
commit e2ce3d5397

18
chat.c
View File

@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <ctype.h> #include <ctype.h>
#include <time.h>
#include "../../core/Messenger.h" #include "../../core/Messenger.h"
#include "../../core/network.h" #include "../../core/network.h"
@ -26,11 +27,15 @@ typedef struct {
extern void fix_name(uint8_t* name); extern void fix_name(uint8_t* name);
static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) { static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len) {
ChatContext* ctx = (ChatContext*) self->x; ChatContext* ctx = (ChatContext*) self->x;
uint8_t nick[MAX_NAME_LENGTH] = {0}; uint8_t nick[MAX_NAME_LENGTH] = {0};
time_t now;
time(&now);
struct tm * timeinfo;
timeinfo = localtime(&now);
if(ctx->friendnum != num) if(ctx->friendnum != num)
return; return;
@ -42,10 +47,11 @@ static void chat_onMessage(ToxWindow* self, int num, uint8_t* msg, uint16_t len)
fix_name(msg); fix_name(msg);
fix_name(nick); fix_name(nick);
wattron(ctx->history, COLOR_PAIR(2));
wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattron(ctx->history, COLOR_PAIR(4)); wattron(ctx->history, COLOR_PAIR(4));
wprintw(ctx->history, "%s: ", nick); wprintw(ctx->history, "%s: ", nick);
wattroff(ctx->history, COLOR_PAIR(4)); wattroff(ctx->history, COLOR_PAIR(4));
wprintw(ctx->history, "%s\n", msg); wprintw(ctx->history, "%s\n", msg);
self->blink = true; self->blink = true;
@ -74,6 +80,11 @@ static void chat_onStatusChange(ToxWindow* self, int num, uint8_t* status, uint1
static void chat_onKey(ToxWindow* self, int key) { static void chat_onKey(ToxWindow* self, int key) {
ChatContext* ctx = (ChatContext*) self->x; ChatContext* ctx = (ChatContext*) self->x;
time_t now;
time(&now);
struct tm * timeinfo;
timeinfo = localtime(&now);
if(isprint(key)) { if(isprint(key)) {
if(ctx->pos != sizeof(ctx->line)-1) { if(ctx->pos != sizeof(ctx->line)-1) {
@ -82,10 +93,11 @@ static void chat_onKey(ToxWindow* self, int key) {
} }
} }
else if(key == '\n') { else if(key == '\n') {
wattron(ctx->history, COLOR_PAIR(2));
wprintw(ctx->history, "%02d:%02d:%02d ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
wattron(ctx->history, COLOR_PAIR(1)); wattron(ctx->history, COLOR_PAIR(1));
wprintw(ctx->history, "you: ", ctx->line); wprintw(ctx->history, "you: ", ctx->line);
wattroff(ctx->history, COLOR_PAIR(1)); wattroff(ctx->history, COLOR_PAIR(1));
wprintw(ctx->history, "%s\n", ctx->line); wprintw(ctx->history, "%s\n", ctx->line);
if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) { if(m_sendmessage(ctx->friendnum, (uint8_t*) ctx->line, strlen(ctx->line)+1) < 0) {