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. 78
      src/lib/storages/filters.ts

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

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

4
src/lib/appManagers/appChatsManager.ts

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

2
src/lib/appManagers/appProfileManager.ts

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

4
src/lib/storages/dialogs.ts

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

78
src/lib/storages/filters.ts

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

Loading…
Cancel
Save