Skip to content

Commit

Permalink
Turn of scroll reporting while jump to message is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
szuperaz committed Jul 15, 2024
1 parent b5281ce commit b580fcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class MessageListComponent
unreadCount?: number;
isJumpingToLatestUnreadMessage = false;
isJumpToLatestButtonVisible = true;
isJumpingToMessage = false;
scroll$ = new Subject<void>();
@ViewChild('scrollContainer')
private scrollContainer!: ElementRef<HTMLElement>;
Expand Down Expand Up @@ -411,7 +412,7 @@ export class MessageListComponent
}

ngAfterViewChecked() {
if (this.highlightedMessageId) {
if (this.isJumpingToMessage) {
this.isNewMessageSentByUser = false;
this.messageIdToAnchorTo = undefined;
this.anchorMessageTopOffset = undefined;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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',
Expand All @@ -767,6 +769,7 @@ export class MessageListComponent
this.newMessageCountWhileBeingScrolled = 0;
this.isNewMessageSentByUser = false;
this.isLatestMessageInList = true;
this.isJumpingToMessage = false;
this.scrollPosition$.next('bottom');
}

Expand Down Expand Up @@ -804,6 +807,9 @@ export class MessageListComponent
? this.scrollToBottom()
: this.scrollToTop();
}
setTimeout(() => {
this.isJumpingToMessage = false;
}, 0);
setTimeout(() => {
this.highlightedMessageId = undefined;
this.firstUnreadMessageId = undefined;
Expand Down

0 comments on commit b580fcd

Please sign in to comment.