mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-23 11:15:44 +00:00
Change chat badge to show total unread message count.
This commit is contained in:
committed by
Cody Henthorne
parent
2200af9c31
commit
cdff0a61f2
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
) {
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user