From 35d176c71e3ed6b0df3d98ca1369923e26b52773 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 9 Apr 2024 12:36:11 +0930 Subject: [PATCH] Handle case where there are no messages --- .../thoughtcrime/securesms/database/MmsSmsDatabase.java | 7 +++++-- .../thoughtcrime/securesms/database/ThreadDatabase.java | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java b/app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java index be66d84db2..da4f39f0c1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/MmsSmsDatabase.java @@ -325,9 +325,12 @@ public class MmsSmsDatabase extends Database { String selection = MmsSmsColumns.THREAD_ID + " = " + threadId; try (Cursor cursor = queryTables(PROJECTION, selection, order, "1")) { - cursor.moveToFirst(); - return cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.NORMALIZED_DATE_SENT)); + if (cursor.moveToFirst()) { + return cursor.getLong(cursor.getColumnIndexOrThrow(MmsSmsColumns.NORMALIZED_DATE_SENT)); + } } + + return -1; } public Cursor getUnread() { 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 b7adab9320..ef3937d4d4 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java +++ b/app/src/main/java/org/thoughtcrime/securesms/database/ThreadDatabase.java @@ -939,7 +939,9 @@ public class ThreadDatabase extends Database { if (count > 0) { MmsSmsDatabase mmsSmsDatabase = DatabaseComponent.get(context).mmsSmsDatabase(); long messageTimestamp = mmsSmsDatabase.getLastMessageTimestamp(threadId); - lastMessage = mmsSmsDatabase.getMessageForTimestamp(messageTimestamp); + if (messageTimestamp > 0) { + lastMessage = mmsSmsDatabase.getMessageForTimestamp(messageTimestamp); + } } return new ThreadRecord(body, snippetUri, lastMessage, recipient, date, count,