Fix read receipts: mark visible messages as read immediately
This commit is contained in:
@@ -573,6 +573,7 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
||||
{
|
||||
root: scrollContainerRef.current,
|
||||
threshold: 0.1,
|
||||
rootMargin: '0px',
|
||||
}
|
||||
);
|
||||
|
||||
@@ -584,7 +585,26 @@ export default function ChatView({ onStartCall, onStartGroupCall }: { onStartCal
|
||||
unreadElements.forEach((el: Element) => {
|
||||
const id = el.getAttribute('data-message-id');
|
||||
if (id && !sentReadIdsRef.current.has(id)) {
|
||||
observer.observe(el);
|
||||
// Check if element is already visible
|
||||
const rect = el.getBoundingClientRect();
|
||||
const containerRect = scrollContainerRef.current!.getBoundingClientRect();
|
||||
const isVisible = rect.top >= containerRect.top && rect.bottom <= containerRect.bottom;
|
||||
|
||||
if (isVisible) {
|
||||
// Mark as read immediately without waiting for intersection
|
||||
const seqId = parseInt(el.getAttribute('data-sequence-id') || '0', 10);
|
||||
if (seqId > 0) {
|
||||
socket.emit('read_messages', {
|
||||
chatId: activeChat,
|
||||
lastReadMessageId: id,
|
||||
lastReadSequenceId: seqId,
|
||||
});
|
||||
useChatStore.getState().markRead(activeChat, user.id, seqId);
|
||||
sentReadIdsRef.current.add(id);
|
||||
}
|
||||
} else {
|
||||
observer.observe(el);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user