summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--testing/toxic/chat.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/testing/toxic/chat.c b/testing/toxic/chat.c
index da67567d..a312d211 100644
--- a/testing/toxic/chat.c
+++ b/testing/toxic/chat.c
@@ -29,16 +29,21 @@ extern int active_window;
29extern void del_window(ToxWindow *w, int f_num); 29extern void del_window(ToxWindow *w, int f_num);
30extern void fix_name(uint8_t *name); 30extern void fix_name(uint8_t *name);
31void print_help(ChatContext *self); 31void print_help(ChatContext *self);
32void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct tm *timeinfo); 32void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd);
33
34struct tm *get_time(void) {
35 struct tm *timeinfo;
36 time_t now;
37 time(&now);
38 timeinfo = localtime(&now);
39 return timeinfo;
40}
33 41
34static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, uint16_t len) 42static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg, uint16_t len)
35{ 43{
36 ChatContext *ctx = (ChatContext*) self->x; 44 ChatContext *ctx = (ChatContext*) self->x;
37 uint8_t nick[MAX_NAME_LENGTH] = {0}; 45 uint8_t nick[MAX_NAME_LENGTH] = {0};
38 time_t now; 46 struct tm *timeinfo = get_time();
39 time(&now);
40 struct tm *timeinfo;
41 timeinfo = localtime(&now);
42 47
43 if (ctx->friendnum != num) 48 if (ctx->friendnum != num)
44 return; 49 return;
@@ -64,10 +69,7 @@ static void chat_onMessage(ToxWindow *self, Messenger *m, int num, uint8_t *msg,
64static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *action, uint16_t len) 69static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *action, uint16_t len)
65{ 70{
66 ChatContext *ctx = (ChatContext*) self->x; 71 ChatContext *ctx = (ChatContext*) self->x;
67 time_t now; 72 struct tm *timeinfo = get_time();
68 time(&now);
69 struct tm *timeinfo;
70 timeinfo = localtime(&now);
71 73
72 if (ctx->friendnum != num) 74 if (ctx->friendnum != num)
73 return; 75 return;
@@ -90,30 +92,40 @@ static void chat_onAction(ToxWindow *self, Messenger *m, int num, uint8_t *actio
90static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len) 92static void chat_onNickChange(ToxWindow *self, int num, uint8_t *nick, uint16_t len)
91{ 93{
92 ChatContext *ctx = (ChatContext*) self->x; 94 ChatContext *ctx = (ChatContext*) self->x;
95 struct tm *timeinfo = get_time();
93 if (ctx->friendnum != num) 96 if (ctx->friendnum != num)
94 return; 97 return;
95 98
99 wattron(ctx->history, COLOR_PAIR(2));
100 wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
101 wattroff(ctx->history, COLOR_PAIR(2));
102
96 nick[len-1] = '\0'; 103 nick[len-1] = '\0';
97 fix_name(nick); 104 fix_name(nick);
98 snprintf(self->title, sizeof(self->title), "[%s (%d)]", nick, num); 105 snprintf(self->title, sizeof(self->title), "[%s (%d)]", nick, num);
99 106
100 wattron(ctx->history, COLOR_PAIR(3)); 107 wattron(ctx->history, COLOR_PAIR(3));
101 wprintw(ctx->history, " * Your partner changed nick to '%s'\n", nick); 108 wprintw(ctx->history, "* Your partner changed nick to '%s'\n", nick);
102 wattroff(ctx->history, COLOR_PAIR(3)); 109 wattroff(ctx->history, COLOR_PAIR(3));
103} 110}
104 111
105static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len) 112static void chat_onStatusChange(ToxWindow *self, int num, uint8_t *status, uint16_t len)
106{ 113{
107 ChatContext *ctx = (ChatContext*) self->x; 114 ChatContext *ctx = (ChatContext*) self->x;
115 struct tm *timeinfo = get_time();
108 if (ctx->friendnum != num) 116 if (ctx->friendnum != num)
109 return; 117 return;
110 118
119 wattron(ctx->history, COLOR_PAIR(2));
120 wprintw(ctx->history, "[%02d:%02d:%02d] ", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
121 wattroff(ctx->history, COLOR_PAIR(2));
122
111 status[len-1] = '\0'; 123 status[len-1] = '\0';
112 fix_name(status); 124 fix_name(status);
113 snprintf(self->title, sizeof(self->title), "[%s (%d)]", status, num); 125 snprintf(self->title, sizeof(self->title), "[%s (%d)]", status, num);
114 126
115 wattron(ctx->history, COLOR_PAIR(3)); 127 wattron(ctx->history, COLOR_PAIR(3));
116 wprintw(ctx->history, " * Your partner changed status to '%s'\n", status); 128 wprintw(ctx->history, "* Your partner changed status to '%s'\n", status);
117 wattroff(ctx->history, COLOR_PAIR(3)); 129 wattroff(ctx->history, COLOR_PAIR(3));
118 130
119} 131}
@@ -131,10 +143,7 @@ int string_is_empty(char *string)
131static void chat_onKey(ToxWindow *self, Messenger *m, int key) 143static void chat_onKey(ToxWindow *self, Messenger *m, int key)
132{ 144{
133 ChatContext *ctx = (ChatContext*) self->x; 145 ChatContext *ctx = (ChatContext*) self->x;
134 time_t now; 146 struct tm *timeinfo = get_time();
135 time(&now);
136 struct tm * timeinfo;
137 timeinfo = localtime(&now);
138 147
139 int x, y, y2, x2; 148 int x, y, y2, x2;
140 getyx(self->window, y, x); 149 getyx(self->window, y, x);
@@ -166,7 +175,7 @@ static void chat_onKey(ToxWindow *self, Messenger *m, int key)
166 wmove(self->window, y2-CURS_Y_OFFSET, 0); 175 wmove(self->window, y2-CURS_Y_OFFSET, 0);
167 wclrtobot(self->window); 176 wclrtobot(self->window);
168 if (ctx->line[0] == '/') 177 if (ctx->line[0] == '/')
169 execute(self, ctx, m, ctx->line, timeinfo); 178 execute(self, ctx, m, ctx->line);
170 else { 179 else {
171 /* make sure the string has at least non-space character */ 180 /* make sure the string has at least non-space character */
172 if (!string_is_empty(ctx->line)) { 181 if (!string_is_empty(ctx->line)) {
@@ -193,7 +202,7 @@ static void chat_onKey(ToxWindow *self, Messenger *m, int key)
193 } 202 }
194} 203}
195 204
196void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct tm *timeinfo) 205void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd)
197{ 206{
198 if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) { 207 if (!strcmp(cmd, "/clear") || !strcmp(cmd, "/c")) {
199 wclear(self->window); 208 wclear(self->window);
@@ -213,6 +222,7 @@ void execute(ToxWindow *self, ChatContext *ctx, Messenger *m, char *cmd, struct
213 } 222 }
214 223
215 else if (!strncmp(cmd, "/me ", strlen("/me "))) { 224 else if (!strncmp(cmd, "/me ", strlen("/me "))) {
225 struct tm *timeinfo = get_time();
216 char *action = strchr(cmd, ' '); 226 char *action = strchr(cmd, ' ');
217 if (action == NULL) { 227 if (action == NULL) {
218 wprintw(self->window, "Invalid syntax.\n"); 228 wprintw(self->window, "Invalid syntax.\n");