Skip to content

Commit 732045d

Browse files
authored
Merge pull request #98 from GetStream/upload-not-finished-notification
fix: Notify if message sent before upload end #97
2 parents 2903205 + 3755273 commit 732045d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,32 @@ describe('MessageInputComponent', () => {
237237
});
238238

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

244246
expect(sendMessageSpy).not.toHaveBeenCalled();
247+
expect(notificationService.addPermanentNotification).toHaveBeenCalledWith(
248+
'streamChat.Wait until all attachments have uploaded'
249+
);
245250
});
246251

252+
it('should hide "Wait for upload" notification, if upload is finished', fakeAsync(() => {
253+
const notificationService = TestBed.inject(NotificationService);
254+
const removeNotificationSpy = jasmine.createSpy();
255+
spyOn(notificationService, 'addPermanentNotification').and.returnValue(
256+
removeNotificationSpy
257+
);
258+
uploadAttachmentsSpy.and.resolveTo([]);
259+
void component.filesSelected([{ type: 'image/png' }] as any as FileList);
260+
void component.messageSent();
261+
tick();
262+
263+
expect(removeNotificationSpy).toHaveBeenCalledWith();
264+
}));
265+
247266
it(`shouldn't send message, if file uploads are in progress - multiple uploads`, fakeAsync(() => {
248267
uploadAttachmentsSpy.and.resolveTo([]);
249268
void component.filesSelected([{ type: 'image/png' }] as any as FileList);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export class MessageInputComponent implements OnDestroy {
2525
@ViewChild('input') private messageInput!: ElementRef<HTMLInputElement>;
2626
@ViewChild('fileInput') private fileInput!: ElementRef<HTMLInputElement>;
2727
private subscriptions: Subscription[] = [];
28+
private hideNotification: Function | undefined;
2829

2930
constructor(
3031
private channelService: ChannelService,
@@ -46,6 +47,12 @@ export class MessageInputComponent implements OnDestroy {
4647
async messageSent(event?: Event) {
4748
event?.preventDefault();
4849
if (this.attachmentUploadInProgressCounter > 0) {
50+
if (!this.hideNotification) {
51+
this.hideNotification =
52+
this.notificationService.addPermanentNotification(
53+
'streamChat.Wait until all attachments have uploaded'
54+
);
55+
}
4956
return;
5057
}
5158
const text = this.messageInput.nativeElement.value;
@@ -182,6 +189,10 @@ export class MessageInputComponent implements OnDestroy {
182189
}
183190
});
184191
this.attachmentUploadInProgressCounter--;
192+
if (this.attachmentUploadInProgressCounter === 0 && this.hideNotification) {
193+
this.hideNotification();
194+
this.hideNotification = undefined;
195+
}
185196
}
186197

187198
private clearFileInput() {

0 commit comments

Comments
 (0)