Code improvements

This commit is contained in:
ericdecanini 2022-10-24 10:31:55 -04:00
parent 35be56a44a
commit 3673e720fa
4 changed files with 15 additions and 12 deletions

View File

@ -98,11 +98,11 @@ data class RoomSummary(
*/ */
val highlightCount: Int = 0, val highlightCount: Int = 0,
/** /**
* Number of threads with unread messages in this room * Number of threads with unread messages in this room.
*/ */
val threadNotificationCount: Int = 0, val threadNotificationCount: Int = 0,
/** /**
* Number of threads with highlighted messages in this room * Number of threads with highlighted messages in this room.
*/ */
val threadHighlightCount: Int = 0, val threadHighlightCount: Int = 0,
/** /**

View File

@ -48,7 +48,7 @@ data class RoomSync(
@Json(name = "unread_notifications") val unreadNotifications: RoomSyncUnreadNotifications? = null, @Json(name = "unread_notifications") val unreadNotifications: RoomSyncUnreadNotifications? = null,
/** /**
* The count of threads with unread notifications (not the total # of notifications in all threads) * The count of threads with unread notifications (not the total # of notifications in all threads).
*/ */
@Json(name = "unread_thread_notifications") val unreadThreadNotifications: Map<String, RoomSyncUnreadThreadNotifications>? = null, @Json(name = "unread_thread_notifications") val unreadThreadNotifications: Map<String, RoomSyncUnreadThreadNotifications>? = null,

View File

@ -75,7 +75,9 @@ internal data class RoomEventFilter(
*/ */
@Json(name = "contains_url") val containsUrl: Boolean? = null, @Json(name = "contains_url") val containsUrl: Boolean? = null,
/** /**
* If true, enables lazy-loading of membership events. See Lazy-loading room members for more information. Defaults to false. * If true, enables lazy-loading of membership events.
* See Lazy-loading room members for more information.
* Defaults to false.
*/ */
@Json(name = "lazy_load_members") val lazyLoadMembers: Boolean? = null, @Json(name = "lazy_load_members") val lazyLoadMembers: Boolean? = null,
/** /**

View File

@ -408,11 +408,12 @@ 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 val threadNotificationsSupported = session.homeServerCapabilitiesService().getHomeServerCapabilities().canUseThreadReadReceiptsAndNotifications
if (threadNotificationsSupported) { if (threadNotificationsSupported) {
room?.getRoomSummaryLive() room.getRoomSummaryLive()
?.asFlow() .asFlow()
?.onEach { .onEach {
it.getOrNull()?.let { it.getOrNull()?.let {
setState { setState {
copy( copy(
@ -424,15 +425,15 @@ class TimelineViewModel @AssistedInject constructor(
} }
} }
} }
?.launchIn(viewModelScope) .launchIn(viewModelScope)
} else { } else {
room?.flow() room.flow()
?.liveLocalUnreadThreadList() .liveLocalUnreadThreadList()
?.execute { .execute {
val threadList = it.invoke() val threadList = it.invoke()
val isUserMentioned = threadList?.firstOrNull { threadRootEvent -> val isUserMentioned = threadList?.firstOrNull { threadRootEvent ->
threadRootEvent.root.threadDetails?.threadNotificationState == ThreadNotificationState.NEW_HIGHLIGHTED_MESSAGE threadRootEvent.root.threadDetails?.threadNotificationState == ThreadNotificationState.NEW_HIGHLIGHTED_MESSAGE
}?.let { true } ?: false } != null
val numberOfLocalUnreadThreads = threadList?.size ?: 0 val numberOfLocalUnreadThreads = threadList?.size ?: 0
copy( copy(
threadNotificationBadgeState = ThreadNotificationBadgeState( threadNotificationBadgeState = ThreadNotificationBadgeState(