Skip to content

Commit b89c18d

Browse files
committed
chore: replace ref with state for new line existence in GroupChannelMessageList
1 parent 0108698 commit b89c18d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

packages/uikit-react-native/src/domain/groupChannel/component/GroupChannelMessageList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ const GroupChannelMessageList = (props: GroupChannelProps['MessageList']) => {
294294
break;
295295
}
296296
case 'ON_MARKED_AS_UNREAD_BY_CURRENT_USER': {
297+
isNewLineExistInChannelRef.current = true;
297298
const foundUnreadFirstMessage = findUnreadFirstMessage(true);
298299
processNewLineVisibility(foundUnreadFirstMessage);
299300
setUnreadFirstMessage(foundUnreadFirstMessage);

packages/uikit-react-native/src/fragments/createGroupChannelFragment.tsx

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,12 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
9292
}
9393
});
9494

95-
const isNewLineExistInChannelRef = useRef(false);
95+
const [isNewLineExistInChannel, setIsNewLineExistInChannel] = useState(false);
9696
const hasSeenNewLineRef = useRef(false);
9797
const hasUserMarkedAsUnreadRef = useRef(false);
9898

9999
useEffect(() => {
100-
isNewLineExistInChannelRef.current =
101-
channel.myLastRead < (channel.lastMessage?.createdAt ?? Number.MIN_SAFE_INTEGER);
100+
setIsNewLineExistInChannel(channel.myLastRead < (channel.lastMessage?.createdAt ?? Number.MIN_SAFE_INTEGER));
102101
}, [channel.url]);
103102

104103
const onNewLineSeenChange = useFreshCallback((hasSeenNewLine: boolean) => {
@@ -114,7 +113,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
114113
if (
115114
!scrolledAwayFromBottom &&
116115
!hasUserMarkedAsUnreadRef.current &&
117-
(hasSeenNewLineRef.current || !isNewLineExistInChannelRef.current)
116+
(hasSeenNewLineRef.current || !isNewLineExistInChannel)
118117
) {
119118
confirmAndMarkAsRead(channels);
120119
}
@@ -154,7 +153,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
154153
}
155154
} else if (ctx?.source === GroupChannelEventSource.EVENT_CHANNEL_UNREAD) {
156155
if (ctx.userIds.includes(currentUser?.userId ?? '')) {
157-
isNewLineExistInChannelRef.current = true;
156+
setIsNewLineExistInChannel(true);
158157
groupChannelPubSub.publish({ type: 'ON_MARKED_AS_UNREAD_BY_CURRENT_USER' });
159158
}
160159
}
@@ -281,7 +280,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
281280
if (!value) {
282281
resetNewMessages();
283282
if (sbOptions.uikit.groupChannel.channel.enableMarkAsUnread) {
284-
if (!hasUserMarkedAsUnreadRef.current && (hasSeenNewLineRef.current || !isNewLineExistInChannelRef.current)) {
283+
if (!hasUserMarkedAsUnreadRef.current && (hasSeenNewLineRef.current || !isNewLineExistInChannel)) {
285284
confirmAndMarkAsRead([channel]);
286285
}
287286
}
@@ -331,7 +330,7 @@ const createGroupChannelFragment = (initModule?: Partial<GroupChannelModule>): G
331330
onPressMediaMessage={_onPressMediaMessage}
332331
flatListComponent={flatListComponent}
333332
flatListProps={memoizedFlatListProps}
334-
isNewLineExistInChannel={isNewLineExistInChannelRef.current}
333+
isNewLineExistInChannel={isNewLineExistInChannel}
335334
onNewLineSeenChange={onNewLineSeenChange}
336335
onUserMarkedAsUnreadChange={onUserMarkedAsUnreadChange}
337336
/>

0 commit comments

Comments
 (0)