From 9aba85b9675293a1e60d91ae22c52e5c9b880259 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 21 Dec 2020 22:00:36 +0100 Subject: [PATCH] add handling for local message deleting --- .../simplemobiletools/smsmessenger/extensions/Context.kt | 2 ++ .../smsmessenger/interfaces/MessagesDao.kt | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt index d3beb6e2..b0b08594 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/extensions/Context.kt @@ -502,6 +502,7 @@ fun Context.deleteConversation(threadId: Long) { contentResolver.delete(uri, selection, selectionArgs) conversationsDB.deleteThreadId(threadId) + messagesDB.deleteThreadMessages(threadId) } fun Context.deleteMessage(id: Long, isMMS: Boolean) { @@ -510,6 +511,7 @@ fun Context.deleteMessage(id: Long, isMMS: Boolean) { val selectionArgs = arrayOf(id.toString()) try { contentResolver.delete(uri, selection, selectionArgs) + messagesDB.delete(id) } catch (e: Exception) { showErrorToast(e) } diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt index 4e25bd99..70bf6510 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/interfaces/MessagesDao.kt @@ -25,4 +25,10 @@ interface MessagesDao { @Query("UPDATE messages SET read = 1 WHERE thread_id = :threadId") fun markThreadRead(threadId: Long) + + @Query("DELETE FROM messages WHERE id = :id") + fun delete(id: Long) + + @Query("DELETE FROM messages WHERE thread_id = :threadId") + fun deleteThreadMessages(threadId: Long) }