Change chat badge to show total unread message count.

This commit is contained in:
Greyson Parrelli
2022-11-17 15:26:06 -05:00
committed by Cody Henthorne
parent 2200af9c31
commit cdff0a61f2
5 changed files with 43 additions and 10 deletions

View File

@@ -512,6 +512,42 @@ class ThreadDatabase(context: Context, databaseHelper: SignalDatabase) : Databas
}
}
/**
* Returns the number of unread messages across all threads.
* Threads that are forced-unread count as 1.
*/
fun getUnreadMessageCount(): Long {
val allCount: Long = readableDatabase
.select("SUM($UNREAD_COUNT)")
.from(TABLE_NAME)
.run()
.use { cursor ->
if (cursor.moveToFirst()) {
cursor.getLong(0)
} else {
0
}
}
val forcedUnreadCount: Long = readableDatabase
.select("COUNT(*)")
.from(TABLE_NAME)
.where("$READ = ?", ReadStatus.FORCED_UNREAD.serialize())
.run()
.use { cursor ->
if (cursor.moveToFirst()) {
cursor.getLong(0)
} else {
0
}
}
return allCount + forcedUnreadCount
}
/**
* Returns the number of unread messages in a given thread.
*/
fun getUnreadMessageCount(threadId: Long): Long {
return readableDatabase
.select(UNREAD_COUNT)