Skip to content

Commit 4cf5a48

Browse files
authored
Merge pull request #441 from GetStream/fix-nessage-input-reset
fix: Don't reset message input on channel update
2 parents dd51ac6 + 04532a8 commit 4cf5a48

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ describe('MessageInputComponent', () => {
338338
{ file, state: 'success', url: 'http://url/to/image' },
339339
]);
340340
const files = [file];
341+
component.textareaValue = 'my message';
341342
await component.filesSelected(files as any as FileList);
342343
await component.messageSent();
343344

@@ -429,6 +430,25 @@ describe('MessageInputComponent', () => {
429430
expect(attachmentService.resetAttachmentUploads).toHaveBeenCalledWith();
430431
});
431432

433+
it('should not reset textarea and attachments if channel id remains the same', () => {
434+
attachmentService.attachmentUploads$.next([
435+
{
436+
file: { name: 'img.png' } as any as File,
437+
state: 'uploading',
438+
type: 'image',
439+
},
440+
]);
441+
component.textareaValue = 'text';
442+
mockActiveChannel$.next({
443+
...mockActiveChannel$.getValue(),
444+
getConfig: () => ({ commands: [] }),
445+
} as any as Channel<DefaultStreamChatGenerics>);
446+
fixture.detectChanges();
447+
448+
expect(component.textareaValue).toBe('text');
449+
expect(attachmentService.resetAttachmentUploads).not.toHaveBeenCalled();
450+
});
451+
432452
it('should accept #message as input', () => {
433453
component.message = mockMessage();
434454
component.ngOnChanges({ message: {} as any as SimpleChange });

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ export class MessageInputComponent
153153
);
154154
this.subscriptions.push(
155155
this.channelService.activeChannel$.subscribe((channel) => {
156-
this.textareaValue = '';
157-
this.attachmentService.resetAttachmentUploads();
156+
if (channel && this.channel && channel.id !== this.channel.id) {
157+
this.textareaValue = '';
158+
this.attachmentService.resetAttachmentUploads();
159+
}
158160
const capabilities = channel?.data?.own_capabilities as string[];
159161
if (capabilities) {
160162
this.isFileUploadAuthorized =

0 commit comments

Comments
 (0)