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

don't write unsent messages to log

This commit is contained in:
Jfreegman 2014-09-11 01:36:33 -04:00
parent 13c5de5531
commit 0a6ce62363
No known key found for this signature in database
GPG Key ID: 3627F3144076AE63
4 changed files with 18 additions and 13 deletions

View File

@ -290,8 +290,7 @@ static void chat_onStatusMessageChange(ToxWindow *self, int32_t num, const char
static void chat_onReadReceipt(ToxWindow *self, Tox *m, int32_t num, uint32_t receipt) static void chat_onReadReceipt(ToxWindow *self, Tox *m, int32_t num, uint32_t receipt)
{ {
struct chat_queue *q = self->chatwin->cqueue; cqueue_remove(self, m, receipt);
cqueue_remove(self, q, receipt);
} }
static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum, static void chat_onFileSendRequest(ToxWindow *self, Tox *m, int32_t num, uint8_t filenum,
@ -838,7 +837,6 @@ static void send_action(ToxWindow *self, ChatContext *ctx, Tox *m, char *action)
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, OUT_ACTION, 0, 0, "%s", action); line_info_add(self, timefrmt, selfname, NULL, OUT_ACTION, 0, 0, "%s", action);
write_to_log(action, selfname, ctx->log, true);
cqueue_add(ctx->cqueue, action, strlen(action), OUT_ACTION, ctx->hst->line_end->id + 1); cqueue_add(ctx->cqueue, action, strlen(action), OUT_ACTION, ctx->hst->line_end->id + 1);
} }
@ -920,7 +918,6 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
get_time_str(timefrmt, sizeof(timefrmt)); get_time_str(timefrmt, sizeof(timefrmt));
line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line); line_info_add(self, timefrmt, selfname, NULL, OUT_MSG, 0, 0, "%s", line);
write_to_log(line, selfname, ctx->log, false);
cqueue_add(ctx->cqueue, line, strlen(line), OUT_MSG, ctx->hst->line_end->id + 1); cqueue_add(ctx->cqueue, line, strlen(line), OUT_MSG, ctx->hst->line_end->id + 1);
} }

View File

@ -86,7 +86,7 @@ void init_logging_session(char *name, const char *key, struct chatlog *log)
fprintf(log->file, "\n*** NEW SESSION ***\n\n"); fprintf(log->file, "\n*** NEW SESSION ***\n\n");
} }
#define LOG_FLUSH_LIMIT 2 /* limits calls to fflush to a max of one per LOG_FLUSH_LIMIT seconds */ #define LOG_FLUSH_LIMIT 1 /* limits calls to fflush to a max of one per LOG_FLUSH_LIMIT seconds */
void write_to_log(const char *msg, const char *name, struct chatlog *log, bool event) void write_to_log(const char *msg, const char *name, struct chatlog *log, bool event)
{ {

View File

@ -27,6 +27,7 @@
#include "message_queue.h" #include "message_queue.h"
#include "misc_tools.h" #include "misc_tools.h"
#include "line_info.h" #include "line_info.h"
#include "log.h"
void cqueue_cleanup(struct chat_queue *q) void cqueue_cleanup(struct chat_queue *q)
{ {
@ -68,17 +69,17 @@ void cqueue_add(struct chat_queue *q, const char *msg, int len, uint8_t type, ui
} }
/* update line to show receipt was received after queue removal */ /* update line to show receipt was received after queue removal */
static void cqueue_mark_read(ToxWindow *self, uint32_t id, uint8_t type) static void cqueue_mark_read(ToxWindow *self, struct cqueue_msg *msg)
{ {
struct line_info *line = self->chatwin->hst->line_end; struct line_info *line = self->chatwin->hst->line_end;
while (line) { while (line) {
if (line->id != id) { if (line->id != msg->line_id) {
line = line->prev; line = line->prev;
continue; continue;
} }
line->type = type == OUT_ACTION ? OUT_ACTION_READ : OUT_MSG_READ; line->type = msg->type == OUT_ACTION ? OUT_ACTION_READ : OUT_MSG_READ;
if (line->noread_flag == true) { if (line->noread_flag == true) {
line->len -= 2; line->len -= 2;
@ -89,9 +90,10 @@ static void cqueue_mark_read(ToxWindow *self, uint32_t id, uint8_t type)
} }
} }
/* removes message with matching receipt from queue and updates line to show the message was received. */ /* removes message with matching receipt from queue, writes to log and updates line to show the message was received. */
void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt) void cqueue_remove(ToxWindow *self, Tox *m, uint32_t receipt)
{ {
struct chat_queue *q = self->chatwin->cqueue;
struct cqueue_msg *msg = q->root; struct cqueue_msg *msg = q->root;
while (msg) { while (msg) {
@ -100,7 +102,13 @@ void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt)
continue; continue;
} }
cqueue_mark_read(self, msg->line_id, msg->type); char selfname[TOX_MAX_NAME_LENGTH];
uint16_t len = tox_get_self_name(m, (uint8_t *) selfname);
selfname[len] = '\0';
write_to_log(msg->message, selfname, self->chatwin->log, msg->type == OUT_ACTION);
cqueue_mark_read(self, msg);
struct cqueue_msg *next = msg->next; struct cqueue_msg *next = msg->next;
if (msg->prev == NULL) { /* root */ if (msg->prev == NULL) { /* root */

View File

@ -42,5 +42,5 @@ void cqueue_add(struct chat_queue *q, const char *msg, int len, uint8_t type, ui
/* Tries to send the oldest unsent message in queue. */ /* Tries to send the oldest unsent message in queue. */
void cqueue_try_send(ToxWindow *self, Tox *m); void cqueue_try_send(ToxWindow *self, Tox *m);
/* removes message with matching receipt from queue and updates line to show the message was received. */ /* removes message with matching receipt from queue, writes to log and updates line to show the message was received. */
void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt); void cqueue_remove(ToxWindow *self, Tox *m, uint32_t receipt);