Skip to content

Commit 5ec2d0c

Browse files
authored
Expose way to manually hide unread separator. (#6001)
* Expose MessageListViewModel#hideUnreadLabel to manually hide the unread label. * Revert wrong commit. * Add test. * Update CHANGELOG.md. * Rename hideUnreadLabel() to hideUnreadSeparator().
1 parent ea5e3cc commit 5ec2d0c

File tree

8 files changed

+62
-0
lines changed

8 files changed

+62
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
### ⬆️ Improved
5252

5353
### ✅ Added
54+
- Add `MessageListController.hideUnreadSeparator()` method to manually hide the unread separator. [#6001](https://github.com/GetStream/stream-chat-android/pull/6001)
5455

5556
### ⚠️ Changed
5657

@@ -62,6 +63,7 @@
6263
### ⬆️ Improved
6364

6465
### ✅ Added
66+
- Add `MessageListViewModel.hideUnreadSeparator()` method to manually hide the unread separator. [#6001](https://github.com/GetStream/stream-chat-android/pull/6001)
6567

6668
### ⚠️ Changed
6769

@@ -73,6 +75,7 @@
7375
### ⬆️ Improved
7476

7577
### ✅ Added
78+
- Add `MessageListViewModel.hideUnreadSeparator()` method to manually hide the unread separator. [#6001](https://github.com/GetStream/stream-chat-android/pull/6001)
7679

7780
### ⚠️ Changed
7881

stream-chat-android-compose/api/stream-chat-android-compose.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5036,6 +5036,7 @@ public final class io/getstream/chat/android/compose/viewmodel/messages/MessageL
50365036
public final fun getShowSystemMessagesState ()Z
50375037
public final fun getTypingUsers ()Ljava/util/List;
50385038
public final fun getUser ()Lkotlinx/coroutines/flow/StateFlow;
5039+
public final fun hideUnreadSeparator ()V
50395040
public final fun isInThread ()Z
50405041
public final fun isOnline ()Lkotlinx/coroutines/flow/Flow;
50415042
public final fun isShowingOverlay ()Z

stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/viewmodel/messages/MessageListViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,13 @@ public class MessageListViewModel(
548548
messageListController.scrollToFirstUnreadMessage()
549549
}
550550

551+
/**
552+
* Hides the unread label in the messages list (if already visible).
553+
*/
554+
public fun hideUnreadSeparator() {
555+
messageListController.hideUnreadSeparator()
556+
}
557+
551558
/**
552559
* Sets a handler which determines the position of a message inside a group.
553560
*

stream-chat-android-ui-common/api/stream-chat-android-ui-common.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ public final class io/getstream/chat/android/ui/common/feature/messages/list/Mes
730730
public final fun getUnreadCount ()Lkotlinx/coroutines/flow/StateFlow;
731731
public final fun getUnreadLabelState ()Lkotlinx/coroutines/flow/MutableStateFlow;
732732
public final fun getUser ()Lkotlinx/coroutines/flow/StateFlow;
733+
public final fun hideUnreadSeparator ()V
733734
public final fun isInThread ()Z
734735
public final fun isInsideSearch ()Lkotlinx/coroutines/flow/StateFlow;
735736
public final fun isStartedForThread ()Z

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,13 @@ public class MessageListController(
628628
unreadLabelState.value = unreadLabelState.value?.copy(buttonVisibility = false)
629629
}
630630

631+
/**
632+
* Hides the unread label in the messages list (if already visible).
633+
*/
634+
public fun hideUnreadSeparator() {
635+
unreadLabelState.value = null
636+
}
637+
631638
/**
632639
* Scrolls to the first unread message in the channel.
633640
*/

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,41 @@ internal class MessageListControllerTests {
966966
}
967967
}
968968

969+
@Test
970+
fun `When hideUnreadSeparator is called, unread label state is set to null`() = runTest {
971+
val user = randomUser()
972+
val firstMessage = randomMessage(id = "last_read_message_id", deletedAt = null, deletedForMe = false)
973+
val messages = listOf(
974+
firstMessage,
975+
randomMessage(id = "first_unread_message_id", deletedAt = null, deletedForMe = false),
976+
)
977+
val channelRead = MutableStateFlow(
978+
randomChannelUserRead(
979+
user = user,
980+
lastReadMessageId = firstMessage.id,
981+
unreadMessages = 1,
982+
),
983+
)
984+
val messagesState = MutableStateFlow(messages)
985+
val controller = Fixture()
986+
.givenCurrentUser(user)
987+
.givenChannelState(
988+
messagesState = messagesState,
989+
read = channelRead,
990+
)
991+
.get()
992+
993+
// Verify unread label is initially visible
994+
val unreadLabel = controller.unreadLabelState.value
995+
unreadLabel.shouldNotBeNull()
996+
997+
// Hide the unread label
998+
controller.hideUnreadSeparator()
999+
1000+
// Verify unread label state is now null
1001+
controller.unreadLabelState.value.shouldBeNull()
1002+
}
1003+
9691004
@Test
9701005
fun `When reactToMessage is called with skipPush set to true, sendReaction is invoked with skipPush true`() = runTest {
9711006
val messageId = randomString()

stream-chat-android-ui-components/api/stream-chat-android-ui-components.api

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4668,6 +4668,7 @@ public final class io/getstream/chat/android/ui/viewmodel/messages/MessageListVi
46684668
public final fun getUnreadCount ()Landroidx/lifecycle/LiveData;
46694669
public final fun getUnreadLabel ()Landroidx/lifecycle/LiveData;
46704670
public final fun getUser ()Landroidx/lifecycle/LiveData;
4671+
public final fun hideUnreadSeparator ()V
46714672
public final fun onEvent (Lio/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel$Event;)V
46724673
public final fun pauseAudioRecordingAttachments ()V
46734674
public final fun scrollToBottom (ILkotlin/jvm/functions/Function0;)V

stream-chat-android-ui-components/src/main/kotlin/io/getstream/chat/android/ui/viewmodel/messages/MessageListViewModel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ public class MessageListViewModel(
341341
messageListController.scrollToFirstUnreadMessage()
342342
}
343343

344+
/**
345+
* Hides the unread label in the messages list (if already visible).
346+
*/
347+
public fun hideUnreadSeparator() {
348+
messageListController.hideUnreadSeparator()
349+
}
350+
344351
/**
345352
* Sets the date separator handler which determines when to add date separators.
346353
* By default, a date separator will be added if the difference between two messages' dates is greater than 4h.

0 commit comments

Comments
 (0)