diff --git a/src/components/audio.ts b/src/components/audio.ts index 01622652..6f77094c 100644 --- a/src/components/audio.ts +++ b/src/components/audio.ts @@ -692,23 +692,29 @@ export default class AudioElement extends HTMLElement { } disconnectedCallback() { - if(this.isConnected) { - return; - } - - if(this.onTypeDisconnect) { - this.onTypeDisconnect(); - this.onTypeDisconnect = null; - } - - if(this.readyPromise) { - this.readyPromise.reject(); - } - - this.listenerSetter.removeAll(); - this.listenerSetter = null; - - this.preloader = null; + setTimeout(() => { + if(this.isConnected) { + return; + } + + if(this.onTypeDisconnect) { + this.onTypeDisconnect(); + this.onTypeDisconnect = null; + } + + if(this.readyPromise) { + this.readyPromise.reject(); + } + + if(this.listenerSetter) { + this.listenerSetter.removeAll(); + this.listenerSetter = null; + } + + if(this.preloader) { + this.preloader = null; + } + }, 100); } } diff --git a/src/components/chat/bubbles.ts b/src/components/chat/bubbles.ts index 6eb18a2f..c70924e2 100644 --- a/src/components/chat/bubbles.ts +++ b/src/components/chat/bubbles.ts @@ -323,7 +323,7 @@ export default class ChatBubbles { const _items = this.bubbleGroups.itemsArr.slice(); indexOfAndSplice(_items, item); const foundItem = this.bubbleGroups.findGroupSiblingByItem(newItem, _items); - if(group === foundItem?.group/* && false */) { + if(group === foundItem?.group || (group === this.bubbleGroups.getLastGroup() && group.items.length === 1)/* && false */) { log && log('item has correct position', item); this.bubbleGroups.changeBubbleMid(bubble, mid); return; @@ -2902,21 +2902,22 @@ export default class ChatBubbles { this.chat.dispatchEvent('setPeer', lastMsgId, !isJump); - this.setFetchReactionsInterval(afterSetPromise); - this.setFetchHistoryInterval({ - afterSetPromise, - lastMsgId, - samePeer, - savedPosition, - topMessage + Promise.all([ + this.setFetchReactionsInterval(afterSetPromise), + this.setFetchHistoryInterval({ + afterSetPromise, + lastMsgId, + samePeer, + savedPosition, + topMessage + }), + ]).then(() => { + log('scrolledAllDown:', scrollable.loadedAll.bottom); + //if(!this.unreaded.length && dialog) { // lol + if(scrollable.loadedAll.bottom && topMessage && !this.unreaded.size) { // lol + this.onScrolledAllDown(); + } }); - - log('scrolledAllDown:', scrollable.loadedAll.bottom); - - //if(!this.unreaded.length && dialog) { // lol - if(scrollable.loadedAll.bottom && topMessage && !this.unreaded.size) { // lol - this.onScrolledAllDown(); - } if(chatType === 'chat') { const dialog = await m(this.managers.appMessagesManager.getDialogOnly(peerId)); diff --git a/src/helpers/scrollSaver.ts b/src/helpers/scrollSaver.ts index d99dd81b..fa02cf0b 100644 --- a/src/helpers/scrollSaver.ts +++ b/src/helpers/scrollSaver.ts @@ -85,7 +85,7 @@ export default class ScrollSaver { public save() { this.findAndSetElements(); - console.warn('scroll save', this.elements); + // console.warn('scroll save', this.elements); this._save(); } @@ -152,7 +152,7 @@ export default class ScrollSaver { const diff = newRect.bottom - rect.bottom; this.setScrollTop(scrollTop + diff, useReflow); // if(diff) debugger; - console.warn('scroll restore', rect, diff, newRect); + // console.warn('scroll restore', rect, diff, newRect); } public _restore(useReflow?: boolean) {