From b255c746fee340a3d4488e7be26374de87aa8d17 Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Sat, 8 May 2021 22:49:50 +0400 Subject: [PATCH] Fix unread replies status on empty threads Fix clearing chat after it is closed Fix bubbles loadedAll --- src/components/chat/bubbles.ts | 4 ++-- src/components/chat/chat.ts | 4 ++++ src/components/chat/replies.ts | 12 +++++++----- src/config/app.ts | 2 +- src/lib/appManagers/appImManager.ts | 4 ++++ src/lib/appManagers/appMessagesManager.ts | 16 +++++++--------- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 67f5f5b1..1e68fdb8 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -2684,11 +2684,11 @@ export default class ChatBubbles { const historyStorage = this.appMessagesManager.getHistoryStorage(this.peerId, this.chat.threadId); const firstSlice = historyStorage.history.first; const lastSlice = historyStorage.history.last; - if(firstSlice.isEnd(SliceEnd.Bottom) && history.includes(firstSlice[0])) { + if(firstSlice.isEnd(SliceEnd.Bottom) && (!firstSlice.length || history.includes(firstSlice[0]))) { this.scrollable.loadedAll.bottom = true; } - if(lastSlice.isEnd(SliceEnd.Top) && history.includes(lastSlice[lastSlice.length - 1])) { + if(lastSlice.isEnd(SliceEnd.Top) && (!lastSlice.length || history.includes(lastSlice[lastSlice.length - 1]))) { this.scrollable.loadedAll.top = true; } diff --git a/src/components/chat/chat.ts b/src/components/chat/chat.ts index d18d498a..3ccf5f69 100644 --- a/src/components/chat/chat.ts +++ b/src/components/chat/chat.ts @@ -197,6 +197,10 @@ export default class Chat extends EventListenerBase<{ }); } + public beforeDestroy() { + this.bubbles.cleanup(); + } + public destroy() { //const perf = performance.now(); diff --git a/src/components/chat/replies.ts b/src/components/chat/replies.ts index 177dabb2..250c31cf 100644 --- a/src/components/chat/replies.ts +++ b/src/components/chat/replies.ts @@ -116,11 +116,13 @@ export default class RepliesElement extends HTMLElement { if(replies) { const historyStorage = appMessagesManager.getHistoryStorage(-replies.channel_id); - let isUnread: boolean; - if(replies.read_max_id !== undefined && replies.max_id !== undefined) { - isUnread = replies.read_max_id < replies.max_id; - } else { - isUnread = !historyStorage.readMaxId || historyStorage.readMaxId < (replies.max_id || 0); + let isUnread = false; + if(replies.replies) { + if(replies.read_max_id !== undefined && replies.max_id !== undefined) { + isUnread = replies.read_max_id < replies.max_id; + } else { + isUnread = !historyStorage.readMaxId || historyStorage.readMaxId < (replies.max_id || 0); + } } this.classList.toggle('is-unread', isUnread); } diff --git a/src/config/app.ts b/src/config/app.ts index df266947..52c3bfdd 100644 --- a/src/config/app.ts +++ b/src/config/app.ts @@ -12,7 +12,7 @@ const App = { id: 1025907, hash: '452b0359b988148995f22ff0f4229750', - version: '0.5.1', + version: '0.5.2', langPackVersion: '0.1.6', langPack: 'macos', langPackCode: 'en', diff --git a/src/lib/appManagers/appImManager.ts b/src/lib/appManagers/appImManager.ts index b0e7d982..0de4348a 100644 --- a/src/lib/appManagers/appImManager.ts +++ b/src/lib/appManagers/appImManager.ts @@ -773,6 +773,10 @@ export class AppImManager { appSidebarRight.sharedMediaTab.loadSidebarMedia(false); }); */ } + + spliced.forEach(chat => { + chat.beforeDestroy(); + }); setTimeout(() => { //chat.setPeer(0); diff --git a/src/lib/appManagers/appMessagesManager.ts b/src/lib/appManagers/appMessagesManager.ts index 8c3aa668..6fa98c8d 100644 --- a/src/lib/appManagers/appMessagesManager.ts +++ b/src/lib/appManagers/appMessagesManager.ts @@ -4654,16 +4654,14 @@ export class AppMessagesManager { mids.splice(i, 0, offset_id); } - const slice = historyStorage.history.insertSlice(mids); - if(slice) { - if(isTopEnd) { - slice.setEnd(SliceEnd.Top); - } + const slice = historyStorage.history.insertSlice(mids) || historyStorage.history.slice; + if(isTopEnd) { + slice.setEnd(SliceEnd.Top); + } - if(isBottomEnd) { - slice.setEnd(SliceEnd.Bottom); - historyStorage.maxId = slice[0]; // ! WARNING - } + if(isBottomEnd) { + slice.setEnd(SliceEnd.Bottom); + historyStorage.maxId = slice[0]; // ! WARNING } /* const isBackLimit = offset < 0 && -offset !== fullLimit;