mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-22 21:43:02 +01:00
save logging preference for friend chats and improve log command message
This commit is contained in:
parent
46b046a209
commit
4fb82cceaa
18
src/chat.c
18
src/chat.c
@ -95,9 +95,6 @@ void chat_enable_log(ToxWindow *self)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (ctx->log.log_on)
|
||||
return;
|
||||
|
||||
ctx->log.log_on = true;
|
||||
|
||||
if (!ctx->log.log_path[0])
|
||||
@ -108,10 +105,10 @@ void chat_disable_log(ToxWindow *self)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (ctx->log.log_on) {
|
||||
if (ctx->log.log_on)
|
||||
write_to_log(ctx);
|
||||
ctx->log.log_on = false;
|
||||
}
|
||||
|
||||
ctx->log.log_on = false;
|
||||
}
|
||||
|
||||
static void chat_onMessage(ToxWindow *self, Tox *m, int num, uint8_t *msg, uint16_t len)
|
||||
@ -692,9 +689,14 @@ static void chat_onInit(ToxWindow *self, Tox *m)
|
||||
scrollok(ctx->history, 1);
|
||||
ctx->linewin = subwin(self->window, CHATBOX_HEIGHT, x2, y2-CHATBOX_HEIGHT, 0);
|
||||
wprintw(ctx->history, "\n\n");
|
||||
execute(ctx->history, self, m, "/help", CHAT_COMMAND_MODE);
|
||||
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
||||
wmove(self->window, y2 - CURS_Y_OFFSET, 0);
|
||||
|
||||
execute(ctx->history, self, m, "/help", CHAT_COMMAND_MODE);
|
||||
|
||||
if (friends[self->num].logging_on)
|
||||
chat_enable_log(self);
|
||||
|
||||
execute(ctx->history, self, m, "/log", GLOBAL_COMMAND_MODE);
|
||||
}
|
||||
|
||||
ToxWindow new_chat(Tox *m, int friendnum)
|
||||
|
@ -37,6 +37,7 @@ typedef struct {
|
||||
bool active;
|
||||
bool online;
|
||||
bool is_typing;
|
||||
bool logging_on; /* saves preference for friend irrespective of chat windows */
|
||||
TOX_USERSTATUS status;
|
||||
struct FileReceiver file_receiver;
|
||||
} ToxicFriend;
|
||||
|
@ -222,16 +222,27 @@ void cmd_groupchat(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*arg
|
||||
|
||||
void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX_STR_SIZE])
|
||||
{
|
||||
if (!self->is_chat && !self->is_groupchat) /* remove if prompt logging gets implemented */
|
||||
if (!self->is_chat && !self->is_groupchat) { /* remove if prompt logging gets implemented */
|
||||
wprintw(window, "Invalid command.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (argc == 0) {
|
||||
if (ctx->log.log_on)
|
||||
wprintw(window, "Logging for this chat is on. Type \"/log off\" to disable.\n");
|
||||
else
|
||||
wprintw(window, "Logging for this chat is off. Type \"/log on\" to enable.\n");
|
||||
if (ctx->log.log_on) {
|
||||
wprintw(window, "Logging for this chat is ");
|
||||
wattron(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
wprintw(window, "[on]");
|
||||
wattroff(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
wprintw(window, ". Type \"/log off\" to disable.\n");
|
||||
} else {
|
||||
wprintw(window, "Logging for this chat is ");
|
||||
wattron(window, COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(window, "[off]");
|
||||
wattroff(window, COLOR_PAIR(RED) | A_BOLD);
|
||||
wprintw(window, ". Type \"/log on\" to enable.\n");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@ -239,10 +250,13 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
uint8_t *swch = argv[1];
|
||||
|
||||
if (!strcmp(swch, "1") || !strcmp(swch, "on")) {
|
||||
if (self->is_chat)
|
||||
if (self->is_chat) {
|
||||
chat_enable_log(self);
|
||||
else if (self->is_groupchat)
|
||||
friends[self->num].logging_on = true;
|
||||
} else if (self->is_groupchat) {
|
||||
groupchat_enable_log(self);
|
||||
friends[self->num].logging_on = false;
|
||||
}
|
||||
|
||||
wprintw(window, "Logging ");
|
||||
wattron(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
@ -250,10 +264,12 @@ void cmd_log(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*argv)[MAX
|
||||
wattroff(window, COLOR_PAIR(GREEN) | A_BOLD);
|
||||
return;
|
||||
} else if (!strcmp(swch, "0") || !strcmp(swch, "off")) {
|
||||
if (self->is_chat)
|
||||
if (self->is_chat) {
|
||||
chat_disable_log(self);
|
||||
else if (self->is_groupchat)
|
||||
friends[self->num].logging_on = false;
|
||||
} else if (self->is_groupchat) {
|
||||
groupchat_disable_log(self);
|
||||
}
|
||||
|
||||
wprintw(window, "Logging ");
|
||||
wattron(window, COLOR_PAIR(RED) | A_BOLD);
|
||||
|
@ -106,9 +106,6 @@ void groupchat_enable_log(ToxWindow *self)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
if (ctx->log.log_on)
|
||||
return;
|
||||
|
||||
ctx->log.log_on = true;
|
||||
|
||||
if (!ctx->log.log_path[0])
|
||||
|
@ -48,7 +48,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx)
|
||||
ident[KEY_IDENT_DIGITS*2+1] = '\0';
|
||||
} else {
|
||||
struct tm *tminfo = get_time();
|
||||
snprintf(ident, 32,
|
||||
snprintf(ident, sizeof(ident),
|
||||
"%04d-%02d-%02d-%02d:%02d:%02d", tminfo->tm_year+1900,tminfo->tm_mon+1, tminfo->tm_mday,
|
||||
tminfo->tm_hour, tminfo->tm_min, tminfo->tm_sec);
|
||||
path_len += strlen(ident) + 1;
|
||||
@ -69,7 +69,7 @@ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx)
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(logfile, "\n***NEW SESSION***\n\n");
|
||||
fprintf(logfile, "\n*** NEW SESSION ***\n\n");
|
||||
|
||||
fclose(logfile);
|
||||
free(user_config_dir);
|
||||
|
@ -144,7 +144,7 @@ struct chatlog {
|
||||
uint8_t log_path[MAX_STR_SIZE];
|
||||
uint8_t log_buf[MAX_LOG_BUF_LINES][MAX_LOG_LINE_SIZE];
|
||||
int pos;
|
||||
bool log_on;
|
||||
bool log_on; /* specific to current chat window */
|
||||
};
|
||||
|
||||
#define MAX_LINE_HIST 128
|
||||
|
Loading…
Reference in New Issue
Block a user