Handle case where there are no messages

This commit is contained in:
Andrew 2024-04-09 12:36:11 +09:30
parent c4309c9fba
commit 35d176c71e
2 changed files with 8 additions and 3 deletions

View File

@ -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() {

View File

@ -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,