From 165ade7259ec61d89b82833f06a993e0a682cb9a Mon Sep 17 00:00:00 2001 From: AL-Session <160798022+AL-Session@users.noreply.github.com> Date: Mon, 8 Apr 2024 15:31:05 +1000 Subject: [PATCH 1/2] SES1688 - Deleting last message in conversation, group, or community leaves the RecyclerView in a broken state (#1449) * Initial fix implemented * Fixes #1448 * Addressed PR feedback --- .../conversation/v2/ConversationActivityV2.kt | 11 +++++------ .../thoughtcrime/securesms/database/MmsDatabase.kt | 3 +-- .../securesms/database/SmsDatabase.java | 1 + .../securesms/database/ThreadDatabase.java | 14 ++------------ 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 00e72562d5..7b9c3629f9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -1112,6 +1112,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val blindedRecipient = viewModel.blindedRecipient val binding = binding ?: return val openGroup = viewModel.openGroup + val (textResource, insertParam) = when { recipient.isLocalNumber -> R.string.activity_conversation_empty_state_note_to_self to null openGroup != null && !openGroup.canWrite -> R.string.activity_conversation_empty_state_read_only to recipient.toShortString() @@ -1882,12 +1883,12 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe Log.w("ConversationActivityV2", "Asked to delete messages but could not obtain viewModel recipient - aborting.") return } - + val allSentByCurrentUser = messages.all { it.isOutgoing } val allHasHash = messages.all { lokiMessageDb.getMessageServerHash(it.id, it.isMms) != null } - // If the recipient is a community then we delete the message for everyone - if (recipient.isCommunityRecipient) { + // If the recipient is a community OR a Note-to-Self then we delete the message for everyone + if (recipient.isCommunityRecipient || recipient.isLocalNumber) { val messageCount = 1 // Only used for plurals string showSessionDialog { title(resources.getQuantityString(R.plurals.ConversationFragment_delete_selected_messages, messageCount, messageCount)) @@ -1917,8 +1918,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe } bottomSheet.show(supportFragmentManager, bottomSheet.tag) } - else // Finally, if this is a closed group and you are deleting someone else's message(s) - // then we can only delete locally. + else // Finally, if this is a closed group and you are deleting someone else's message(s) then we can only delete locally. { val messageCount = 1 showSessionDialog { @@ -2027,7 +2027,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe val message = messages.first() as MmsMessageRecord // Do not allow the user to download a file attachment before it has finished downloading - // TODO: Localise the msg in this toast! if (message.isMediaPending) { Toast.makeText(this, resources.getString(R.string.conversation_activity__wait_until_attachment_has_finished_downloading), Toast.LENGTH_LONG).show() return diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt index 0f39e3a496..f2fcefd0aa 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsDatabase.kt @@ -1095,8 +1095,7 @@ class MmsDatabase(context: Context, databaseHelper: SQLCipherOpenHelper) : Messa } val whereString = where.substring(0, where.length - 4) try { - cursor = - db!!.query(TABLE_NAME, arrayOf(ID), whereString, null, null, null, null) + cursor = db!!.query(TABLE_NAME, arrayOf(ID), whereString, null, null, null, null) val toDeleteStringMessageIds = mutableListOf() while (cursor.moveToNext()) { toDeleteStringMessageIds += cursor.getLong(0).toString() diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java index 61f17a2d86..450e7c2d23 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/SmsDatabase.java @@ -633,6 +633,7 @@ public class SmsDatabase extends MessagingDatabase { SQLiteDatabase db = databaseHelper.getWritableDatabase(); long threadId = getThreadIdForMessage(messageId); db.delete(TABLE_NAME, ID_WHERE, new String[] {messageId+""}); + notifyConversationListeners(threadId); boolean threadDeleted = DatabaseComponent.get(context).threadDatabase().update(threadId, false, true); return threadDeleted; } diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java index e2f9687451..507088a0ad 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -515,12 +515,6 @@ public class ThreadDatabase extends Database { return getConversationList(where); } - public Cursor getArchivedConversationList() { - String where = "(" + MESSAGE_COUNT + " != 0 OR " + GroupDatabase.TABLE_NAME + "." + GROUP_ID + " LIKE '" + COMMUNITY_PREFIX + "%') " + - "AND " + ARCHIVED + " = 1 "; - return getConversationList(where); - } - private Cursor getConversationList(String where) { SQLiteDatabase db = databaseHelper.getReadableDatabase(); String query = createQuery(where, 0); @@ -750,10 +744,7 @@ public class ThreadDatabase extends Database { return true; } - MmsSmsDatabase.Reader reader = null; - - try { - reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId)); + try (MmsSmsDatabase.Reader reader = mmsSmsDatabase.readerFor(mmsSmsDatabase.getConversationSnippet(threadId))) { MessageRecord record = null; if (reader != null) { record = reader.getNext(); @@ -771,11 +762,10 @@ public class ThreadDatabase extends Database { deleteThread(threadId); return true; } + // todo: add empty snippet that clears existing data return false; } } finally { - if (reader != null) - reader.close(); notifyConversationListListeners(); notifyConversationListeners(threadId); } From 1d9ac6ac10ed36b0c447073185770584e8691a4e Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Wed, 10 Apr 2024 15:31:33 +1000 Subject: [PATCH 2/2] build: update build number --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1e63207bf9..9e231c1bec 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -31,8 +31,8 @@ configurations.all { exclude module: "commons-logging" } -def canonicalVersionCode = 369 -def canonicalVersionName = "1.18.1" +def canonicalVersionCode = 370 +def canonicalVersionName = "1.18.2" def postFixSize = 10 def abiPostFix = ['armeabi-v7a' : 1,