From 9c59c46b571b101a6ed5684e17bbbf6091204bdc Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Wed, 11 Jul 2018 16:29:46 +0200 Subject: [PATCH] add a msg-function to set a msg into error-state, incl. error-text --- src/dc_job.c | 17 ++--------------- src/dc_msg.c | 30 ++++++++++++++++++++++++++++++ src/dc_msg.h | 1 + 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/dc_job.c b/src/dc_job.c index 015fd303..7c62455e 100644 --- a/src/dc_job.c +++ b/src/dc_job.c @@ -298,17 +298,6 @@ cleanup: ******************************************************************************/ -static void mark_as_error(dc_context_t* context, dc_msg_t* msg) -{ - if (context==NULL || msg==NULL) { - return; - } - - dc_update_msg_state(context, msg->id, DC_STATE_OUT_ERROR); - context->cb(context, DC_EVENT_MSGS_CHANGED, msg->chat_id, 0); -} - - static void dc_job_do_DC_JOB_SEND_MSG_TO_SMTP(dc_context_t* context, dc_job_t* job) { dc_mimefactory_t mimefactory; @@ -343,15 +332,13 @@ static void dc_job_do_DC_JOB_SEND_MSG_TO_SMTP(dc_context_t* context, dc_job_t* j /* send message - it's okay if there are no recipients, this is a group with only OURSELF; we only upload to IMAP in this case */ if (clist_count(mimefactory.recipients_addr) > 0) { if (!dc_mimefactory_render(&mimefactory)) { - mark_as_error(context, mimefactory.msg); - dc_log_error(context, 0, "Empty message."); /* should not happen */ + dc_update_msg_error(context, job->msg_id, "Empty message."); goto cleanup; /* no redo, no IMAP - there won't be more recipients next time. */ } /* have we guaranteed encryption but cannot fulfill it for any reason? Do not send the message then.*/ if (dc_param_get_int(mimefactory.msg->param, DC_PARAM_GUARANTEE_E2EE, 0) && !mimefactory.out_encrypted) { - mark_as_error(context, mimefactory.msg); - dc_log_error(context, 0, "End-to-end-encryption unavailable unexpectedly."); + dc_update_msg_error(context, job->msg_id, "End-to-end-encryption unavailable unexpectedly."); goto cleanup; /* unrecoverable */ } diff --git a/src/dc_msg.c b/src/dc_msg.c index e5fab6d6..8b0a197e 100644 --- a/src/dc_msg.c +++ b/src/dc_msg.c @@ -1158,6 +1158,36 @@ void dc_update_msg_state(dc_context_t* context, uint32_t msg_id, int state) } +void dc_update_msg_error(dc_context_t* context, uint32_t msg_id, const char* error) +{ + dc_msg_t* msg = dc_msg_new(); + sqlite3_stmt* stmt = NULL; + + if (!dc_msg_load_from_db(msg, context, msg_id)) { + goto cleanup; + } + + msg->state = DC_STATE_OUT_ERROR; + if (error) { + dc_param_set(msg->param, DC_PARAM_ERROR, error); + dc_log_error(context, 0, "%s", error); + } + + stmt = dc_sqlite3_prepare(context->sql, + "UPDATE msgs SET state=?, param=? WHERE id=?;"); + sqlite3_bind_int (stmt, 1, msg->state); + sqlite3_bind_text(stmt, 2, msg->param->packed, -1, SQLITE_STATIC); + sqlite3_bind_int (stmt, 3, msg_id); + sqlite3_step(stmt); + + context->cb(context, DC_EVENT_MSGS_CHANGED, msg->chat_id, 0); + +cleanup: + sqlite3_finalize(stmt); + dc_msg_unref(msg); +} + + size_t dc_get_real_msg_cnt(dc_context_t* context) { sqlite3_stmt* stmt = NULL; diff --git a/src/dc_msg.h b/src/dc_msg.h index dc1e2fb0..75144a86 100644 --- a/src/dc_msg.h +++ b/src/dc_msg.h @@ -110,6 +110,7 @@ The value is also used for CC:-summaries */ // Context functions to work with messages void dc_update_msg_chat_id (dc_context_t*, uint32_t msg_id, uint32_t chat_id); void dc_update_msg_state (dc_context_t*, uint32_t msg_id, int state); +void dc_update_msg_error (dc_context_t*, uint32_t msg_id, const char* error); int dc_mdn_from_ext (dc_context_t*, uint32_t from_id, const char* rfc724_mid, time_t, uint32_t* ret_chat_id, uint32_t* ret_msg_id); /* returns 1 if an event should be send */ size_t dc_get_real_msg_cnt (dc_context_t*); /* the number of messages assigned to real chat (!=deaddrop, !=trash) */ size_t dc_get_deaddrop_msg_cnt (dc_context_t*);