From 5ff70657446c0773c7cfb6d59a084caedcdf0434 Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Wed, 26 Feb 2014 03:51:26 -0500 Subject: [PATCH] basic logging for groupchats --- build/Makefile.am | 4 +++- src/chat.c | 8 ++++---- src/chat_commands.c | 2 +- src/global_commands.c | 2 +- src/groupchat.c | 8 ++++++++ src/groupchat.h | 1 + src/log.c | 6 ++++-- 7 files changed, 22 insertions(+), 9 deletions(-) diff --git a/build/Makefile.am b/build/Makefile.am index a670d9b..d38b8f5 100644 --- a/build/Makefile.am +++ b/build/Makefile.am @@ -25,7 +25,9 @@ toxic_SOURCES = $(top_srcdir)/src/main.c \ $(top_srcdir)/src/misc_tools.c \ $(top_srcdir)/src/misc_tools.h \ $(top_srcdir)/src/toxic_strings.c \ - $(top_srcdir)/src/toxic_strings.h + $(top_srcdir)/src/toxic_strings.h \ + $(top_srcdir)/src/log.c \ + $(top_srcdir)/src/log.h toxic_CFLAGS = -I$(top_srcdir) \ $(NCURSES_CFLAGS) \ diff --git a/src/chat.c b/src/chat.c index 7666215..29bcec1 100644 --- a/src/chat.c +++ b/src/chat.c @@ -319,9 +319,9 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, uint8_t *acti wattron(ctx->history, COLOR_PAIR(RED)); wprintw(ctx->history, " * Failed to send action\n"); wattroff(ctx->history, COLOR_PAIR(RED)); + } else { + add_to_log_buf(action, selfname, ctx); } - - add_to_log_buf(action, selfname, ctx); } static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) @@ -507,12 +507,12 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key) } else wprintw(ctx->history, "%s\n", line); - add_to_log_buf(line, selfname, ctx); - if (!statusbar->is_online || tox_send_message(m, self->num, line, strlen(line) + 1) == 0) { wattron(ctx->history, COLOR_PAIR(RED)); wprintw(ctx->history, " * Failed to send message.\n"); wattroff(ctx->history, COLOR_PAIR(RED)); + } else { + add_to_log_buf(line, selfname, ctx); } } diff --git a/src/chat_commands.c b/src/chat_commands.c index 9fdedb3..2fd35bf 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -108,7 +108,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar return; } - if (init_groupchat_win(prompt, m, groupnum) == -1) { + if (init_groupchat_win(prompt, m, groupnum, groupkey) == -1) { wprintw(window, "Group chat window failed to initialize.\n"); tox_del_groupchat(m, groupnum); return; diff --git a/src/global_commands.c b/src/global_commands.c index 0649bac..129b02c 100644 --- a/src/global_commands.c +++ b/src/global_commands.c @@ -211,7 +211,7 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg return; } - if (init_groupchat_win(prompt, m, groupnum) == -1) { + if (init_groupchat_win(prompt, m, groupnum, NULL) == -1) { wprintw(window, "Group chat window failed to initialize.\n"); tox_del_groupchat(m, groupnum); return; diff --git a/src/groupchat.c b/src/groupchat.c index 694a5d0..7fd238f 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -154,6 +154,8 @@ static void groupchat_onGroupMessage(ToxWindow *self, Tox *m, int groupnum, int } else { wprintw(ctx->history, "%s\n", msg); } + + add_to_log_buf(msg, nick, ctx); } static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int peernum, uint8_t *action, @@ -188,6 +190,8 @@ static void groupchat_onGroupAction(ToxWindow *self, Tox *m, int groupnum, int p wattron(ctx->history, COLOR_PAIR(YELLOW)); wprintw(ctx->history, "* %s %s\n", nick, action); wattroff(ctx->history, COLOR_PAIR(YELLOW)); + + add_to_log_buf(action, nick, ctx); } /* Puts two copies of peerlist in chat instance */ @@ -483,6 +487,7 @@ static void groupchat_onKey(ToxWindow *self, Tox *m, wint_t key) if (line[0] == '/') { if (close_win = strcmp(line, "/close") == 0) { + write_to_log(ctx); set_active_window(0); int groupnum = self->num; delwin(ctx->linewin); @@ -575,6 +580,9 @@ static void groupchat_onInit(ToxWindow *self, Tox *m) print_groupchat_help(ctx); wmove(self->window, y-CURS_Y_OFFSET, 0); + + ctx->log.log_on = true; + init_logging_session(self->name, groupchats[self->num].groupkey, ctx); } ToxWindow new_group_chat(Tox *m, int groupnum) diff --git a/src/groupchat.h b/src/groupchat.h index b14efb7..ea282df 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -30,6 +30,7 @@ typedef struct { int side_pos; /* current position of the sidebar - used for scrolling up and down */ uint8_t *peer_names; uint8_t *oldpeer_names; + uint8_t groupkey[TOX_CLIENT_ID_SIZE]; } GroupChat; int init_groupchat_win(ToxWindow *prompt, Tox *m, int groupnum); diff --git a/src/log.c b/src/log.c index 0b127e8..8204615 100644 --- a/src/log.c +++ b/src/log.c @@ -35,7 +35,8 @@ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx) return; char *user_config_dir = get_user_config_dir(); - int path_len = strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(name) + (KEY_IDENT_DIGITS * 2) + 5; + int path_len = strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(name)\ + + (KEY_IDENT_DIGITS * 2) + 5; if (path_len > MAX_STR_SIZE) return; @@ -45,7 +46,8 @@ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx) sprintf(&ident[2], "%02X", key[2] & 0xff); ident[KEY_IDENT_DIGITS*2+1] = '\0'; - snprintf(ctx->log.log_path, MAX_STR_SIZE, "%s%s%s-%s.log", user_config_dir, CONFIGDIR, name, ident); + snprintf(ctx->log.log_path, MAX_STR_SIZE, "%s%s%s-%s.log", + user_config_dir, CONFIGDIR, name, ident); FILE *logfile = fopen(ctx->log.log_path, "a");