mirror of
https://github.com/Tha14/toxic.git
synced 2024-12-23 10:13:24 +01:00
don't write unsent messages to log
This commit is contained in:
parent
13c5de5531
commit
0a6ce62363
@ -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)
|
||||
{
|
||||
struct chat_queue *q = self->chatwin->cqueue;
|
||||
cqueue_remove(self, q, receipt);
|
||||
cqueue_remove(self, m, receipt);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@ -920,7 +918,6 @@ static void chat_onKey(ToxWindow *self, Tox *m, wint_t key, bool ltr)
|
||||
get_time_str(timefrmt, sizeof(timefrmt));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ void init_logging_session(char *name, const char *key, struct chatlog *log)
|
||||
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)
|
||||
{
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "message_queue.h"
|
||||
#include "misc_tools.h"
|
||||
#include "line_info.h"
|
||||
#include "log.h"
|
||||
|
||||
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 */
|
||||
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;
|
||||
|
||||
while (line) {
|
||||
if (line->id != id) {
|
||||
if (line->id != msg->line_id) {
|
||||
line = line->prev;
|
||||
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) {
|
||||
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. */
|
||||
void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt)
|
||||
/* removes message with matching receipt from queue, writes to log and updates line to show the message was received. */
|
||||
void cqueue_remove(ToxWindow *self, Tox *m, uint32_t receipt)
|
||||
{
|
||||
struct chat_queue *q = self->chatwin->cqueue;
|
||||
struct cqueue_msg *msg = q->root;
|
||||
|
||||
while (msg) {
|
||||
@ -100,7 +102,13 @@ void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt)
|
||||
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;
|
||||
|
||||
if (msg->prev == NULL) { /* root */
|
||||
|
@ -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. */
|
||||
void cqueue_try_send(ToxWindow *self, Tox *m);
|
||||
|
||||
/* removes message with matching receipt from queue and updates line to show the message was received. */
|
||||
void cqueue_remove(ToxWindow *self, struct chat_queue *q, uint32_t receipt);
|
||||
/* removes message with matching receipt from queue, writes to log and updates line to show the message was received. */
|
||||
void cqueue_remove(ToxWindow *self, Tox *m, uint32_t receipt);
|
||||
|
Loading…
Reference in New Issue
Block a user