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.threadHighlightCount = unreadThreadNotifications
?.map { it.value.highlightCount.takeIf { count -> (count ?: 0) > 0 } }
?.size
?: 0
roomSummaryEntity.threadNotificationCount = unreadThreadNotifications
?.map { it.value.notificationCount.takeIf { count -> (count ?: 0) > 0 } }
?.size
?.count { (it.value.highlightCount ?: 0) > 0 }
?: 0
roomSummaryEntity.threadNotificationCount = unreadThreadNotifications
?.count { (it.value.notificationCount ?: 0) > 0 }
?: 0
if (membership != null) {
roomSummaryEntity.membership = membership

View File

@ -18,6 +18,7 @@ package im.vector.app.features.home.room.detail
import android.net.Uri
import androidx.annotation.IdRes
import androidx.lifecycle.asFlow
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.Loading
@ -407,22 +408,40 @@ class TimelineViewModel @AssistedInject constructor(
* Observe local unread threads.
*/
private fun observeLocalThreadNotifications() {
if (room == null) return
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
)
)
}
val threadNotificationsSupported = session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreadReadReceiptsAndNotifications
if (threadNotificationsSupported) {
room?.getRoomSummaryLive()
?.asFlow()
?.onEach {
it.getOrNull()?.let {
setState {
copy(
threadNotificationBadgeState = ThreadNotificationBadgeState(
numberOfLocalUnreadThreads = it.threadNotificationCount + it.threadHighlightCount,
isUserMentioned = it.threadHighlightCount > 0,
)
)
}
}
}
?.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) {