Browse Source

Fix editing folders with dead chats in it

Rollback displaying chat where we're kicked
master
Eduard Kuzmenko 3 years ago
parent
commit
3212916518
  1. 8
      src/components/sidebarLeft/tabs/editFolder.ts
  2. 4
      src/lib/appManagers/appChatsManager.ts
  3. 2
      src/lib/appManagers/appProfileManager.ts
  4. 4
      src/lib/storages/dialogs.ts
  5. 90
      src/lib/storages/filters.ts

8
src/components/sidebarLeft/tabs/editFolder.ts

@ -377,8 +377,12 @@ export default class AppEditFolderTab extends SliderSuperTab {
} }
return super.open().then(() => { return super.open().then(() => {
if(this.type === 'edit') this.onEditOpen(); if(this.type === 'edit') {
else this.onCreateOpen(); this.setFilter(this.originalFilter, true);
this.onEditOpen();
} else {
this.onCreateOpen();
}
}); });
} }
} }

4
src/lib/appManagers/appChatsManager.ts

@ -238,7 +238,7 @@ export class AppChatsManager {
if(chat._ === 'chatForbidden' || if(chat._ === 'chatForbidden' ||
chat._ === 'channelForbidden' || chat._ === 'channelForbidden' ||
(chat as any).pFlags.kicked || // (chat as any).pFlags.kicked ||
(chat.pFlags.left && !(chat as Chat.channel).pFlags.megagroup)) { (chat.pFlags.left && !(chat as Chat.channel).pFlags.megagroup)) {
return false; return false;
} }
@ -377,7 +377,7 @@ export class AppChatsManager {
|| chat._ === 'chatForbidden' || chat._ === 'chatForbidden'
|| chat._ === 'chatEmpty' || chat._ === 'chatEmpty'
|| (chat as Chat.chat).pFlags.left || (chat as Chat.chat).pFlags.left
|| (chat as any).pFlags.kicked // || (chat as any).pFlags.kicked
|| (chat as Chat.chat).pFlags.deactivated) { || (chat as Chat.chat).pFlags.deactivated) {
good = false; good = false;
} }

2
src/lib/appManagers/appProfileManager.ts

@ -324,7 +324,7 @@ export class AppProfileManager {
const chat = appChatsManager.getChat(id); const chat = appChatsManager.getChat(id);
if(chat && if(chat &&
chat.pFlags && ( chat.pFlags && (
chat.pFlags.kicked || // chat.pFlags.kicked ||
chat.pFlags.broadcast && !chat.pFlags.creator && !chat.admin_rights chat.pFlags.broadcast && !chat.pFlags.creator && !chat.admin_rights
)) { )) {
return Promise.reject(); return Promise.reject();

4
src/lib/storages/dialogs.ts

@ -764,9 +764,9 @@ export default class DialogsStorage {
// ! chatForbidden stays for chat where you're kicked // ! chatForbidden stays for chat where you're kicked
if( if(
chat._ === 'channelForbidden' chat._ === 'channelForbidden'
|| chat._ === 'chatForbidden' // || chat._ === 'chatForbidden'
|| (chat as Chat.chat).pFlags.left || (chat as Chat.chat).pFlags.left
|| (chat as any).pFlags.kicked // || (chat as any).pFlags.kicked
) { ) {
return; return;
} }

90
src/lib/storages/filters.ts

@ -5,7 +5,7 @@
*/ */
import type { DialogFilter, Update } from "../../layer"; import type { DialogFilter, Update } from "../../layer";
import type { Modify } from "../../types"; import type { ArgumentTypes, Modify } from "../../types";
import type { AppPeersManager } from "../appManagers/appPeersManager"; import type { AppPeersManager } from "../appManagers/appPeersManager";
import type { AppUsersManager } from "../appManagers/appUsersManager"; import type { AppUsersManager } from "../appManagers/appUsersManager";
//import type { ApiManagerProxy } from "../mtproto/mtprotoworker"; //import type { ApiManagerProxy } from "../mtproto/mtprotoworker";
@ -13,11 +13,12 @@ import type _rootScope from "../rootScope";
import type {AppMessagesManager, Dialog} from '../appManagers/appMessagesManager'; import type {AppMessagesManager, Dialog} from '../appManagers/appMessagesManager';
import type {AppNotificationsManager} from "../appManagers/appNotificationsManager"; import type {AppNotificationsManager} from "../appManagers/appNotificationsManager";
import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager"; import type { ApiUpdatesManager } from "../appManagers/apiUpdatesManager";
import type { AppStateManager } from "../appManagers/appStateManager";
import apiManager from "../mtproto/mtprotoworker"; import apiManager from "../mtproto/mtprotoworker";
import { AppStateManager } from "../appManagers/appStateManager";
import forEachReverse from "../../helpers/array/forEachReverse"; import forEachReverse from "../../helpers/array/forEachReverse";
import copy from "../../helpers/object/copy"; import copy from "../../helpers/object/copy";
import safeReplaceObject from "../../helpers/object/safeReplaceObject"; import safeReplaceObject from "../../helpers/object/safeReplaceObject";
import findAndSplice from "../../helpers/array/findAndSplice";
export type MyDialogFilter = Modify<DialogFilter, { export type MyDialogFilter = Modify<DialogFilter, {
/* pinned_peers: PeerId[], /* pinned_peers: PeerId[],
@ -321,31 +322,80 @@ export default class FiltersStorage {
}); });
} }
public reloadMissingPeerIds(filterId: number, type: 'pinned_peers' | 'include_peers' | 'exclude_peers' = 'pinned_peers') { private p(filterId: number, type: ArgumentTypes<FiltersStorage['reloadMissingPeerIds']>[1], missingPeerIds: PeerId[]) {
const promises: Promise<any>[] = [];
const filter = this.getFilter(filterId); const filter = this.getFilter(filterId);
const peers = filter && filter[type]; const peers = filter && filter[type];
if(peers?.length) { if(!peers?.length) {
const reloadDialogs = peers.filter((inputPeer, idx) => { return;
const peerId = this.appPeersManager.getPeerId(inputPeer); }
return !this.reloadedPeerIds.has(peerId) && !this.appMessagesManager.getDialogOnly(peerId);
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
}); });
}
}
if(reloadDialogs.length) { public reloadMissingPeerIds(filterId: number, type: 'pinned_peers' | 'include_peers' | 'exclude_peers' = 'pinned_peers') {
const reloadPromises = reloadDialogs.map(inputPeer => { const filter = this.getFilter(filterId);
const peerId = this.appPeersManager.getPeerId(inputPeer); const peers = filter && filter[type];
const promise = this.appMessagesManager.reloadConversation(inputPeer); if(!peers?.length) {
promise.then(() => { return;
this.reloadedPeerIds.add(peerId); }
});
return promise; const missingPeerIds: PeerId[] = [];
}); const reloadDialogs = peers.filter((inputPeer) => {
const reloadPromise = Promise.all(reloadPromises); const peerId = this.appPeersManager.getPeerId(inputPeer);
promises.push(reloadPromise); const isAlreadyReloaded = this.reloadedPeerIds.has(peerId);
const dialog = this.appMessagesManager.getDialogOnly(peerId);
if(isAlreadyReloaded && !dialog) {
missingPeerIds.push(peerId);
} }
const reload = !isAlreadyReloaded && !dialog;
return reload;
});
if(!reloadDialogs.length) {
if(missingPeerIds.length) {
this.p(filterId, type, missingPeerIds);
}
return;
} }
return promises.length ? Promise.all(promises) : undefined; const reloadPromises = reloadDialogs.map((inputPeer) => {
const peerId = this.appPeersManager.getPeerId(inputPeer);
const promise = this.appMessagesManager.reloadConversation(inputPeer)
.then((dialog) => {
this.reloadedPeerIds.add(peerId);
return dialog ? undefined : peerId;
});
return promise;
});
const reloadPromise = Promise.all(reloadPromises).then((missingPeerIds) => {
missingPeerIds = missingPeerIds.filter(Boolean);
if(!missingPeerIds.length) {
return;
}
this.p(filterId, type, missingPeerIds);
});
return reloadPromise;
} }
public async getDialogFilters(overwrite = false): Promise<MyDialogFilter[]> { public async getDialogFilters(overwrite = false): Promise<MyDialogFilter[]> {

Loading…
Cancel
Save