Browse Source

Fix filling missed dialogs in folders

master
morethanwords 3 years ago
parent
commit
1b49a65db0
  1. 6
      src/lib/appManagers/appMessagesManager.ts
  2. 13
      src/lib/storages/dialogs.ts
  3. 29
      src/lib/storages/filters.ts

6
src/lib/appManagers/appMessagesManager.ts

@ -2153,14 +2153,16 @@ export class AppMessagesManager { @@ -2153,14 +2153,16 @@ export class AppMessagesManager {
return apiManager.invokeApiSingle('channels.deleteHistory', {
channel: appChatsManager.getChannelInput(channelId),
max_id: appMessagesIdsManager.getServerMessageId(maxId)
}).then(() => {
}).then((bool) => {
if(bool) {
apiUpdatesManager.processLocalUpdate({
_: 'updateChannelAvailableMessages',
channel_id: channelId,
available_min_id: maxId
});
}
return true;
return bool;
});
}

13
src/lib/storages/dialogs.ts

@ -907,16 +907,9 @@ export default class DialogsStorage { @@ -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) {

29
src/lib/storages/filters.ts

@ -39,6 +39,7 @@ const START_ORDER_INDEX = 1; @@ -39,6 +39,7 @@ const START_ORDER_INDEX = 1;
export default class FiltersStorage {
public filters: {[filterId: string]: MyDialogFilter};
private orderIndex: number;
private reloadedPeerIds: Set<PeerId>;
constructor(private appMessagesManager: AppMessagesManager,
private appPeersManager: AppPeersManager,
@ -96,6 +97,7 @@ export default class FiltersStorage { @@ -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 { @@ -298,6 +300,33 @@ export default class FiltersStorage {
});
}
public reloadMissingPeerIds(filterId: number) {
const promises: Promise<any>[] = [];
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<MyDialogFilter[]> {
const keys = Object.keys(this.filters);
if(keys.length && !overwrite) {

Loading…
Cancel
Save