diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt index 82f7717a8d..5462112fd4 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelinePresenter.kt @@ -296,11 +296,7 @@ class TimelinePresenter( markerIdx = i break } - if (item is TimelineItem.Event && - !item.isMine && - item.origin != TimelineItemEventOrigin.PAGINATION && - item.content.isMessageContent() - ) { + if (item is TimelineItem.Event && item.isCountableNewMessage()) { unread++ } } @@ -464,11 +460,7 @@ class TimelinePresenter( var delta = 0 for (item in timelineItems) { if (item.identifier() == prevMostRecentItemIdValue) break - if (item is TimelineItem.Event && - item.origin != TimelineItemEventOrigin.PAGINATION && - !item.isMine && - item.content.isMessageContent() - ) { + if (item is TimelineItem.Event && item.isCountableNewMessage()) { delta++ } } @@ -519,6 +511,16 @@ private fun FocusRequestState.onFocusEventRender(): FocusRequestState { } } +/** + * Whether this event should be counted toward the unread / new-message badges: a user-facing + * message from someone other than the local user, that wasn't pulled in via back-pagination. + */ +private fun TimelineItem.Event.isCountableNewMessage(): Boolean { + return !isMine && + origin != TimelineItemEventOrigin.PAGINATION && + content.isMessageContent() +} + // Workaround for not having the server names available, get possible server names from the user ids of the room members private fun calculateServerNamesForRoom(room: JoinedRoom): List { // If we have no room members, return right ahead diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 51bd67a382..ce62f1ef9f 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -598,7 +598,7 @@ internal fun TimelineViewWithReadMarkerPreview() = ElementPreview { @PreviewsDayNight @Composable internal fun TimelineViewWithReadMarkerDotBadgesPreview() = ElementPreview { - TimelineViewWithReadMarker(unreadMessagesCount = 47, newMessagesCount = 99) + TimelineViewWithReadMarker(unreadMessagesCount = 47, newMessagesCount = 0) } @PreviewsDayNight diff --git a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt index 60e164df0f..6c8f9e9d8f 100644 --- a/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt +++ b/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt @@ -139,7 +139,8 @@ enum class FeatureFlags( JumpToUnread( key = "feature.jump_to_unread", title = "Jump to unread messages", - description = "Show a button to jump to the read marker, plus a count badge on the scroll-to-bottom button when new messages arrive while scrolled away.", + description = "Show a button to jump to the read marker, plus a count badge on the scroll-to-bottom button " + + "when new messages arrive while scrolled away.", defaultValue = { false }, isFinished = false, ),