Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,32 @@ describe('MessageInputComponent', () => {
});

it(`shouldn't send message, if file uploads are in progress`, async () => {
const notificationService = TestBed.inject(NotificationService);
spyOn(notificationService, 'addPermanentNotification');
uploadAttachmentsSpy.and.resolveTo([]);
void component.filesSelected([{ type: 'image/png' }] as any as FileList);
await component.messageSent();

expect(sendMessageSpy).not.toHaveBeenCalled();
expect(notificationService.addPermanentNotification).toHaveBeenCalledWith(
'streamChat.Wait until all attachments have uploaded'
);
});

it('should hide "Wait for upload" notification, if upload is finished', fakeAsync(() => {
const notificationService = TestBed.inject(NotificationService);
const removeNotificationSpy = jasmine.createSpy();
spyOn(notificationService, 'addPermanentNotification').and.returnValue(
removeNotificationSpy
);
uploadAttachmentsSpy.and.resolveTo([]);
void component.filesSelected([{ type: 'image/png' }] as any as FileList);
void component.messageSent();
tick();

expect(removeNotificationSpy).toHaveBeenCalledWith();
}));

it(`shouldn't send message, if file uploads are in progress - multiple uploads`, fakeAsync(() => {
uploadAttachmentsSpy.and.resolveTo([]);
void component.filesSelected([{ type: 'image/png' }] as any as FileList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class MessageInputComponent implements OnDestroy {
@ViewChild('input') private messageInput!: ElementRef<HTMLInputElement>;
@ViewChild('fileInput') private fileInput!: ElementRef<HTMLInputElement>;
private subscriptions: Subscription[] = [];
private hideNotification: Function | undefined;

constructor(
private channelService: ChannelService,
Expand All @@ -46,6 +47,12 @@ export class MessageInputComponent implements OnDestroy {
async messageSent(event?: Event) {
event?.preventDefault();
if (this.attachmentUploadInProgressCounter > 0) {
if (!this.hideNotification) {
this.hideNotification =
this.notificationService.addPermanentNotification(
'streamChat.Wait until all attachments have uploaded'
);
}
return;
}
const text = this.messageInput.nativeElement.value;
Expand Down Expand Up @@ -182,6 +189,10 @@ export class MessageInputComponent implements OnDestroy {
}
});
this.attachmentUploadInProgressCounter--;
if (this.attachmentUploadInProgressCounter === 0 && this.hideNotification) {
this.hideNotification();
this.hideNotification = undefined;
}
}

private clearFileInput() {
Expand Down