From cbbb0c7d46ee45bdd066efc6dc74cec4365a187f Mon Sep 17 00:00:00 2001 From: Eduard Kuzmenko Date: Tue, 22 Dec 2020 10:57:10 +0200 Subject: [PATCH] Fix rendering discussion message in cached chats --- src/components/chat/bubbles.ts | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 59173ea6..394c2376 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -2499,6 +2499,21 @@ export default class ChatBubbles { //additionMsgID = 0; } + const processResult = (historyResult: typeof result) => { + if(this.chat.type === 'discussion' && 'offsetIdOffset' in historyResult) { + const isTopEnd = historyResult.offsetIdOffset >= (historyResult.count - loadCount); + this.log('discussion got history', loadCount, backLimit, historyResult, isTopEnd); + + // * inject discussion start + if(isTopEnd) { + const serviceStartMessageId = this.appMessagesManager.threadsServiceMessagesIdsStorage[this.peerId + '_' + this.chat.threadId]; + if(serviceStartMessageId) historyResult.history.push(serviceStartMessageId); + historyResult.history.push(this.chat.threadId); + this.scrolledAll = true; + } + } + }; + const processPromise = (result: Promise) => { const promise = result.then((result) => { this.log('getHistory not cached result by maxId:', maxId, reverse, isBackLimit, result, peerId, justLoad); @@ -2515,19 +2530,7 @@ export default class ChatBubbles { return Promise.reject(); } - if(this.chat.type === 'discussion') { - const topLoadCount = loadCount; - const isTopEnd = result.offsetIdOffset >= (result.count - topLoadCount); - this.log('discussion got history', loadCount, backLimit, result, isTopEnd); - - // * inject discussion start - if(isTopEnd) { - const serviceStartMessageId = this.appMessagesManager.threadsServiceMessagesIdsStorage[this.peerId + '_' + this.chat.threadId]; - if(serviceStartMessageId) result.history.push(serviceStartMessageId); - result.history.push(this.chat.threadId); - this.scrolledAll = true; - } - } + processResult(result); ////console.timeEnd('render history total'); @@ -2549,6 +2552,7 @@ export default class ChatBubbles { } else { cached = true; this.log('getHistory cached result by maxId:', maxId, reverse, isBackLimit, result, peerId, justLoad); + processResult(result); promise = this.performHistoryResult(result.history || [], reverse, isBackLimit, !isFirstMessageRender && additionMsgId); //return (reverse ? this.getHistoryTopPromise = promise : this.getHistoryBottomPromise = promise); //return this.performHistoryResult(result.history || [], reverse, isBackLimit, additionMsgID, true);