From ff3ee75bcc5affd023fbfe600db4f9beb1038eab Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sun, 17 Apr 2022 18:01:43 +0300 Subject: [PATCH] Fix folders again --- src/components/sidebarLeft/tabs/editFolder.ts | 20 +++++- src/lib/appManagers/appMessagesManager.ts | 12 ++-- src/lib/appManagers/appUsersManager.ts | 2 +- src/lib/storages/filters.ts | 62 +++++++++---------- 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/components/sidebarLeft/tabs/editFolder.ts b/src/components/sidebarLeft/tabs/editFolder.ts index bafe6be7..2cde564a 100644 --- a/src/components/sidebarLeft/tabs/editFolder.ts +++ b/src/components/sidebarLeft/tabs/editFolder.ts @@ -23,6 +23,8 @@ import PopupPeer from "../../popups/peer"; import RLottiePlayer from "../../../lib/rlottie/rlottiePlayer"; import copy from "../../../helpers/object/copy"; import deepEqual from "../../../helpers/object/deepEqual"; +import appUsersManager from "../../../lib/appManagers/appUsersManager"; +import forEachReverse from "../../../helpers/array/forEachReverse"; const MAX_FOLDER_NAME_LENGTH = 12; @@ -291,11 +293,27 @@ export default class AppEditFolderTab extends SliderSuperTab { const section = this[key]; const ul = appDialogsManager.createChatList(); - const peers = filter[key].slice(); + let peers = filter[key]; + + // filter peers where we're kicked + const hasPeer = (peerId: PeerId) => { + return !!appMessagesManager.getDialogOnly(peerId) || (peerId.isUser() ? appUsersManager.getUser(peerId.toUserId())._ === 'user' : false); + }; + + forEachReverse(peers, (peerId, idx, arr) => { + if(!hasPeer(peerId)) { + arr.splice(idx, 1); + } + }); + + peers = peers.slice(); const renderMore = (_length: number) => { for(let i = 0, length = Math.min(peers.length, _length); i < length; ++i) { const peerId = peers.shift(); + if(peerId.isUser() ? false : !appMessagesManager.getDialogOnly(peerId)) { + continue; + } const {dom} = appDialogsManager.addDialogNew({ dialog: peerId, diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index cdcb9789..d4e9ab17 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -2260,12 +2260,16 @@ export class AppMessagesManager { } }); - fullfillLeft(); - resolve(); + // fullfillLeft(); + // resolve(); }, (err) => { - fullfillLeft(); - reject(err); + // fullfillLeft(); + // resolve(); + // reject(err); }).finally(() => { + fullfillLeft(); + resolve(); + this.reloadConversationsPromise = null; if(this.reloadConversationsPeers.size) { diff --git a/src/lib/appManagers/appUsersManager.ts b/src/lib/appManagers/appUsersManager.ts index 069bfb1a..e3be0d15 100644 --- a/src/lib/appManagers/appUsersManager.ts +++ b/src/lib/appManagers/appUsersManager.ts @@ -552,7 +552,7 @@ export class AppUsersManager { return id; } - return this.users[id] || {id, pFlags: {deleted: true}, access_hash: ''} as User; + return this.users[id] || {_: 'userEmpty', id, pFlags: {deleted: true}, access_hash: ''} as any as User; } public getSelf() { diff --git a/src/lib/storages/filters.ts b/src/lib/storages/filters.ts index 7ba2feae..b8c71f2c 100644 --- a/src/lib/storages/filters.ts +++ b/src/lib/storages/filters.ts @@ -322,29 +322,29 @@ export default class FiltersStorage { }); } - private p(filterId: number, type: ArgumentTypes[1], missingPeerIds: PeerId[]) { - const filter = this.getFilter(filterId); - const peers = filter && filter[type]; - if(!peers?.length) { - return; - } - - let spliced = false; - missingPeerIds.forEach((peerId) => { - const inputPeer = findAndSplice(peers, (inputPeer) => this.appPeersManager.getPeerId(inputPeer) === peerId); - if(inputPeer) { - spliced = true; - } - }); - - if(spliced) { - this.onUpdateDialogFilter({ - _: 'updateDialogFilter', - id: filterId, - filter - }); - } - } + // private spliceMissingPeerIds(filterId: number, type: ArgumentTypes[1], missingPeerIds: PeerId[]) { + // const filter = this.getFilter(filterId); + // const peers = filter && filter[type]; + // if(!peers?.length) { + // return; + // } + + // let spliced = false; + // missingPeerIds.forEach((peerId) => { + // const inputPeer = findAndSplice(peers, (inputPeer) => this.appPeersManager.getPeerId(inputPeer) === peerId); + // if(inputPeer) { + // spliced = true; + // } + // }); + + // if(spliced) { + // this.onUpdateDialogFilter({ + // _: 'updateDialogFilter', + // id: filterId, + // filter + // }); + // } + // } public reloadMissingPeerIds(filterId: number, type: 'pinned_peers' | 'include_peers' | 'exclude_peers' = 'pinned_peers') { const filter = this.getFilter(filterId); @@ -353,23 +353,23 @@ export default class FiltersStorage { return; } - const missingPeerIds: PeerId[] = []; + // const missingPeerIds: PeerId[] = []; const reloadDialogs = peers.filter((inputPeer) => { const peerId = this.appPeersManager.getPeerId(inputPeer); const isAlreadyReloaded = this.reloadedPeerIds.has(peerId); const dialog = this.appMessagesManager.getDialogOnly(peerId); - if(isAlreadyReloaded && !dialog) { - missingPeerIds.push(peerId); - } + // if(isAlreadyReloaded && !dialog) { + // missingPeerIds.push(peerId); + // } const reload = !isAlreadyReloaded && !dialog; return reload; }); if(!reloadDialogs.length) { - if(missingPeerIds.length) { - this.p(filterId, type, missingPeerIds); - } + // if(missingPeerIds.length) { + // this.spliceMissingPeerIds(filterId, type, missingPeerIds); + // } return; } @@ -392,7 +392,7 @@ export default class FiltersStorage { return; } - this.p(filterId, type, missingPeerIds); + // this.spliceMissingPeerIds(filterId, type, missingPeerIds); }); return reloadPromise;