Skip to content

Commit

Permalink
refactor(flat-components): scroll to chat list bottom smartly (#2128)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyrious committed Mar 7, 2024
1 parent 01ab0a5 commit b1b4a5c
Showing 1 changed file with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,15 @@ export const ChatMessageList = /* @__PURE__ */ observer<ChatMessageListProps>(
latestMessage!.timestamp > prev.latestMessage.timestamp
) {
// user sent a new message
// scroll to the bottom
setScrollToIndex(messageCount - 1);
// scroll to the bottom only if the user is the last message's sender or is at bottom
if (latestMessage?.senderID === userUUID) {
setScrollToIndex(messageCount - 1);
} else {
const div = document.querySelector(".chat-message-list");
if (div && div.scrollTop + div.clientHeight >= div.scrollHeight - 30) {
setScrollToIndex(messageCount - 1);
}
}
} else {
// history messages loaded
// stay at the last position
Expand Down Expand Up @@ -157,7 +164,7 @@ export const ChatMessageList = /* @__PURE__ */ observer<ChatMessageListProps>(
{() => (
<List
ref={registerChild}
className="fancy-scrollbar"
className="chat-message-list fancy-scrollbar"
height={height}
rowCount={messages.length}
rowHeight={cellCache.rowHeight}
Expand Down

0 comments on commit b1b4a5c

Please sign in to comment.