From 257b5404379b0f4f3d11ab437a22fe03fc94e002 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Fri, 16 Apr 2021 18:14:50 +0400 Subject: [PATCH] Fix archived tab leak --- src/components/chat/bubbles.ts | 19 +++++++------------ .../sidebarLeft/tabs/archivedTab.ts | 4 +--- src/lib/appManagers/appDialogsManager.ts | 5 ++++- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 37a2afe4..5af4e50a 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -59,6 +59,7 @@ import findUpClassName from "../../helpers/dom/findUpClassName"; import findUpTag from "../../helpers/dom/findUpTag"; import { toast } from "../toast"; import { getElementByPoint } from "../../helpers/dom/getElementByPoint"; +import { getMiddleware } from "../../helpers/middleware"; const USE_MEDIA_TAILS = false; const IGNORE_ACTIONS: Message.messageService['action']['_'][] = [/* 'messageActionHistoryClear' */]; @@ -115,7 +116,7 @@ export default class ChatBubbles { public lazyLoadQueue: LazyLoadQueue; - private cleanupObj = {cleaned: false}; + private middleware = getMiddleware(); private log: ReturnType; @@ -1374,7 +1375,7 @@ export default class ChatBubbles { // clear messages if(bubblesToo) { - this.scrollable.container.innerHTML = ''; + this.scrollable.container.textContent = ''; } this.firstUnreadBubble = null; @@ -1396,8 +1397,7 @@ export default class ChatBubbles { this.loadedTopTimes = this.loadedBottomTimes = 0; - this.cleanupObj.cleaned = true; - this.cleanupObj = {cleaned: false}; + this.middleware.clean(); ////console.timeEnd('appImManager cleanup'); } @@ -1497,10 +1497,9 @@ export default class ChatBubbles { this.isFirstLoad = true; } - const oldChatInner = this.chatInner; this.cleanup(); - this.chatInner = oldChatInner.cloneNode() as HTMLDivElement; - this.chatInner.classList.remove('disable-hover', 'is-scrolling'); + this.chatInner = document.createElement('div'); + this.chatInner.classList.add('bubbles-inner'); this.lazyLoadQueue.lock(); @@ -1758,12 +1757,8 @@ export default class ChatBubbles { this.bubbleGroups.addBubble(bubble, message, reverse); } - // * will change .cleaned in cleanup() and new instance will be created public getMiddleware() { - const cleanupObj = this.cleanupObj; - return () => { - return !cleanupObj.cleaned; - }; + return this.middleware.get(); } // reverse means top diff --git a/src/components/sidebarLeft/tabs/archivedTab.ts b/src/components/sidebarLeft/tabs/archivedTab.ts index ddf9c8a8..88530b79 100644 --- a/src/components/sidebarLeft/tabs/archivedTab.ts +++ b/src/components/sidebarLeft/tabs/archivedTab.ts @@ -25,9 +25,7 @@ export default class AppArchivedTab extends SliderSuperTab { this.scrollable.onScrolledBottom = appDialogsManager.onChatsScroll; ///this.scroll.attachSentinels(); - appDialogsManager.setListClickListener(chatList, null, true); - - window.addEventListener('resize', () => { + this.listenerSetter.add(window, 'resize', () => { setTimeout(appDialogsManager.scroll.checkForTriggers, 0); }); } diff --git a/src/lib/appManagers/appDialogsManager.ts b/src/lib/appManagers/appDialogsManager.ts index 47e87130..f33fb691 100644 --- a/src/lib/appManagers/appDialogsManager.ts +++ b/src/lib/appManagers/appDialogsManager.ts @@ -227,10 +227,13 @@ export class AppDialogsManager { private lastActiveElements: Set = new Set(); constructor() { + const archivedChatList = this.createChatList(); this.chatLists = { - 1: this.createChatList() + 1: archivedChatList }; + this.setListClickListener(archivedChatList, null, true); + this.chatsPreloader = putPreloader(null, true); this.allUnreadCount = this.folders.menu.querySelector('.badge');