diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index ec973459..f877067b 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -2153,14 +2153,16 @@ export class AppMessagesManager { return apiManager.invokeApiSingle('channels.deleteHistory', { channel: appChatsManager.getChannelInput(channelId), max_id: appMessagesIdsManager.getServerMessageId(maxId) - }).then(() => { - apiUpdatesManager.processLocalUpdate({ - _: 'updateChannelAvailableMessages', - channel_id: channelId, - available_min_id: maxId - }); + }).then((bool) => { + if(bool) { + apiUpdatesManager.processLocalUpdate({ + _: 'updateChannelAvailableMessages', + channel_id: channelId, + available_min_id: maxId + }); + } - return true; + return bool; }); } diff --git a/src/lib/storages/dialogs.ts b/src/lib/storages/dialogs.ts index 9981d255..62f5bede 100644 --- a/src/lib/storages/dialogs.ts +++ b/src/lib/storages/dialogs.ts @@ -907,16 +907,9 @@ export default class DialogsStorage { promises.push(fillContactsResult.promise); } - const filter = this.appMessagesManager.filtersStorage.getFilter(folderId); - const pinnedPeers = filter?.pinned_peers; - if(pinnedPeers?.length) { - const pinnedPeerIds = filter.pinnedPeerIds; - const reloadDialogs = pinnedPeers.filter((inputPeer, idx) => !this.getDialogOnly(pinnedPeerIds[idx])); - if(reloadDialogs.length) { - const reloadPromises = reloadDialogs.map(inputPeer => this.appMessagesManager.reloadConversation(inputPeer)); - const reloadPromise = Promise.all(reloadPromises); - promises.push(reloadPromise); - } + const reloadMissingDialogsPromise = this.appMessagesManager.filtersStorage.reloadMissingPeerIds(folderId); + if(reloadMissingDialogsPromise) { + promises.push(reloadMissingDialogsPromise); } if(promises.length) { diff --git a/src/lib/storages/filters.ts b/src/lib/storages/filters.ts index 1b35ccf0..12213642 100644 --- a/src/lib/storages/filters.ts +++ b/src/lib/storages/filters.ts @@ -39,6 +39,7 @@ const START_ORDER_INDEX = 1; export default class FiltersStorage { public filters: {[filterId: string]: MyDialogFilter}; private orderIndex: number; + private reloadedPeerIds: Set; constructor(private appMessagesManager: AppMessagesManager, private appPeersManager: AppPeersManager, @@ -96,6 +97,7 @@ export default class FiltersStorage { } this.orderIndex = START_ORDER_INDEX; + this.reloadedPeerIds = new Set(); } private onUpdateDialogFilter = (update: Update.updateDialogFilter) => { @@ -298,6 +300,33 @@ export default class FiltersStorage { }); } + public reloadMissingPeerIds(filterId: number) { + const promises: Promise[] = []; + const filter = this.getFilter(filterId); + const pinnedPeers = filter?.pinned_peers; + if(pinnedPeers?.length) { + const reloadDialogs = pinnedPeers.filter((inputPeer, idx) => { + const peerId = this.appPeersManager.getPeerId(inputPeer); + return !this.reloadedPeerIds.has(peerId) && !this.appMessagesManager.getDialogOnly(peerId); + }); + + if(reloadDialogs.length) { + const reloadPromises = reloadDialogs.map(inputPeer => { + const peerId = this.appPeersManager.getPeerId(inputPeer); + const promise = this.appMessagesManager.reloadConversation(inputPeer); + promise.then(() => { + this.reloadedPeerIds.add(peerId); + }); + return promise; + }); + const reloadPromise = Promise.all(reloadPromises); + promises.push(reloadPromise); + } + } + + return promises.length ? Promise.all(promises) : undefined; + } + public async getDialogFilters(overwrite = false): Promise { const keys = Object.keys(this.filters); if(keys.length && !overwrite) {