Skip to content

Commit

Permalink
fix: Room history scroll position (#29335)
Browse files Browse the repository at this point in the history
Co-authored-by: gabriellsh <[email protected]>
  • Loading branch information
yash-rajpal and gabriellsh authored Jun 6, 2023
1 parent 059a92e commit cebe359
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/pretty-dots-leave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': minor
---

fix: Room history scrollbar position
7 changes: 5 additions & 2 deletions apps/meteor/client/views/room/components/body/RoomBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import UploadProgressIndicator from './UploadProgressIndicator';
import ComposerContainer from './composer/ComposerContainer';
import { useFileUploadDropTarget } from './hooks/useFileUploadDropTarget';
import { useReadMessageWindowEvents } from './hooks/useReadMessageWindowEvents';
import { useRestoreScrollPosition } from './hooks/useRestoreScrollPosition';
import { useRetentionPolicy } from './hooks/useRetentionPolicy';
import { useUnreadMessages } from './hooks/useUnreadMessages';

Expand Down Expand Up @@ -403,10 +404,10 @@ const RoomBody = (): ReactElement => {
sendToBottom();
}
wrapper.removeEventListener('MessageGroup', afterMessageGroup);

wrapper.addEventListener('scroll', handleWrapperScroll);
};

wrapper.addEventListener('scroll', handleWrapperScroll);

wrapper.addEventListener('MessageGroup', afterMessageGroup);

return () => {
Expand All @@ -415,6 +416,8 @@ const RoomBody = (): ReactElement => {
};
}, [room._id, sendToBottom]);

useRestoreScrollPosition(room._id, scrollMessageList, sendToBottom);

useEffect(() => {
const wrapper = wrapperRef.current;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { IRoom } from '@rocket.chat/core-typings';
import { useEffect } from 'react';

import type { MessageListContextValue } from '../../../../../components/message/list/MessageListContext';
import { RoomManager } from '../../../../../lib/RoomManager';

export function useRestoreScrollPosition(
roomId: IRoom['_id'],
scrollMessageList: Exclude<MessageListContextValue['scrollMessageList'], undefined>,
sendToBottom: () => void,
) {
useEffect(() => {
const store = RoomManager.getStore(roomId);

if (store?.scroll && !store.atBottom) {
scrollMessageList(() => {
return { left: 30, top: store.scroll };
});
} else {
sendToBottom();
}
}, [roomId, scrollMessageList, sendToBottom]);
}

0 comments on commit cebe359

Please sign in to comment.