Skip to content

Commit

Permalink
fix: add undefined check for message when checking for isMessageUnread (
Browse files Browse the repository at this point in the history
#2518)

* fix: add undefined check for message when checking for isMessageUnread

* fix: add undefined check for message when checking for isMessageUnread

* fix: simplify case
  • Loading branch information
khushal87 authored May 21, 2024
1 parent 04cfc97 commit b0a2ce0
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions package/src/components/MessageList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,17 @@ const MessageListWithContext = <
const isLatestMessageSetShown = !!channel.state.messageSets.find(
(set) => set.isCurrent && set.isLatest,
);
const msg = processedMessageList?.[messageArrayIndex];

if (!isLatestMessageSetShown) {
const msg = processedMessageList?.[messageArrayIndex];
if (
channel.state.latestMessages.length !== 0 &&
unreadCount > channel.state.latestMessages.length
) {
return messageArrayIndex <= unreadCount - channel.state.latestMessages.length - 1;
} else if (lastRead && msg.created_at) {
}
// The `msg` can be undefined here, since `messageArrayIndex` can be out of bounds hence we add a check for `msg`.
else if (lastRead && msg?.created_at) {
return lastRead < msg.created_at;
}
return false;
Expand Down

0 comments on commit b0a2ce0

Please sign in to comment.