Skip to content

Commit 765ef24

Browse files
committed
fix: unread indicator label presence in message list
1 parent 25f812a commit 765ef24

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

package/src/components/Channel/Channel.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ const ChannelWithContext = <
694694
const [deleted, setDeleted] = useState<boolean>(false);
695695
const [editing, setEditing] = useState<MessageType<StreamChatGenerics> | undefined>(undefined);
696696
const [error, setError] = useState<Error | boolean>(false);
697-
const [lastRead, setLastRead] = useState<ChannelContextValue<StreamChatGenerics>['lastRead']>();
697+
const lastRead = useRef<Date | undefined>(new Date());
698+
698699
const [quotedMessage, setQuotedMessage] = useState<MessageType<StreamChatGenerics> | undefined>(
699700
undefined,
700701
);
@@ -824,7 +825,6 @@ const ChannelWithContext = <
824825
useEffect(() => {
825826
let listener: ReturnType<typeof channel.on>;
826827
const initChannel = async () => {
827-
setLastRead(new Date());
828828
const unreadCount = channel.countUnread();
829829
if (!channel || !shouldSyncChannel || channel.offlineMode) {
830830
return;
@@ -950,14 +950,15 @@ const ChannelWithContext = <
950950
return;
951951
}
952952

953+
lastRead.current = new Date();
953954
if (doMarkReadRequest) {
954955
doMarkReadRequest(channel, updateChannelUnreadState ? setChannelUnreadState : undefined);
955956
} else {
956957
try {
957958
const response = await channel.markRead();
958959
if (updateChannelUnreadState && response && lastRead) {
959960
setChannelUnreadState({
960-
last_read: lastRead,
961+
last_read: lastRead.current,
961962
last_read_message_id: response?.event.last_read_message_id,
962963
unread_messages: 0,
963964
});
@@ -1725,7 +1726,7 @@ const ChannelWithContext = <
17251726
hideStickyDateHeader,
17261727
highlightedMessageId,
17271728
isChannelActive: shouldSyncChannel,
1728-
lastRead,
1729+
lastRead: lastRead.current,
17291730
loadChannelAroundMessage,
17301731
loadChannelAtFirstUnreadMessage,
17311732
loading: channelMessagesState.loading,
@@ -1738,7 +1739,7 @@ const ChannelWithContext = <
17381739
reloadChannel,
17391740
scrollToFirstUnreadThreshold,
17401741
setChannelUnreadState,
1741-
setLastRead,
1742+
setLastRead: () => {},
17421743
setTargetedMessage,
17431744
StickyHeader,
17441745
targetedMessage,

package/src/components/MessageList/MessageList.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,6 @@ const MessageListWithContext = <
430430
setIsUnreadNotificationOpen(false);
431431
return;
432432
}
433-
434433
if (unreadIndicatorDate && lastItemDate > unreadIndicatorDate) {
435434
setIsUnreadNotificationOpen(true);
436435
} else {
@@ -485,12 +484,13 @@ const MessageListWithContext = <
485484
* Effect to mark the channel as read when the user scrolls to the bottom of the message list.
486485
*/
487486
useEffect(() => {
488-
const listener: ReturnType<typeof channel.on> = channel.on('message.new', (event) => {
487+
const listener: ReturnType<typeof channel.on> = channel.on('message.new', async (event) => {
489488
const newMessageToCurrentChannel = event.cid === channel.cid;
490489
const mainChannelUpdated = !event.message?.parent_id || event.message?.show_in_channel;
491490

492491
if (newMessageToCurrentChannel && mainChannelUpdated && !scrollToBottomButtonVisible) {
493-
markRead();
492+
console.log('markRead');
493+
await markRead();
494494
}
495495
});
496496

0 commit comments

Comments
 (0)