Skip to content
This repository has been archived by the owner on Nov 25, 2022. It is now read-only.

Commit

Permalink
Deleting a chat always deletes all messages from the device permanently.
Browse files Browse the repository at this point in the history
  • Loading branch information
r10s committed Jul 27, 2017
1 parent c8df206 commit baca7ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 41 deletions.
47 changes: 7 additions & 40 deletions src/mrchat.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,65 +986,32 @@ int mrmailbox_delete_chat_part2(mrmailbox_t* mailbox, uint32_t chat_id)
goto cleanup;
}

if( obj->m_type == MR_CHAT_NORMAL )
{
/* delete a single-user-chat; all messages go to the deaddrop chat */
mrsqlite3_begin_transaction__(mailbox->m_sql);
pending_transaction = 1;
mrsqlite3_begin_transaction__(mailbox->m_sql);
pending_transaction = 1;

q3 = sqlite3_mprintf("UPDATE msgs SET chat_id=%i WHERE chat_id=%i AND from_id=1;", MR_CHAT_ID_TO_DEADDROP, chat_id);
q3 = sqlite3_mprintf("DELETE FROM msgs WHERE chat_id=%i;", chat_id);
if( !mrsqlite3_execute__(mailbox->m_sql, q3) ) {
goto cleanup;
}
sqlite3_free(q3);
q3 = NULL;

q3 = sqlite3_mprintf("UPDATE msgs SET chat_id=%i WHERE chat_id=%i AND from_id!=1;", MR_CHAT_ID_DEADDROP, chat_id);
q3 = sqlite3_mprintf("DELETE FROM chats_contacts WHERE chat_id=%i;", chat_id);
if( !mrsqlite3_execute__(mailbox->m_sql, q3) ) {
goto cleanup;
}
sqlite3_free(q3);
q3 = NULL;
}
else if( obj->m_type == MR_CHAT_GROUP )
{
/* delete a group-chat; all messages are deleted from the device but stay on the server.
Currently, they cannot be restored - "to_id" as used to restore single-user-chats is not sufficient.
Maybe it is okay (and maybe even expected :-) that messages from deleted chats do not show up again if a chat is re-created. */
mrsqlite3_begin_transaction__(mailbox->m_sql);
pending_transaction = 1;

q3 = sqlite3_mprintf("DELETE FROM msgs WHERE chat_id=%i;", chat_id);
q3 = sqlite3_mprintf("DELETE FROM chats WHERE id=%i;", chat_id);
if( !mrsqlite3_execute__(mailbox->m_sql, q3) ) {
goto cleanup;
}
sqlite3_free(q3);
q3 = NULL;
}
else
{
/* Bad type. */
goto cleanup;
}

q3 = sqlite3_mprintf("DELETE FROM chats_contacts WHERE chat_id=%i;", chat_id);
if( !mrsqlite3_execute__(mailbox->m_sql, q3) ) {
goto cleanup;
}
sqlite3_free(q3);
q3 = NULL;

q3 = sqlite3_mprintf("DELETE FROM chats WHERE id=%i;", chat_id);
if( !mrsqlite3_execute__(mailbox->m_sql, q3) ) {
goto cleanup;
}
sqlite3_free(q3);
q3 = NULL;

if( pending_transaction ) {
mrsqlite3_commit__(mailbox->m_sql);
pending_transaction = 0;
}
mrsqlite3_commit__(mailbox->m_sql);
pending_transaction = 0;

mrsqlite3_unlock(mailbox->m_sql);
locked = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/mrmailbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ uint32_t mrmailbox_get_chat_id_by_contact_id (mrmailbox_t*, uint32_t
uint32_t mrmailbox_create_chat_by_contact_id (mrmailbox_t*, uint32_t contact_id); /* create a normal chat with a single user */
carray* mrmailbox_get_chat_media (mrmailbox_t*, uint32_t chat_id, int msg_type, int or_msg_type); /* returns message IDs, the result must be carray_free()'d */
carray* mrmailbox_get_fresh_msgs (mrmailbox_t*); /* returns message IDs, typically used for implementing notification summaries, the result must be free()'d */
int mrmailbox_delete_chat (mrmailbox_t*, uint32_t chat_id); /* deletes the chat object, no messages are deleted (we do not so as we cannot distinguish between chat messages and normal mails) */
int mrmailbox_delete_chat (mrmailbox_t*, uint32_t chat_id); /* deletes the chat object, messages are deleted from the device and stay on the server. */


/* Get previous/next media of a given media message (imaging eg. a virtual playlist of all audio tracks in a chat).
Expand Down

0 comments on commit baca7ee

Please sign in to comment.