Chat List: Fix missing archived chats in folders
This commit is contained in:
parent
d7011bf24f
commit
5ed545aa0b
@ -45,7 +45,9 @@ type StateProps = {
|
|||||||
notifyExceptions?: Record<number, NotifyException>;
|
notifyExceptions?: Record<number, NotifyException>;
|
||||||
};
|
};
|
||||||
|
|
||||||
type DispatchProps = Pick<GlobalActions, 'loadMoreChats' | 'preloadTopChatMessages' | 'openChat' | 'openNextChat'>;
|
type DispatchProps = Pick<GlobalActions, (
|
||||||
|
'loadMoreChats' | 'preloadTopChatMessages' | 'preloadArchivedChats' | 'openChat' | 'openNextChat'
|
||||||
|
)>;
|
||||||
|
|
||||||
enum FolderTypeToListType {
|
enum FolderTypeToListType {
|
||||||
'all' = 'active',
|
'all' = 'active',
|
||||||
@ -68,6 +70,7 @@ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
onScreenSelect,
|
onScreenSelect,
|
||||||
loadMoreChats,
|
loadMoreChats,
|
||||||
preloadTopChatMessages,
|
preloadTopChatMessages,
|
||||||
|
preloadArchivedChats,
|
||||||
openChat,
|
openChat,
|
||||||
openNextChat,
|
openNextChat,
|
||||||
}) => {
|
}) => {
|
||||||
@ -122,8 +125,9 @@ const ChatList: FC<OwnProps & StateProps & DispatchProps> = ({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (lastSyncTime && folderType === 'all') {
|
if (lastSyncTime && folderType === 'all') {
|
||||||
preloadTopChatMessages();
|
preloadTopChatMessages();
|
||||||
|
preloadArchivedChats();
|
||||||
}
|
}
|
||||||
}, [lastSyncTime, folderType, preloadTopChatMessages]);
|
}, [lastSyncTime, folderType, preloadTopChatMessages, preloadArchivedChats]);
|
||||||
|
|
||||||
const getAnimationType = useChatAnimationType(orderDiffById);
|
const getAnimationType = useChatAnimationType(orderDiffById);
|
||||||
|
|
||||||
@ -255,6 +259,7 @@ export default memo(withGlobal<OwnProps>(
|
|||||||
(setGlobal, actions): DispatchProps => pick(actions, [
|
(setGlobal, actions): DispatchProps => pick(actions, [
|
||||||
'loadMoreChats',
|
'loadMoreChats',
|
||||||
'preloadTopChatMessages',
|
'preloadTopChatMessages',
|
||||||
|
'preloadArchivedChats',
|
||||||
'openChat',
|
'openChat',
|
||||||
'openNextChat',
|
'openNextChat',
|
||||||
]),
|
]),
|
||||||
|
|||||||
@ -452,7 +452,8 @@ export type ActionTypes = (
|
|||||||
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' |
|
'setAuthPhoneNumber' | 'setAuthCode' | 'setAuthPassword' | 'signUp' | 'returnToAuthPhoneNumber' | 'signOut' |
|
||||||
'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' |
|
'setAuthRememberMe' | 'clearAuthError' | 'uploadProfilePhoto' | 'goToAuthQrCode' | 'clearCache' |
|
||||||
// chats
|
// chats
|
||||||
'preloadTopChatMessages' | 'loadChats' | 'loadMoreChats' | 'openChat' | 'openChatWithInfo' | 'openLinkedChat' |
|
'preloadTopChatMessages' | 'preloadArchivedChats' | 'loadChats' | 'loadMoreChats' | 'openChat' |
|
||||||
|
'openChatWithInfo' | 'openLinkedChat' |
|
||||||
'openSupportChat' | 'openTipsChat' | 'focusMessageInComments' |
|
'openSupportChat' | 'openTipsChat' | 'focusMessageInComments' |
|
||||||
'loadFullChat' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' |
|
'loadFullChat' | 'loadTopChats' | 'requestChatUpdate' | 'updateChatMutedState' |
|
||||||
'joinChannel' | 'leaveChannel' | 'deleteChannel' | 'toggleChatPinned' | 'toggleChatArchived' | 'toggleChatUnread' |
|
'joinChannel' | 'leaveChannel' | 'deleteChannel' | 'toggleChatPinned' | 'toggleChatArchived' | 'toggleChatUnread' |
|
||||||
|
|||||||
@ -47,11 +47,12 @@ import {
|
|||||||
} from '../../helpers';
|
} from '../../helpers';
|
||||||
import { processDeepLink } from '../../../util/deeplink';
|
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
|
// We expect this ID does not exist
|
||||||
const TMP_CHAT_ID = -1;
|
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 runThrottledForLoadTopChats = throttle((cb) => cb(), 3000, true);
|
||||||
const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true);
|
const runDebouncedForLoadFullChat = debounce((cb) => cb(), 500, false, true);
|
||||||
|
|
||||||
@ -60,7 +61,7 @@ addReducer('preloadTopChatMessages', (global, actions) => {
|
|||||||
const preloadedChatIds: number[] = [];
|
const preloadedChatIds: number[] = [];
|
||||||
|
|
||||||
for (let i = 0; i < TOP_CHAT_MESSAGES_PRELOAD_LIMIT; i++) {
|
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 {
|
const {
|
||||||
byId,
|
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) => {
|
addReducer('loadFullChat', (global, actions, payload) => {
|
||||||
const { chatId, force } = payload!;
|
const { chatId, force } = payload!;
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
@ -279,7 +298,7 @@ addReducer('joinChannel', (global, actions, payload) => {
|
|||||||
|
|
||||||
addReducer('deleteChatUser', (global, actions, payload) => {
|
addReducer('deleteChatUser', (global, actions, payload) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { chatId, userId } : { chatId: number; userId: number } = payload!;
|
const { chatId, userId }: { chatId: number; userId: number } = payload!;
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
const user = selectUser(global, userId);
|
const user = selectUser(global, userId);
|
||||||
if (!chat || !user) {
|
if (!chat || !user) {
|
||||||
@ -296,7 +315,7 @@ addReducer('deleteChatUser', (global, actions, payload) => {
|
|||||||
|
|
||||||
addReducer('deleteChat', (global, actions, payload) => {
|
addReducer('deleteChat', (global, actions, payload) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { chatId } : { chatId: number } = payload!;
|
const { chatId }: { chatId: number } = payload!;
|
||||||
const chat = selectChat(global, chatId);
|
const chat = selectChat(global, chatId);
|
||||||
if (!chat) {
|
if (!chat) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user