Skip to content

Commit eb744a0

Browse files
authored
Fix: Mark as read definitely when receiving message (#373)
* Add 10px as a buffer when calculating if the scroll reached the bottom
1 parent b37e35b commit eb744a0

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/smart-components/Channel/components/MessageList/index.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,26 @@ const MessageList: React.FC<MessageListProps> = (props: MessageListProps) => {
8484
});
8585
}
8686

87-
// save the lastest scroll bottom value
87+
// Save the lastest scroll bottom value
8888
if (scrollRef?.current) {
8989
const current = scrollRef?.current;
9090
setScrollBottom(current.scrollHeight - current.scrollTop - current.offsetHeight)
9191
}
9292

93-
// do this later
94-
setTimeout(() => {
95-
// mark as read if scroll is at end
96-
if (!disableMarkAsRead && clientHeight + scrollTop === scrollHeight) {
93+
if (!disableMarkAsRead && isAboutSame(clientHeight + scrollTop, scrollHeight, 10)) {
94+
// Mark as read if scroll is at end
95+
setTimeout(() => {
9796
messagesDispatcher({
9897
type: messageActionTypes.MARK_AS_READ,
9998
payload: { channel: currentGroupChannel },
10099
});
101100
try {
102-
currentGroupChannel?.markAsRead();
101+
currentGroupChannel?.markAsRead?.();
103102
} catch {
104103
//
105104
}
106-
}
107-
}, 500);
105+
}, 500);
106+
}
108107
};
109108

110109
const onClickScrollBot = () => {

src/smart-components/Channel/context/hooks/useHandleChannelEvents.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ function useHandleChannelEvents({
5656
let scrollToEnd = false;
5757
try {
5858
const { current } = scrollRef;
59-
scrollToEnd = current.offsetHeight + current.scrollTop >= current.scrollHeight;
59+
scrollToEnd = current.offsetHeight + current.scrollTop >= current.scrollHeight - 10;
60+
// 10 is a buffer
6061
} catch (error) {
6162
//
6263
}

src/ui/MessageStatus/index.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import './index.scss';
2-
import React, { useMemo } from 'react';
2+
import React from 'react';
33
import format from 'date-fns/format';
44
import { GroupChannel } from '@sendbird/chat/groupChannel';
55
import { FileMessage, UserMessage } from '@sendbird/chat/message';
@@ -29,9 +29,7 @@ export default function MessageStatus({
2929
channel,
3030
}: MessageStatusProps): React.ReactElement {
3131
const { dateLocale } = useLocalization();
32-
const status = useMemo(() => (
33-
getOutgoingMessageState(channel, message)
34-
), [channel, message]);
32+
const status = getOutgoingMessageState(channel, message);
3533
const hideMessageStatusIcon = channel?.isGroupChannel?.() && (
3634
(channel.isSuper || channel.isPublic || channel.isBroadcast)
3735
&& !(status === OutgoingMessageStates.PENDING || status === OutgoingMessageStates.FAILED)

0 commit comments

Comments
 (0)