diff --git a/src/components/left/main/ChatList.tsx b/src/components/left/main/ChatList.tsx index 2d2ae157a..9baeef413 100644 --- a/src/components/left/main/ChatList.tsx +++ b/src/components/left/main/ChatList.tsx @@ -161,7 +161,7 @@ const ChatList: FC = ({ onLoadMore={getMore} preloadBackwards={CHAT_LIST_SLICE} noFastList - isDisabled + noScrollRestore > {viewportIds && viewportIds.length && chatArrays ? ( renderChats() diff --git a/src/components/main/ForwardPicker.tsx b/src/components/main/ForwardPicker.tsx index bbdce6442..a1f1fe4c6 100644 --- a/src/components/main/ForwardPicker.tsx +++ b/src/components/main/ForwardPicker.tsx @@ -146,7 +146,7 @@ const ForwardPicker: FC = ({ className="picker-list custom-scroll" items={viewportIds} onLoadMore={getMore} - isDisabled={Boolean(filter)} + noScrollRestore={Boolean(filter)} > {viewportIds.map((id) => ( ; @@ -90,7 +94,6 @@ const Profile: FC = ({ chatId, profileState, onProfileStateChange, - isBasicGroup, isChannel, resolvedUserId, chatMessages, @@ -307,11 +310,10 @@ const Profile: FC = ({ ref={containerRef} className="Profile custom-scroll" itemSelector={buildInfiniteScrollItemSelector(resultType)} - items={viewportIds} + items={canRenderContents ? viewportIds : undefined} cacheBuster={cacheBuster} - sensitiveArea={500} - preloadBackwards={resultType === 'members' ? MEMBERS_SLICE : SHARED_MEDIA_SLICE} - isDisabled={resultType === 'members' && isBasicGroup} + sensitiveArea={PROFILE_SENSITIVE_AREA} + preloadBackwards={canRenderContents ? (resultType === 'members' ? MEMBERS_SLICE : SHARED_MEDIA_SLICE) : 0} noFastList onLoadMore={getMore} onScroll={handleScroll} @@ -370,7 +372,6 @@ export default memo(withGlobal( const { byId: usersById } = global.users; const isGroup = chat && isChatGroup(chat); - const isBasicGroup = chat && isChatBasicGroup(chat); const isChannel = chat && isChatChannel(chat); const hasMembersTab = isGroup || (isChannel && isChatAdmin(chat!)); const members = chat && chat.fullInfo && chat.fullInfo.members; @@ -384,7 +385,6 @@ export default memo(withGlobal( } return { - isBasicGroup, isChannel, resolvedUserId, chatMessages, diff --git a/src/components/ui/InfiniteScroll.tsx b/src/components/ui/InfiniteScroll.tsx index d2dffba9c..01f4ca4da 100644 --- a/src/components/ui/InfiniteScroll.tsx +++ b/src/components/ui/InfiniteScroll.tsx @@ -17,7 +17,7 @@ type OwnProps = { itemSelector?: string; preloadBackwards?: number; sensitiveArea?: number; - isDisabled?: boolean; + noScrollRestore?: boolean; noFastList?: boolean; cacheBuster?: any; children: any; @@ -36,8 +36,8 @@ const InfiniteScroll: FC = ({ itemSelector = DEFAULT_LIST_SELECTOR, preloadBackwards = DEFAULT_PRELOAD_BACKWARDS, sensitiveArea = DEFAULT_SENSITIVE_AREA, - // Used to turn off preloading and restoring scroll position (e.g. for frequently re-ordered chat or user lists) - isDisabled = false, + // Used to turn off restoring scroll position (e.g. for frequently re-ordered chat or user lists) + noScrollRestore = false, noFastList, // Used to re-query `listItemElements` if rendering is delayed by transition cacheBuster, @@ -70,19 +70,20 @@ const InfiniteScroll: FC = ({ // Initial preload useEffect(() => { - if (isDisabled || !loadMoreBackwards) { + if (!loadMoreBackwards) { return; } - if (!items || items.length < preloadBackwards) { + if (preloadBackwards > 0 && (!items || items.length < preloadBackwards)) { loadMoreBackwards(); - } else { - const { scrollHeight, clientHeight } = containerRef.current!; - if (clientHeight && scrollHeight <= clientHeight) { - loadMoreBackwards(); - } + return; } - }, [isDisabled, items, loadMoreBackwards, preloadBackwards]); + + const { scrollHeight, clientHeight } = containerRef.current!; + if (clientHeight && scrollHeight <= clientHeight) { + loadMoreBackwards(); + } + }, [items, loadMoreBackwards, preloadBackwards]); // Restore `scrollTop` after adding items useLayoutEffect(() => { @@ -91,7 +92,7 @@ const InfiniteScroll: FC = ({ state.listItemElements = container.querySelectorAll(itemSelector); - if (isDisabled) { + if (noScrollRestore) { return; } @@ -112,7 +113,7 @@ const InfiniteScroll: FC = ({ resetScroll(container, newScrollTop); state.isScrollTopJustUpdated = true; - }, [isDisabled, itemSelector, items, cacheBuster]); + }, [noScrollRestore, itemSelector, items, cacheBuster]); const handleScroll = useCallback((e: UIEvent) => { if (loadMoreForwards && loadMoreBackwards) { diff --git a/src/config.ts b/src/config.ts index 8f716c212..9b48c3b96 100644 --- a/src/config.ts +++ b/src/config.ts @@ -58,6 +58,7 @@ export const MEMBERS_LOAD_SLICE = 200; export const PINNED_MESSAGES_LIMIT = 50; export const BLOCKED_LIST_LIMIT = 100; export const PROFILE_PHOTOS_LIMIT = 40; +export const PROFILE_SENSITIVE_AREA = 500; export const TOP_CHAT_MESSAGES_PRELOAD_LIMIT = 25; export const ALL_CHATS_PRELOAD_DISABLED = false; diff --git a/src/modules/actions/api/chats.ts b/src/modules/actions/api/chats.ts index f0b90dbf5..23c3f14c4 100644 --- a/src/modules/actions/api/chats.ts +++ b/src/modules/actions/api/chats.ts @@ -673,7 +673,7 @@ addReducer('loadMoreMembers', (global) => { (async () => { const { chatId } = selectCurrentMessageList(global) || {}; const chat = chatId ? selectChat(global, chatId) : undefined; - if (!chat) { + if (!chat || isChatBasicGroup(chat)) { return; }