mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-06 03:50:08 +02:00
add a msg-function to set a msg into error-state, incl. error-text
This commit is contained in:
parent
5770bd8b16
commit
9c59c46b57
3 changed files with 33 additions and 15 deletions
17
src/dc_job.c
17
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 */
|
||||
}
|
||||
|
||||
|
|
30
src/dc_msg.c
30
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;
|
||||
|
|
|
@ -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*);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue