Fixes thread notifications instantly disappearing

This commit is contained in:
ericdecanini 2022-10-20 19:42:06 -04:00
parent dc7bff10c1
commit 1086ed367e
2 changed files with 39 additions and 22 deletions

View File

@ -114,14 +114,12 @@ internal class RoomSummaryUpdater @Inject constructor(
roomSummaryEntity.notificationCount = unreadNotifications?.notificationCount ?: 0 roomSummaryEntity.notificationCount = unreadNotifications?.notificationCount ?: 0
roomSummaryEntity.threadHighlightCount = unreadThreadNotifications roomSummaryEntity.threadHighlightCount = unreadThreadNotifications
?.map { it.value.highlightCount.takeIf { count -> (count ?: 0) > 0 } } ?.count { (it.value.highlightCount ?: 0) > 0 }
?.size
?: 0
roomSummaryEntity.threadNotificationCount = unreadThreadNotifications
?.map { it.value.notificationCount.takeIf { count -> (count ?: 0) > 0 } }
?.size
?: 0 ?: 0
roomSummaryEntity.threadNotificationCount = unreadThreadNotifications
?.count { (it.value.notificationCount ?: 0) > 0 }
?: 0
if (membership != null) { if (membership != null) {
roomSummaryEntity.membership = membership roomSummaryEntity.membership = membership

View File

@ -18,6 +18,7 @@ package im.vector.app.features.home.room.detail
import android.net.Uri import android.net.Uri
import androidx.annotation.IdRes import androidx.annotation.IdRes
import androidx.lifecycle.asFlow
import com.airbnb.mvrx.Async import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Loading
@ -407,22 +408,40 @@ class TimelineViewModel @AssistedInject constructor(
* Observe local unread threads. * Observe local unread threads.
*/ */
private fun observeLocalThreadNotifications() { private fun observeLocalThreadNotifications() {
if (room == null) return val threadNotificationsSupported = session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreadReadReceiptsAndNotifications
room.flow() if (threadNotificationsSupported) {
.liveLocalUnreadThreadList() room?.getRoomSummaryLive()
.execute { ?.asFlow()
val threadList = it.invoke() ?.onEach {
val isUserMentioned = threadList?.firstOrNull { threadRootEvent -> it.getOrNull()?.let {
threadRootEvent.root.threadDetails?.threadNotificationState == ThreadNotificationState.NEW_HIGHLIGHTED_MESSAGE setState {
}?.let { true } ?: false copy(
val numberOfLocalUnreadThreads = threadList?.size ?: 0 threadNotificationBadgeState = ThreadNotificationBadgeState(
copy( numberOfLocalUnreadThreads = it.threadNotificationCount + it.threadHighlightCount,
threadNotificationBadgeState = ThreadNotificationBadgeState( isUserMentioned = it.threadHighlightCount > 0,
numberOfLocalUnreadThreads = numberOfLocalUnreadThreads, )
isUserMentioned = isUserMentioned )
) }
) }
} }
?.launchIn(viewModelScope)
} else {
room?.flow()
?.liveLocalUnreadThreadList()
?.execute {
val threadList = it.invoke()
val isUserMentioned = threadList?.firstOrNull { threadRootEvent ->
threadRootEvent.root.threadDetails?.threadNotificationState == ThreadNotificationState.NEW_HIGHLIGHTED_MESSAGE
}?.let { true } ?: false
val numberOfLocalUnreadThreads = threadList?.size ?: 0
copy(
threadNotificationBadgeState = ThreadNotificationBadgeState(
numberOfLocalUnreadThreads = numberOfLocalUnreadThreads,
isUserMentioned = isUserMentioned
)
)
}
}
} }
override fun handle(action: RoomDetailAction) { override fun handle(action: RoomDetailAction) {