text stringlengths 0 357 |
|---|
* Moreover, the message error text can be updated. |
* Finally, the given error text is also logged using dc_log_error(). |
* |
* @private @memberof dc_context_t |
*/ |
void dc_set_msg_failed(dc_context_t* context, uint32_t msg_id, const char* error) |
{ |
dc_msg_t* msg = dc_msg_new_untyped(context); |
sqlite3_stmt* stmt = NULL; |
if (!dc_msg_load_from_db(msg, context, msg_id)) { |
goto cleanup; |
} |
if (DC_STATE_OUT_PREPARING==msg->state || |
DC_STATE_OUT_PENDING ==msg->state || |
DC_STATE_OUT_DELIVERED==msg->state) |
{ |
msg->state = DC_STATE_OUT_FAILED; |
} |
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_MSG_FAILED, msg->chat_id, msg_id); |
cleanup: |
sqlite3_finalize(stmt); |
dc_msg_unref(msg); |
} |
size_t dc_get_real_msg_cnt(dc_context_t* context) |
{ |
sqlite3_stmt* stmt = NULL; |
size_t ret = 0; |
if (context->sql->cobj==NULL) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT COUNT(*) " |
" FROM msgs m " |
" LEFT JOIN chats c ON c.id=m.chat_id " |
" WHERE m.id>" DC_STRINGIFY(DC_MSG_ID_LAST_SPECIAL) |
" AND m.chat_id>" DC_STRINGIFY(DC_CHAT_ID_LAST_SPECIAL) |
" AND c.blocked=0;"); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
dc_sqlite3_log_error(context->sql, "dc_get_real_msg_cnt() failed."); |
goto cleanup; |
} |
ret = sqlite3_column_int(stmt, 0); |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
size_t dc_get_deaddrop_msg_cnt(dc_context_t* context) |
{ |
sqlite3_stmt* stmt = NULL; |
size_t ret = 0; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || context->sql->cobj==NULL) { |
goto cleanup; |
} |
stmt = dc_sqlite3_prepare(context->sql, |
"SELECT COUNT(*) FROM msgs m LEFT JOIN chats c ON c.id=m.chat_id WHERE c.blocked=2;"); |
if (sqlite3_step(stmt)!=SQLITE_ROW) { |
goto cleanup; |
} |
ret = sqlite3_column_int(stmt, 0); |
cleanup: |
sqlite3_finalize(stmt); |
return ret; |
} |
int dc_rfc724_mid_cnt(dc_context_t* context, const char* rfc724_mid) |
{ |
/* check the number of messages with the same rfc724_mid */ |
int ret = 0; |
sqlite3_stmt* stmt = NULL; |
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC || context->sql->cobj==NULL) { |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.