From b580fcd1d9ba54bcd35ed3d92b478e372900657a Mon Sep 17 00:00:00 2001 From: Zita Szupera Date: Mon, 15 Jul 2024 14:09:20 +0200 Subject: [PATCH] Turn of scroll reporting while jump to message is in progress --- .../lib/message-list/message-list.component.spec.ts | 2 +- .../src/lib/message-list/message-list.component.ts | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/projects/stream-chat-angular/src/lib/message-list/message-list.component.spec.ts b/projects/stream-chat-angular/src/lib/message-list/message-list.component.spec.ts index e0d79372..74ffd24c 100644 --- a/projects/stream-chat-angular/src/lib/message-list/message-list.component.spec.ts +++ b/projects/stream-chat-angular/src/lib/message-list/message-list.component.spec.ts @@ -464,7 +464,7 @@ describe('MessageListComponent', () => { it('should turn of programatic scroll adjustment and message load while jumping to message', () => { // This test uses private memebers to set up test cases, this is not nice, but this is because creating these cases otherwise would require a lot of complex logic - component.highlightedMessageId = 'messageId'; + component['isJumpingToMessage'] = true; component.isUserScrolled = true; spyOn(component, 'scrollToBottom'); component.ngAfterViewChecked(); diff --git a/projects/stream-chat-angular/src/lib/message-list/message-list.component.ts b/projects/stream-chat-angular/src/lib/message-list/message-list.component.ts index aa87b18b..bc692bcb 100644 --- a/projects/stream-chat-angular/src/lib/message-list/message-list.component.ts +++ b/projects/stream-chat-angular/src/lib/message-list/message-list.component.ts @@ -129,6 +129,7 @@ export class MessageListComponent unreadCount?: number; isJumpingToLatestUnreadMessage = false; isJumpToLatestButtonVisible = true; + isJumpingToMessage = false; scroll$ = new Subject(); @ViewChild('scrollContainer') private scrollContainer!: ElementRef; @@ -411,7 +412,7 @@ export class MessageListComponent } ngAfterViewChecked() { - if (this.highlightedMessageId) { + if (this.isJumpingToMessage) { this.isNewMessageSentByUser = false; this.messageIdToAnchorTo = undefined; this.anchorMessageTopOffset = undefined; @@ -534,7 +535,7 @@ export class MessageListComponent } } - if (prevScrollPosition !== scrollPosition) { + if (prevScrollPosition !== scrollPosition && !this.isJumpingToMessage) { if (scrollPosition === 'top' || scrollPosition === 'bottom') { this.virtualizedList?.virtualizedItems$ .pipe(take(1)) @@ -750,6 +751,7 @@ export class MessageListComponent } else if (this.direction === 'top-to-bottom') { jumpToMessage.position = 'top'; } + this.isJumpingToMessage = true; this.scrollMessageIntoView({ messageId: this.firstUnreadMessageId || messageId, position: jumpToMessage.position || 'middle', @@ -767,6 +769,7 @@ export class MessageListComponent this.newMessageCountWhileBeingScrolled = 0; this.isNewMessageSentByUser = false; this.isLatestMessageInList = true; + this.isJumpingToMessage = false; this.scrollPosition$.next('bottom'); } @@ -804,6 +807,9 @@ export class MessageListComponent ? this.scrollToBottom() : this.scrollToTop(); } + setTimeout(() => { + this.isJumpingToMessage = false; + }, 0); setTimeout(() => { this.highlightedMessageId = undefined; this.firstUnreadMessageId = undefined;