From 692aa02c54019c806cc7f7d96c9b800c8c85d6fb Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sat, 13 Mar 2021 17:08:34 +0400 Subject: [PATCH] Fix infinite loop with updates --- src/lib/appManagers/appMessagesManager.ts | 32 ++++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 320dc7c9..8b6f1e9d 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -156,7 +156,7 @@ export class AppMessagesManager { public newMessagesToHandle: {[peerId: string]: number[]} = {}; public newDialogsHandlePromise = 0; public newDialogsToHandle: {[peerId: string]: {reload: true} | Dialog} = {}; - public newUpdatesAfterReloadToHandle: {[peerId: string]: any[]} = {}; + public newUpdatesAfterReloadToHandle: {[peerId: string]: Set} = {}; private notificationsHandlePromise = 0; private notificationsToHandle: {[peerId: string]: { @@ -3756,13 +3756,31 @@ export class AppMessagesManager { const storage = this.getMessagesStorage(peerId); const foundDialog = this.getDialogByPeerId(peerId); - if(!foundDialog.length && (peerId > 0 || !appChatsManager.getChat(-peerId).pFlags.left)) { - this.newDialogsToHandle[peerId] = {reload: true}; - this.scheduleHandleNewDialogs(); - if(this.newUpdatesAfterReloadToHandle[peerId] === undefined) { - this.newUpdatesAfterReloadToHandle[peerId] = []; + if(!foundDialog.length) { + let good = true; + if(peerId < 0) { + const chat = appChatsManager.getChat(-peerId); + if(chat._ === 'channelForbidden' + || chat._ === 'chatForbidden' + || (chat as Chat.chat).pFlags.left + || (chat as Chat.chat).pFlags.kicked + || (chat as Chat.chat).pFlags.deactivated) { + good = false; + } } - this.newUpdatesAfterReloadToHandle[peerId].push(update); + + if(good) { + const set = this.newUpdatesAfterReloadToHandle[peerId] ?? (this.newUpdatesAfterReloadToHandle[peerId] = new Set()); + if(set.has(update)) { + this.log.error('here we go again', peerId); + break; + } + + this.newDialogsToHandle[peerId] = {reload: true}; + this.scheduleHandleNewDialogs(); + this.newUpdatesAfterReloadToHandle[peerId].add(update); + } + break; }