Skip to content

Commit 300ebfa

Browse files
authored
Merge pull request #659 from GetStream/parent-message-overflow
fix: if parent message is too big, and there are no thread reply - us…
2 parents e2c2ba4 + ac1415b commit 300ebfa

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

projects/stream-chat-angular/src/lib/message-list/message-list.component.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,9 @@ export class MessageListComponent
281281
);
282282
this.subscriptions.push(
283283
this.channelService.activeParentMessage$.subscribe((message) => {
284+
if (!message && this.parentMessage && this.mode === 'thread') {
285+
this.resetScrollState();
286+
}
284287
if (
285288
message &&
286289
this.parentMessage &&
@@ -490,6 +493,14 @@ export class MessageListComponent
490493
}
491494
return;
492495
}
496+
if (
497+
this.scrollContainer.nativeElement.scrollHeight >
498+
this.scrollContainer.nativeElement.clientHeight
499+
) {
500+
if (!this.isJumpToLatestButtonVisible) {
501+
this.isJumpToLatestButtonVisible = true;
502+
}
503+
}
493504
this.scroll$.next();
494505
let scrollPosition = this.getScrollPosition();
495506

@@ -625,17 +636,17 @@ export class MessageListComponent
625636
private getScrollPosition(): 'top' | 'bottom' | 'middle' {
626637
let position: 'top' | 'bottom' | 'middle' = 'middle';
627638
if (
628-
Math.floor(this.scrollContainer.nativeElement.scrollTop) <=
629-
(this.parentMessageElement?.nativeElement.clientHeight || 0)
630-
) {
631-
position = 'top';
632-
} else if (
633639
Math.ceil(this.scrollContainer.nativeElement.scrollTop) +
634640
this.scrollContainer.nativeElement.clientHeight +
635641
1 >=
636642
this.scrollContainer.nativeElement.scrollHeight
637643
) {
638644
position = 'bottom';
645+
} else if (
646+
Math.floor(this.scrollContainer.nativeElement.scrollTop) <=
647+
(this.parentMessageElement?.nativeElement?.clientHeight || 0)
648+
) {
649+
position = 'top';
639650
}
640651

641652
return position;
@@ -663,11 +674,7 @@ export class MessageListComponent
663674
}
664675
);
665676
this.messages$ = this.virtualizedList.virtualizedItems$.pipe(
666-
tap((messages) => {
667-
if (messages.length === 0) {
668-
this.resetScrollState();
669-
return;
670-
}
677+
tap(() => {
671678
if (this.isEmpty) {
672679
// cdRef.detectChanges() isn't enough here, test will fail
673680
setTimeout(() => (this.isEmpty = false), 0);
@@ -706,6 +713,8 @@ export class MessageListComponent
706713
this.isLatestMessageInList =
707714
!latestMessageInList ||
708715
latestMessageInList.cid !== channel?.cid ||
716+
(this.mode === 'thread' &&
717+
latestMessageInList?.parent_id !== this.parentMessage?.id) ||
709718
latestMessageInList?.id ===
710719
messagesFromState[messagesFromState.length - 1]?.id;
711720
if (!this.isLatestMessageInList) {

0 commit comments

Comments
 (0)