diff --git a/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts b/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts index 6511a7f3..56af380a 100644 --- a/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts +++ b/projects/ucap-webmessenger-ui-chat/src/lib/components/messages.component.ts @@ -425,39 +425,29 @@ export class MessagesComponent implements OnInit, OnDestroy { useSwap: boolean, addtionalOffset?: number ) { - if (!!to) { - this.preSwapScroll(useHide, useSwap); - if (!!preCallback) { - preCallback(); - } - - this.virtualScroller.scrollInto( - to, - true, - undefined !== this.storedScrollItemOffsetTop - ? -this.storedScrollItemOffsetTop - : undefined !== addtionalOffset - ? -addtionalOffset - : 0, - 0, - () => { - setTimeout(() => { - if (!!postCallback) { - postCallback(); - } - this.postSwapScroll(useHide, useSwap); - }); - } - ); - } else { - if (!!preCallback) { - preCallback(); - } - - if (!!postCallback) { - postCallback(); - } + this.preSwapScroll(useHide, useSwap); + if (!!preCallback) { + preCallback(); } + + this.virtualScroller.scrollInto( + to, + true, + undefined !== this.storedScrollItemOffsetTop + ? -this.storedScrollItemOffsetTop + : undefined !== addtionalOffset + ? -addtionalOffset + : 0, + 0, + () => { + setTimeout(() => { + if (!!postCallback) { + postCallback(); + } + this.postSwapScroll(useHide, useSwap); + }); + } + ); } preSwapScroll(useHide: boolean, useSwap: boolean) { @@ -540,6 +530,12 @@ export class MessagesComponent implements OnInit, OnDestroy { return; } + if (!!this.gotoEventSeq) { + this.gotoPosition(this.gotoEventSeq); + this.gotoEventSeq = undefined; + return; + } + const lastEvent = !!this.eventList && 0 < this.eventList.length ? this.eventList[this.eventList.length - 1] @@ -550,20 +546,14 @@ export class MessagesComponent implements OnInit, OnDestroy { } const isInViewPortItems = this.isInViewPortItems(lastEvent.seq); this.swapScrollTo( - !!this.gotoEventSeq - ? undefined - : this.eventList[this.eventList.length - 1], + this.eventList[this.eventList.length - 1], () => {}, () => { this.initalized = true; - if (!!this.gotoEventSeq) { - this.gotoPosition(this.gotoEventSeq); - this.gotoEventSeq = undefined; - } }, -1 === this.virtualScroller.viewPortInfo.endIndex || !isInViewPortItems, - !isInViewPortItems || !!this.gotoEventSeq + !isInViewPortItems ); } }