Skip to content

Commit f49617f

Browse files
authored
Merge pull request #490 from GetStream/performance
Performance
2 parents 5d2a1df + 0f5792b commit f49617f

File tree

6 files changed

+14
-15
lines changed

6 files changed

+14
-15
lines changed

projects/stream-chat-angular/src/lib/channel.service.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ export class ChannelService<
499499
this.watchForActiveChannelEvents(channel);
500500
this.addChannel(channel);
501501
this.activeChannelSubject.next(channel);
502+
const channelStateLength = channel.state.latestMessages.length;
503+
if (channelStateLength > 2 * this.messagePageSize) {
504+
channel.state.latestMessages = channel.state.latestMessages.slice(
505+
channelStateLength - 2 * this.messagePageSize
506+
);
507+
}
502508
this.setChannelState(channel);
503509
}
504510

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,7 @@
153153
<div class="str-chat__jump-to-latest-message">
154154
<button
155155
data-testid="scroll-to-latest"
156-
*ngIf="
157-
isUserScrolled &&
158-
(!isScrollInProgress || !hideJumpToLatestButtonDuringScroll)
159-
"
156+
*ngIf="isUserScrolled"
160157
class="
161158
str-chat__message-notification-scroll-to-latest
162159
str-chat__message-notification-scroll-to-latest-right

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ export class MessageListComponent
9999
parentMessage: StreamMessage | undefined;
100100
highlightedMessageId: string | undefined;
101101
isLoading = false;
102-
isScrollInProgress = false;
103102
scrollEndTimeout: any;
104103
lastReadMessageId?: string;
105104
isJumpingToLatestUnreadMessage = false;
@@ -368,15 +367,6 @@ export class MessageListComponent
368367
}
369368

370369
scrolled() {
371-
this.isScrollInProgress = true;
372-
if (this.scrollEndTimeout) {
373-
clearTimeout(this.scrollEndTimeout);
374-
}
375-
this.scrollEndTimeout = setTimeout(() => {
376-
this.ngZone.run(() => {
377-
this.isScrollInProgress = false;
378-
});
379-
}, 100);
380370
if (
381371
this.scrollContainer.nativeElement.scrollHeight ===
382372
this.scrollContainer.nativeElement.clientHeight

projects/stream-chat-angular/src/lib/message/message.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
class="str-chat__message-simple__actions str-chat__message-options"
3737
data-testid="message-options"
3838
[class.str-chat__message-edit-in-progress]="isEditing"
39-
*ngIf="areOptionsVisible"
39+
*ngIf="areOptionsVisible && optionsRenderTimeoutEnded"
4040
>
4141
<div
4242
data-testid="message-actions-container"

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ describe('MessageComponent', () => {
145145
queryReplyInThreadIcon = () =>
146146
nativeElement.querySelector('[data-testid="reply-in-thread"]');
147147
message = mockMessage();
148+
component.optionsRenderTimeoutEnded = true;
148149
component.message = message;
149150
component.ngOnChanges({ message: {} as SimpleChange });
150151
fixture.detectChanges();

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class MessageComponent
110110
canDisplayReadStatus = false;
111111
private quotedMessageAttachments: Attachment[] | undefined;
112112
user: UserResponse<DefaultStreamChatGenerics> | undefined;
113+
optionsRenderTimeoutEnded = false;
113114
private subscriptions: Subscription[] = [];
114115
@ViewChild('container') private container:
115116
| ElementRef<HTMLElement>
@@ -222,6 +223,10 @@ export class MessageComponent
222223
this.mouseLeft()
223224
);
224225
});
226+
setTimeout(() => {
227+
this.optionsRenderTimeoutEnded = true;
228+
this.cdRef.detectChanges();
229+
}, 0);
225230
}
226231

227232
ngOnDestroy(): void {

0 commit comments

Comments
 (0)