Skip to content

Commit 57f72a8

Browse files
committed
Address PR review: visibility key, null-label guard, test strictness
- Messages.kt: switch the pill's separator-visibility check to compare LazyListItemInfo.key against the separator item's id, instead of comparing the message-list index against the LazyList index. The two diverge when non-message items (footerContent, the load-more indicator) precede itemsIndexed in the column, which would mis-judge pill visibility. - MessageListController.disableUnreadLabelButton: early-return when there is no active unread label. The previous code emitted false on showUnreadButtonState even on a no-op call (e.g. scrollToFirstUnreadMessage with a null unreadLabelState, or the XML SDK's HideUnreadLabel event with no active label), permanently latching the suppression for the controller's lifetime and hiding any future unread pill. - MessageListControllerTests: strengthen the post-read assertion to fail when unreadLabelState becomes null. The previous safe-call chain silently passed when the chain returned null, masking the regression the test is meant to guard.
1 parent 1c47c9e commit 57f72a8

3 files changed

Lines changed: 10 additions & 7 deletions

File tree

  • stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list
  • stream-chat-android-ui-common/src

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/messages/list/Messages.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,13 @@ internal fun BoxScope.DefaultMessagesHelperContent(
386386
)
387387

388388
val unreadLabel = messagesState.unreadLabel
389-
val unreadSeparatorIndex = remember(messages) {
390-
messages.indexOfFirst { it is UnreadSeparatorItemState }
389+
val unreadSeparatorId = remember(messages) {
390+
messages.firstOrNull { it is UnreadSeparatorItemState }?.id
391391
}
392-
val isUnreadSeparatorVisible by remember(unreadSeparatorIndex) {
392+
val isUnreadSeparatorVisible by remember(unreadSeparatorId, lazyListState) {
393393
derivedStateOf {
394-
unreadSeparatorIndex >= 0 &&
395-
lazyListState.layoutInfo.visibleItemsInfo.any { it.index == unreadSeparatorIndex }
394+
unreadSeparatorId != null &&
395+
lazyListState.layoutInfo.visibleItemsInfo.any { it.key == unreadSeparatorId }
396396
}
397397
}
398398
val scrollToFirstUnreadVisible = isScrollToFirstUnreadVisible(

stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,9 @@ public class MessageListController(
636636
* i.e. when the user leaves and re-enters the channel.
637637
*/
638638
public fun disableUnreadLabelButton() {
639+
val currentLabel = unreadLabelState.value ?: return
639640
showUnreadButtonState.tryEmit(false)
640-
unreadLabelState.value = unreadLabelState.value?.copy(buttonVisibility = false)
641+
unreadLabelState.value = currentLabel.copy(buttonVisibility = false)
641642
}
642643

643644
/**

stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/list/MessageListControllerTests.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1047,7 +1047,9 @@ internal class MessageListControllerTests {
10471047

10481048
// The recomputed label must keep buttonVisibility false; otherwise the pill returns
10491049
// immediately after the user dismisses or scrolls.
1050-
controller.unreadLabelState.value?.buttonVisibility?.`should be false`()
1050+
val unreadLabelAfterRead = controller.unreadLabelState.value
1051+
unreadLabelAfterRead.shouldNotBeNull()
1052+
unreadLabelAfterRead.buttonVisibility.`should be false`()
10511053
}
10521054

10531055
@Test

0 commit comments

Comments
 (0)