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

basic logging for groupchats

This commit is contained in:
Jfreegman 2014-02-26 03:51:26 -05:00
parent 831d8e5f24
commit 5ff7065744
7 changed files with 22 additions and 9 deletions

View File

@ -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) \

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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");