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)

View File

@@ -14,13 +14,10 @@ class ConversationListTabRepository {
private val TAG = Log.tag(ConversationListTabRepository::class.java)
}
fun getNumberOfUnreadConversations(): Observable<Long> {
fun getNumberOfUnreadMessages(): Observable<Long> {
return Observable.create<Long> {
fun refresh() {
it.onNext(SignalDatabase.threads.getUnreadThreadCount())
val ids = SignalDatabase.threads.getUnreadThreadIdList()
Log.d(TAG, "Unread threads: { $ids }")
it.onNext(SignalDatabase.threads.getUnreadMessageCount())
}
val listener = DatabaseObserver.Observer {

View File

@@ -91,8 +91,8 @@ class ConversationListTabsFragment : Fragment(R.layout.conversation_list_tabs) {
runPillAnimation(150, chatsPill, storiesPill)
}
chatsUnreadIndicator.visible = state.unreadChatsCount > 0
chatsUnreadIndicator.text = formatCount(state.unreadChatsCount)
chatsUnreadIndicator.visible = state.unreadMessagesCount > 0
chatsUnreadIndicator.text = formatCount(state.unreadMessagesCount)
storiesUnreadIndicator.visible = state.unreadStoriesCount > 0
storiesUnreadIndicator.text = formatCount(state.unreadStoriesCount)

View File

@@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.stories.tabs
data class ConversationListTabsState(
val tab: ConversationListTab = ConversationListTab.CHATS,
val prevTab: ConversationListTab = ConversationListTab.STORIES,
val unreadChatsCount: Long = 0L,
val unreadMessagesCount: Long = 0L,
val unreadStoriesCount: Long = 0L,
val visibilityState: VisibilityState = VisibilityState()
) {

View File

@@ -23,8 +23,8 @@ class ConversationListTabsViewModel(repository: ConversationListTabRepository) :
val tabClickEvents: Observable<ConversationListTab> = internalTabClickEvents.filter { Stories.isFeatureEnabled() }
init {
disposables += repository.getNumberOfUnreadConversations().subscribe { unreadChats ->
store.update { it.copy(unreadChatsCount = unreadChats) }
disposables += repository.getNumberOfUnreadMessages().subscribe { unreadChats ->
store.update { it.copy(unreadMessagesCount = unreadChats) }
}
disposables += repository.getNumberOfUnseenStories().subscribe { unseenStories ->