Chat List: Fix missing archived chats in folders

This commit is contained in:
Alexander Zinchuk 2021-09-24 17:05:41 +03:00
parent d7011bf24f
commit 5ed545aa0b
3 changed files with 33 additions and 8 deletions

View File

@ -45,7 +45,9 @@ type StateProps = {
notifyExceptions?: Record<number, NotifyException>;
};
type DispatchProps = Pick<GlobalActions, 'loadMoreChats' | 'preloadTopChatMessages' | 'openChat' | 'openNextChat'>;
type DispatchProps = Pick<GlobalActions, (
'loadMoreChats' | 'preloadTopChatMessages' | 'preloadArchivedChats' | 'openChat' | 'openNextChat'
)>;
enum FolderTypeToListType {
'all' = 'active',
@ -68,6 +70,7 @@ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({
onScreenSelect,
loadMoreChats,
preloadTopChatMessages,
preloadArchivedChats,
openChat,
openNextChat,
}) => {
@ -122,8 +125,9 @@ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({
useEffect(() => {
if (lastSyncTime && folderType === 'all') {
preloadTopChatMessages();
preloadArchivedChats();
}
}, [lastSyncTime, folderType, preloadTopChatMessages]);
}, [lastSyncTime, folderType, preloadTopChatMessages, preloadArchivedChats]);
const getAnimationType = useChatAnimationType(orderDiffById);
@ -255,6 +259,7 @@ export default memo(withGlobal<OwnProps>(
(setGlobal, actions): DispatchProps => pick(actions, [
'loadMoreChats',
'preloadTopChatMessages',
'preloadArchivedChats',
'openChat',
'openNextChat',
]),

View File

@ -452,7 +452,8 @@ export type ActionTypes = (
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' |
'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' |
// chats
'preloadTopChatMessages' | 'loadChats' | 'loadMoreChats' | 'openChat' | 'openChatWithInfo' | 'openLinkedChat' |
'preloadTopChatMessages' | 'preloadArchivedChats' | 'loadChats' | 'loadMoreChats' | 'openChat' |
'openChatWithInfo' | 'openLinkedChat' |
'openSupportChat' | 'openTipsChat' | 'focusMessageInComments' |
'loadFullChat' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' |
'joinChannel' | 'leaveChannel' | 'deleteChannel' | 'toggleChatPinned' | 'toggleChatArchived' | 'toggleChatUnread' |

View File

@ -47,11 +47,12 @@ import {
} from '../../helpers';
import { processDeepLink } from '../../../util/deeplink';
const TOP_CHATS_PRELOAD_PAUSE = 100;
const TOP_CHAT_MESSAGES_PRELOAD_INTERVAL = 100;
const CHATS_PRELOAD_INTERVAL = 300;
// We expect this ID does not exist
const TMP_CHAT_ID = -1;
const runThrottledForLoadChats = throttle((cb) => cb(), 1000, true);
const runThrottledForLoadChats = throttle((cb) => cb(), CHATS_PRELOAD_INTERVAL, true);
const runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true);
const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true);
@ -60,7 +61,7 @@ addReducer('preloadTopChatMessages', (global, actions) => {
const preloadedChatIds: number[] = [];
for (let i = 0; i < TOP_CHAT_MESSAGES_PRELOAD_LIMIT; i++) {
await pause(TOP_CHATS_PRELOAD_PAUSE);
await pause(TOP_CHAT_MESSAGES_PRELOAD_INTERVAL);
const {
byId,
@ -207,6 +208,24 @@ addReducer('loadMoreChats', (global, actions, payload) => {
}
});
addReducer('preloadArchivedChats', () => {
(async () => {
while (!getGlobal().chats.isFullyLoaded.archived) {
const currentGlobal = getGlobal();
const listIds = currentGlobal.chats.listIds.archived;
const oldestChat = listIds
? listIds
.map((id) => currentGlobal.chats.byId[id])
.filter((chat) => Boolean(chat?.lastMessage) && !selectIsChatPinned(currentGlobal, chat.id))
.sort((chat1, chat2) => (chat1.lastMessage!.date - chat2.lastMessage!.date))[0]
: undefined;
await loadChats('archived', oldestChat?.id, oldestChat?.lastMessage!.date);
await pause(CHATS_PRELOAD_INTERVAL);
}
})();
});
addReducer('loadFullChat', (global, actions, payload) => {
const { chatId, force } = payload!;
const chat = selectChat(global, chatId);
@ -279,7 +298,7 @@ addReducer('joinChannel', (global, actions, payload) => {
addReducer('deleteChatUser', (global, actions, payload) => {
(async () => {
const { chatId, userId } : { chatId: number; userId: number } = payload!;
const { chatId, userId }: { chatId: number; userId: number } = payload!;
const chat = selectChat(global, chatId);
const user = selectUser(global, userId);
if (!chat || !user) {
@ -296,7 +315,7 @@ addReducer('deleteChatUser', (global, actions, payload) => {
addReducer('deleteChat', (global, actions, payload) => {
(async () => {
const { chatId } : { chatId: number } = payload!;
const { chatId }: { chatId: number } = payload!;
const chat = selectChat(global, chatId);
if (!chat) {
return;