mirror of
https://github.com/deltachat/deltachat-core.git
synced 2025-10-05 10:39:27 +02:00
move low-level msg-db-delete to separate function
This commit is contained in:
parent
638ee4fda9
commit
b80caa138c
3 changed files with 77 additions and 54 deletions
55
src/dc_job.c
55
src/dc_job.c
|
@ -56,7 +56,6 @@ static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t*
|
|||
{
|
||||
int delete_from_server = 1;
|
||||
dc_msg_t* msg = dc_msg_new_untyped(context);
|
||||
sqlite3_stmt* stmt = NULL;
|
||||
|
||||
if (!dc_msg_load_from_db(msg, context, job->foreign_id)
|
||||
|| msg->rfc724_mid==NULL || msg->rfc724_mid[0]==0 /* eg. device messages have no Message-ID */) {
|
||||
|
@ -90,61 +89,9 @@ static void dc_job_do_DC_JOB_DELETE_MSG_ON_IMAP(dc_context_t* context, dc_job_t*
|
|||
- if the message is successfully removed from the server
|
||||
- or if there are other parts of the message in the database (in this case we have not deleted if from the server)
|
||||
(As long as the message is not removed from the IMAP-server, we need at least one database entry to avoid a re-download) */
|
||||
stmt = dc_sqlite3_prepare(context->sql,
|
||||
"DELETE FROM msgs WHERE id=?;");
|
||||
sqlite3_bind_int(stmt, 1, msg->id);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
stmt = dc_sqlite3_prepare(context->sql,
|
||||
"DELETE FROM msgs_mdns WHERE msg_id=?;");
|
||||
sqlite3_bind_int(stmt, 1, msg->id);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||
if (pathNfilename) {
|
||||
if (strncmp("$BLOBDIR", pathNfilename, 8)==0)
|
||||
{
|
||||
char* strLikeFilename = dc_mprintf("%%f=%s%%", pathNfilename);
|
||||
stmt = dc_sqlite3_prepare(context->sql,
|
||||
"SELECT id FROM msgs WHERE type!=? AND param LIKE ?;"); /* if this gets too slow, an index over "type" should help. */
|
||||
sqlite3_bind_int (stmt, 1, DC_MSG_TEXT);
|
||||
sqlite3_bind_text(stmt, 2, strLikeFilename, -1, SQLITE_STATIC);
|
||||
int file_used_by_other_msgs = (sqlite3_step(stmt)==SQLITE_ROW)? 1 : 0;
|
||||
free(strLikeFilename);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if (!file_used_by_other_msgs)
|
||||
{
|
||||
dc_delete_file(context, pathNfilename);
|
||||
|
||||
char* increation_file = dc_mprintf("%s.increation", pathNfilename);
|
||||
dc_delete_file(context, increation_file);
|
||||
free(increation_file);
|
||||
|
||||
char* filenameOnly = dc_get_filename(pathNfilename);
|
||||
if (msg->type==DC_MSG_VOICE) {
|
||||
char* waveform_file = dc_mprintf("%s/%s.waveform", context->blobdir, filenameOnly);
|
||||
dc_delete_file(context, waveform_file);
|
||||
free(waveform_file);
|
||||
}
|
||||
else if (msg->type==DC_MSG_VIDEO) {
|
||||
char* preview_file = dc_mprintf("%s/%s-preview.jpg", context->blobdir, filenameOnly);
|
||||
dc_delete_file(context, preview_file);
|
||||
free(preview_file);
|
||||
}
|
||||
free(filenameOnly);
|
||||
}
|
||||
}
|
||||
free(pathNfilename);
|
||||
}
|
||||
dc_delete_msg_from_db(context, msg->id);
|
||||
|
||||
cleanup:
|
||||
sqlite3_finalize(stmt);
|
||||
dc_msg_unref(msg);
|
||||
}
|
||||
|
||||
|
|
74
src/dc_msg.c
74
src/dc_msg.c
|
@ -1594,6 +1594,80 @@ void dc_star_msgs(dc_context_t* context, const uint32_t* msg_ids, int msg_cnt, i
|
|||
******************************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* Low-level function to delete a message from the database.
|
||||
* This does not delete the messages from the server.
|
||||
*
|
||||
* @private @memberof dc_context_t
|
||||
*/
|
||||
void dc_delete_msg_from_db(dc_context_t* context, uint32_t msg_id)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
stmt = dc_sqlite3_prepare(context->sql,
|
||||
"DELETE FROM msgs WHERE id=?;");
|
||||
sqlite3_bind_int(stmt, 1, msg->id);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
stmt = dc_sqlite3_prepare(context->sql,
|
||||
"DELETE FROM msgs_mdns WHERE msg_id=?;");
|
||||
sqlite3_bind_int(stmt, 1, msg->id);
|
||||
sqlite3_step(stmt);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
char* pathNfilename = dc_param_get(msg->param, DC_PARAM_FILE, NULL);
|
||||
if (pathNfilename) {
|
||||
if (strncmp("$BLOBDIR", pathNfilename, 8)==0)
|
||||
{
|
||||
char* strLikeFilename = dc_mprintf("%%f=%s%%", pathNfilename);
|
||||
stmt = dc_sqlite3_prepare(context->sql,
|
||||
"SELECT id FROM msgs WHERE type!=? AND param LIKE ?;"); /* if this gets too slow, an index over "type" should help. */
|
||||
sqlite3_bind_int (stmt, 1, DC_MSG_TEXT);
|
||||
sqlite3_bind_text(stmt, 2, strLikeFilename, -1, SQLITE_STATIC);
|
||||
int file_used_by_other_msgs = (sqlite3_step(stmt)==SQLITE_ROW)? 1 : 0;
|
||||
free(strLikeFilename);
|
||||
sqlite3_finalize(stmt);
|
||||
stmt = NULL;
|
||||
|
||||
if (!file_used_by_other_msgs)
|
||||
{
|
||||
dc_delete_file(context, pathNfilename);
|
||||
|
||||
char* increation_file = dc_mprintf("%s.increation", pathNfilename);
|
||||
dc_delete_file(context, increation_file);
|
||||
free(increation_file);
|
||||
|
||||
char* filenameOnly = dc_get_filename(pathNfilename);
|
||||
if (msg->type==DC_MSG_VOICE) {
|
||||
char* waveform_file = dc_mprintf("%s/%s.waveform", context->blobdir, filenameOnly);
|
||||
dc_delete_file(context, waveform_file);
|
||||
free(waveform_file);
|
||||
}
|
||||
else if (msg->type==DC_MSG_VIDEO) {
|
||||
char* preview_file = dc_mprintf("%s/%s-preview.jpg", context->blobdir, filenameOnly);
|
||||
dc_delete_file(context, preview_file);
|
||||
free(preview_file);
|
||||
}
|
||||
free(filenameOnly);
|
||||
}
|
||||
}
|
||||
free(pathNfilename);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
sqlite3_finalize(stmt);
|
||||
dc_msg_unref(msg);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete messages. The messages are deleted on the current device and
|
||||
* on the IMAP server.
|
||||
|
|
|
@ -73,6 +73,8 @@ char* dc_msg_get_summarytext_by_raw (int type, const char* tex
|
|||
void dc_msg_save_param_to_disk (dc_msg_t*);
|
||||
void dc_msg_guess_msgtype_from_suffix (const char* pathNfilename, int* ret_msgtype, char** ret_mime);
|
||||
|
||||
void dc_delete_msg_from_db (dc_context_t*, uint32_t);
|
||||
|
||||
#define DC_MSG_NEEDS_ATTACHMENT(a) ((a)==DC_MSG_IMAGE || (a)==DC_MSG_GIF || (a)==DC_MSG_AUDIO || (a)==DC_MSG_VOICE || (a)==DC_MSG_VIDEO || (a)==DC_MSG_FILE)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue