Folder: Fix stuck count (#6746)
This commit is contained in:
parent
019c4a5145
commit
08337bf397
@ -82,6 +82,7 @@ let prevGlobal: {
|
|||||||
usersById: Record<string, ApiUser>;
|
usersById: Record<string, ApiUser>;
|
||||||
notifyDefaults?: Record<ApiNotifyPeerType, ApiPeerNotifySettings>;
|
notifyDefaults?: Record<ApiNotifyPeerType, ApiPeerNotifySettings>;
|
||||||
notifyExceptions?: Record<number, ApiPeerNotifySettings>;
|
notifyExceptions?: Record<number, ApiPeerNotifySettings>;
|
||||||
|
threadsByChatId: Record<string, GlobalState['messages']['byChatId'][string]['threadsById'] | undefined>;
|
||||||
} = initials.prevGlobal;
|
} = initials.prevGlobal;
|
||||||
|
|
||||||
let prepared: {
|
let prepared: {
|
||||||
@ -239,6 +240,17 @@ function updateFolderManager(global: GlobalState) {
|
|||||||
const areUsersChanged = global.users.byId !== prevGlobal.usersById;
|
const areUsersChanged = global.users.byId !== prevGlobal.usersById;
|
||||||
const areNotifyDefaultsChanged = selectNotifyDefaults(global) !== prevGlobal.notifyDefaults;
|
const areNotifyDefaultsChanged = selectNotifyDefaults(global) !== prevGlobal.notifyDefaults;
|
||||||
const areNotifyExceptionsChanged = global.chats.notifyExceptionById !== prevGlobal.notifyExceptions;
|
const areNotifyExceptionsChanged = global.chats.notifyExceptionById !== prevGlobal.notifyExceptions;
|
||||||
|
const allRelevantChatIds = unique([
|
||||||
|
...global.chats.listIds.active || [],
|
||||||
|
...global.chats.listIds.archived || [],
|
||||||
|
...global.chats.listIds.saved || [],
|
||||||
|
...prevGlobal.allFolderListIds || [],
|
||||||
|
...prevGlobal.archivedFolderListIds || [],
|
||||||
|
...prevGlobal.savedFolderListIds || [],
|
||||||
|
]);
|
||||||
|
const areThreadsByChatChanged = allRelevantChatIds.some((chatId) => (
|
||||||
|
global.messages.byChatId[chatId]?.threadsById !== prevGlobal.threadsByChatId[chatId]
|
||||||
|
));
|
||||||
|
|
||||||
let affectedFolderIds: number[] = [];
|
let affectedFolderIds: number[] = [];
|
||||||
|
|
||||||
@ -251,7 +263,7 @@ function updateFolderManager(global: GlobalState) {
|
|||||||
if (!(
|
if (!(
|
||||||
isAllFolderChanged || isArchivedFolderChanged || isSavedFolderChanged || areFoldersChanged
|
isAllFolderChanged || isArchivedFolderChanged || isSavedFolderChanged || areFoldersChanged
|
||||||
|| areChatsChanged || areUsersChanged || areTopicsChanged || areNotifyDefaultsChanged || areNotifyExceptionsChanged
|
|| areChatsChanged || areUsersChanged || areTopicsChanged || areNotifyDefaultsChanged || areNotifyExceptionsChanged
|
||||||
|| areSavedLastMessageIdsChanged || areAllLastMessageIdsChanged
|
|| areSavedLastMessageIdsChanged || areAllLastMessageIdsChanged || areThreadsByChatChanged
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
if (affectedFolderIds.length) {
|
if (affectedFolderIds.length) {
|
||||||
@ -420,9 +432,9 @@ function buildFolderSummary(folder: ApiChatFolder): FolderSummary {
|
|||||||
return {
|
return {
|
||||||
...folder,
|
...folder,
|
||||||
orderedPinnedIds: folder.pinnedChatIds,
|
orderedPinnedIds: folder.pinnedChatIds,
|
||||||
excludedChatIds: folder.excludedChatIds ? new Set(folder.excludedChatIds) : undefined,
|
excludedChatIds: new Set(folder.excludedChatIds),
|
||||||
includedChatIds: folder.excludedChatIds ? new Set(folder.includedChatIds) : undefined,
|
includedChatIds: new Set(folder.includedChatIds),
|
||||||
pinnedChatIds: folder.excludedChatIds ? new Set(folder.pinnedChatIds) : undefined,
|
pinnedChatIds: new Set(folder.pinnedChatIds),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,6 +453,7 @@ function updateChats(
|
|||||||
const newSavedLastMessageIds = global.chats.lastMessageIds.saved;
|
const newSavedLastMessageIds = global.chats.lastMessageIds.saved;
|
||||||
const newNotifyDefaults = selectNotifyDefaults(global);
|
const newNotifyDefaults = selectNotifyDefaults(global);
|
||||||
const newNotifyExceptions = global.chats.notifyExceptionById;
|
const newNotifyExceptions = global.chats.notifyExceptionById;
|
||||||
|
const newMessageStoresByChatId = global.messages.byChatId;
|
||||||
const folderSummaries = Object.values(prepared.folderSummariesById);
|
const folderSummaries = Object.values(prepared.folderSummariesById);
|
||||||
const affectedFolderIds = new Set<number>();
|
const affectedFolderIds = new Set<number>();
|
||||||
|
|
||||||
@ -469,6 +482,7 @@ function updateChats(
|
|||||||
&& newUsersById[chatId] === prevGlobal.usersById[chatId]
|
&& newUsersById[chatId] === prevGlobal.usersById[chatId]
|
||||||
&& newAllLastMessageIds?.[chatId] === prevGlobal.lastAllMessageIds?.[chatId]
|
&& newAllLastMessageIds?.[chatId] === prevGlobal.lastAllMessageIds?.[chatId]
|
||||||
&& newSavedLastMessageIds?.[chatId] === prevGlobal.lastSavedMessageIds?.[chatId]
|
&& newSavedLastMessageIds?.[chatId] === prevGlobal.lastSavedMessageIds?.[chatId]
|
||||||
|
&& newMessageStoresByChatId[chatId]?.threadsById === prevGlobal.threadsByChatId[chatId]
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -520,6 +534,10 @@ function updateChats(
|
|||||||
prevGlobal.lastSavedMessageIds = newSavedLastMessageIds;
|
prevGlobal.lastSavedMessageIds = newSavedLastMessageIds;
|
||||||
prevGlobal.notifyDefaults = newNotifyDefaults;
|
prevGlobal.notifyDefaults = newNotifyDefaults;
|
||||||
prevGlobal.notifyExceptions = newNotifyExceptions;
|
prevGlobal.notifyExceptions = newNotifyExceptions;
|
||||||
|
prevGlobal.threadsByChatId = allIds.reduce((acc, chatId) => {
|
||||||
|
acc[chatId] = newMessageStoresByChatId[chatId]?.threadsById;
|
||||||
|
return acc;
|
||||||
|
}, {} as typeof prevGlobal.threadsByChatId);
|
||||||
|
|
||||||
return Array.from(affectedFolderIds);
|
return Array.from(affectedFolderIds);
|
||||||
}
|
}
|
||||||
@ -858,6 +876,7 @@ function buildInitials() {
|
|||||||
chatsById: {},
|
chatsById: {},
|
||||||
usersById: {},
|
usersById: {},
|
||||||
topicsInfoById: {},
|
topicsInfoById: {},
|
||||||
|
threadsByChatId: {},
|
||||||
},
|
},
|
||||||
|
|
||||||
prepared: {
|
prepared: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user