Follow-up
This commit is contained in:
parent
b971b82406
commit
dc2dfe2fff
@ -161,7 +161,7 @@ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
onLoadMore={getMore}
|
onLoadMore={getMore}
|
||||||
preloadBackwards={CHAT_LIST_SLICE}
|
preloadBackwards={CHAT_LIST_SLICE}
|
||||||
noFastList
|
noFastList
|
||||||
isDisabled
|
noScrollRestore
|
||||||
>
|
>
|
||||||
{viewportIds && viewportIds.length && chatArrays ? (
|
{viewportIds && viewportIds.length && chatArrays ? (
|
||||||
renderChats()
|
renderChats()
|
||||||
|
|||||||
@ -146,7 +146,7 @@ const ForwardPicker: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
className="picker-list custom-scroll"
|
className="picker-list custom-scroll"
|
||||||
items={viewportIds}
|
items={viewportIds}
|
||||||
onLoadMore={getMore}
|
onLoadMore={getMore}
|
||||||
isDisabled={Boolean(filter)}
|
noScrollRestore={Boolean(filter)}
|
||||||
>
|
>
|
||||||
{viewportIds.map((id) => (
|
{viewportIds.map((id) => (
|
||||||
<ListItem
|
<ListItem
|
||||||
|
|||||||
@ -14,10 +14,15 @@ import {
|
|||||||
MediaViewerOrigin, ProfileState, ProfileTabType, SharedMediaType,
|
MediaViewerOrigin, ProfileState, ProfileTabType, SharedMediaType,
|
||||||
} from '../../types';
|
} from '../../types';
|
||||||
|
|
||||||
import { MEMBERS_SLICE, SHARED_MEDIA_SLICE, SLIDE_TRANSITION_DURATION } from '../../config';
|
import {
|
||||||
|
MEMBERS_SLICE,
|
||||||
|
PROFILE_SENSITIVE_AREA,
|
||||||
|
SHARED_MEDIA_SLICE,
|
||||||
|
SLIDE_TRANSITION_DURATION,
|
||||||
|
} from '../../config';
|
||||||
import { IS_TOUCH_ENV } from '../../util/environment';
|
import { IS_TOUCH_ENV } from '../../util/environment';
|
||||||
import {
|
import {
|
||||||
isChatAdmin, isChatBasicGroup, isChatChannel, isChatGroup, isChatPrivate,
|
isChatAdmin, isChatChannel, isChatGroup, isChatPrivate,
|
||||||
} from '../../modules/helpers';
|
} from '../../modules/helpers';
|
||||||
import {
|
import {
|
||||||
selectChatMessages,
|
selectChatMessages,
|
||||||
@ -57,7 +62,6 @@ type OwnProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
type StateProps = {
|
type StateProps = {
|
||||||
isBasicGroup?: boolean;
|
|
||||||
isChannel?: boolean;
|
isChannel?: boolean;
|
||||||
resolvedUserId?: number;
|
resolvedUserId?: number;
|
||||||
chatMessages?: Record<number, ApiMessage>;
|
chatMessages?: Record<number, ApiMessage>;
|
||||||
@ -90,7 +94,6 @@ const Profile: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
chatId,
|
chatId,
|
||||||
profileState,
|
profileState,
|
||||||
onProfileStateChange,
|
onProfileStateChange,
|
||||||
isBasicGroup,
|
|
||||||
isChannel,
|
isChannel,
|
||||||
resolvedUserId,
|
resolvedUserId,
|
||||||
chatMessages,
|
chatMessages,
|
||||||
@ -307,11 +310,10 @@ const Profile: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
ref={containerRef}
|
ref={containerRef}
|
||||||
className="Profile custom-scroll"
|
className="Profile custom-scroll"
|
||||||
itemSelector={buildInfiniteScrollItemSelector(resultType)}
|
itemSelector={buildInfiniteScrollItemSelector(resultType)}
|
||||||
items={viewportIds}
|
items={canRenderContents ? viewportIds : undefined}
|
||||||
cacheBuster={cacheBuster}
|
cacheBuster={cacheBuster}
|
||||||
sensitiveArea={500}
|
sensitiveArea={PROFILE_SENSITIVE_AREA}
|
||||||
preloadBackwards={resultType === 'members' ? MEMBERS_SLICE : SHARED_MEDIA_SLICE}
|
preloadBackwards={canRenderContents ? (resultType === 'members' ? MEMBERS_SLICE : SHARED_MEDIA_SLICE) : 0}
|
||||||
isDisabled={resultType === 'members' && isBasicGroup}
|
|
||||||
noFastList
|
noFastList
|
||||||
onLoadMore={getMore}
|
onLoadMore={getMore}
|
||||||
onScroll={handleScroll}
|
onScroll={handleScroll}
|
||||||
@ -370,7 +372,6 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
const { byId: usersById } = global.users;
|
const { byId: usersById } = global.users;
|
||||||
|
|
||||||
const isGroup = chat && isChatGroup(chat);
|
const isGroup = chat && isChatGroup(chat);
|
||||||
const isBasicGroup = chat && isChatBasicGroup(chat);
|
|
||||||
const isChannel = chat && isChatChannel(chat);
|
const isChannel = chat && isChatChannel(chat);
|
||||||
const hasMembersTab = isGroup || (isChannel && isChatAdmin(chat!));
|
const hasMembersTab = isGroup || (isChannel && isChatAdmin(chat!));
|
||||||
const members = chat && chat.fullInfo && chat.fullInfo.members;
|
const members = chat && chat.fullInfo && chat.fullInfo.members;
|
||||||
@ -384,7 +385,6 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isBasicGroup,
|
|
||||||
isChannel,
|
isChannel,
|
||||||
resolvedUserId,
|
resolvedUserId,
|
||||||
chatMessages,
|
chatMessages,
|
||||||
|
|||||||
@ -17,7 +17,7 @@ type OwnProps = {
|
|||||||
itemSelector?: string;
|
itemSelector?: string;
|
||||||
preloadBackwards?: number;
|
preloadBackwards?: number;
|
||||||
sensitiveArea?: number;
|
sensitiveArea?: number;
|
||||||
isDisabled?: boolean;
|
noScrollRestore?: boolean;
|
||||||
noFastList?: boolean;
|
noFastList?: boolean;
|
||||||
cacheBuster?: any;
|
cacheBuster?: any;
|
||||||
children: any;
|
children: any;
|
||||||
@ -36,8 +36,8 @@ const InfiniteScroll: FC<OwnProps> = ({
|
|||||||
itemSelector = DEFAULT_LIST_SELECTOR,
|
itemSelector = DEFAULT_LIST_SELECTOR,
|
||||||
preloadBackwards = DEFAULT_PRELOAD_BACKWARDS,
|
preloadBackwards = DEFAULT_PRELOAD_BACKWARDS,
|
||||||
sensitiveArea = DEFAULT_SENSITIVE_AREA,
|
sensitiveArea = DEFAULT_SENSITIVE_AREA,
|
||||||
// Used to turn off preloading and restoring scroll position (e.g. for frequently re-ordered chat or user lists)
|
// Used to turn off restoring scroll position (e.g. for frequently re-ordered chat or user lists)
|
||||||
isDisabled = false,
|
noScrollRestore = false,
|
||||||
noFastList,
|
noFastList,
|
||||||
// Used to re-query `listItemElements` if rendering is delayed by transition
|
// Used to re-query `listItemElements` if rendering is delayed by transition
|
||||||
cacheBuster,
|
cacheBuster,
|
||||||
@ -70,19 +70,20 @@ const InfiniteScroll: FC<OwnProps> = ({
|
|||||||
|
|
||||||
// Initial preload
|
// Initial preload
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isDisabled || !loadMoreBackwards) {
|
if (!loadMoreBackwards) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!items || items.length < preloadBackwards) {
|
if (preloadBackwards > 0 && (!items || items.length < preloadBackwards)) {
|
||||||
loadMoreBackwards();
|
loadMoreBackwards();
|
||||||
} else {
|
return;
|
||||||
const { scrollHeight, clientHeight } = containerRef.current!;
|
|
||||||
if (clientHeight && scrollHeight <= clientHeight) {
|
|
||||||
loadMoreBackwards();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, [isDisabled, items, loadMoreBackwards, preloadBackwards]);
|
|
||||||
|
const { scrollHeight, clientHeight } = containerRef.current!;
|
||||||
|
if (clientHeight && scrollHeight <= clientHeight) {
|
||||||
|
loadMoreBackwards();
|
||||||
|
}
|
||||||
|
}, [items, loadMoreBackwards, preloadBackwards]);
|
||||||
|
|
||||||
// Restore `scrollTop` after adding items
|
// Restore `scrollTop` after adding items
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
@ -91,7 +92,7 @@ const InfiniteScroll: FC<OwnProps> = ({
|
|||||||
|
|
||||||
state.listItemElements = container.querySelectorAll<HTMLDivElement>(itemSelector);
|
state.listItemElements = container.querySelectorAll<HTMLDivElement>(itemSelector);
|
||||||
|
|
||||||
if (isDisabled) {
|
if (noScrollRestore) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ const InfiniteScroll: FC<OwnProps> = ({
|
|||||||
resetScroll(container, newScrollTop);
|
resetScroll(container, newScrollTop);
|
||||||
|
|
||||||
state.isScrollTopJustUpdated = true;
|
state.isScrollTopJustUpdated = true;
|
||||||
}, [isDisabled, itemSelector, items, cacheBuster]);
|
}, [noScrollRestore, itemSelector, items, cacheBuster]);
|
||||||
|
|
||||||
const handleScroll = useCallback((e: UIEvent<HTMLDivElement>) => {
|
const handleScroll = useCallback((e: UIEvent<HTMLDivElement>) => {
|
||||||
if (loadMoreForwards && loadMoreBackwards) {
|
if (loadMoreForwards && loadMoreBackwards) {
|
||||||
|
|||||||
@ -58,6 +58,7 @@ export const MEMBERS_LOAD_SLICE = 200;
|
|||||||
export const PINNED_MESSAGES_LIMIT = 50;
|
export const PINNED_MESSAGES_LIMIT = 50;
|
||||||
export const BLOCKED_LIST_LIMIT = 100;
|
export const BLOCKED_LIST_LIMIT = 100;
|
||||||
export const PROFILE_PHOTOS_LIMIT = 40;
|
export const PROFILE_PHOTOS_LIMIT = 40;
|
||||||
|
export const PROFILE_SENSITIVE_AREA = 500;
|
||||||
|
|
||||||
export const TOP_CHAT_MESSAGES_PRELOAD_LIMIT = 25;
|
export const TOP_CHAT_MESSAGES_PRELOAD_LIMIT = 25;
|
||||||
export const ALL_CHATS_PRELOAD_DISABLED = false;
|
export const ALL_CHATS_PRELOAD_DISABLED = false;
|
||||||
|
|||||||
@ -673,7 +673,7 @@ addReducer('loadMoreMembers', (global) => {
|
|||||||
(async () => {
|
(async () => {
|
||||||
const { chatId } = selectCurrentMessageList(global) || {};
|
const { chatId } = selectCurrentMessageList(global) || {};
|
||||||
const chat = chatId ? selectChat(global, chatId) : undefined;
|
const chat = chatId ? selectChat(global, chatId) : undefined;
|
||||||
if (!chat) {
|
if (!chat || isChatBasicGroup(chat)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user