diff --git a/package-lock.json b/package-lock.json index ee2c5953..ef23101d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -20,7 +20,7 @@ "@ctrl/ngx-emoji-mart": "^6.2.0", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "^6.0.0", - "@stream-io/stream-chat-css": "2.7.0", + "@stream-io/stream-chat-css": "2.8.1", "@stream-io/transliterate": "^1.5.2", "angular-mentions": "^1.4.0", "dayjs": "^1.10.7", @@ -3994,9 +3994,9 @@ "dev": true }, "node_modules/@stream-io/stream-chat-css": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/@stream-io/stream-chat-css/-/stream-chat-css-2.7.0.tgz", - "integrity": "sha512-4F2QfXHV8YwIA/ifex0KwmpleKwfjIfUWSJWK8XRDc5hkr6GW4zIrxBtWsPIFsDvB/+9Vtonfn8kaYuV5G4bwQ==" + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/@stream-io/stream-chat-css/-/stream-chat-css-2.8.1.tgz", + "integrity": "sha512-8TwtjgzoULhioi71KICh0+yuB4ZT5wWbwpG5zVPlfWGEpuYlCnDVapDUuM9VhjIh5vt5Zd6sgq0rUGxYCeQA0w==" }, "node_modules/@stream-io/transliterate": { "version": "1.5.2", @@ -30250,9 +30250,9 @@ "dev": true }, "@stream-io/stream-chat-css": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/@stream-io/stream-chat-css/-/stream-chat-css-2.7.0.tgz", - "integrity": "sha512-4F2QfXHV8YwIA/ifex0KwmpleKwfjIfUWSJWK8XRDc5hkr6GW4zIrxBtWsPIFsDvB/+9Vtonfn8kaYuV5G4bwQ==" + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/@stream-io/stream-chat-css/-/stream-chat-css-2.8.1.tgz", + "integrity": "sha512-8TwtjgzoULhioi71KICh0+yuB4ZT5wWbwpG5zVPlfWGEpuYlCnDVapDUuM9VhjIh5vt5Zd6sgq0rUGxYCeQA0w==" }, "@stream-io/transliterate": { "version": "1.5.2", diff --git a/package.json b/package.json index dc841d21..13eb1981 100644 --- a/package.json +++ b/package.json @@ -111,7 +111,7 @@ "@ctrl/ngx-emoji-mart": "^6.2.0", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "^6.0.0", - "@stream-io/stream-chat-css": "2.7.0", + "@stream-io/stream-chat-css": "2.8.1", "@stream-io/transliterate": "^1.5.2", "angular-mentions": "^1.4.0", "dayjs": "^1.10.7", diff --git a/projects/stream-chat-angular/src/lib/message-input/message-input.component.spec.ts b/projects/stream-chat-angular/src/lib/message-input/message-input.component.spec.ts index 8631e17f..14ae6b98 100644 --- a/projects/stream-chat-angular/src/lib/message-input/message-input.component.spec.ts +++ b/projects/stream-chat-angular/src/lib/message-input/message-input.component.spec.ts @@ -441,6 +441,36 @@ describe('MessageInputComponent', () => { expect(sendMessageSpy).not.toHaveBeenCalled(); }); + it(`shouldn't send messages with only spaces`, () => { + const textarea = queryTextarea(); + component.textareaValue = ' '; // single space + textarea?.send.next(); + fixture.detectChanges(); + + expect(sendMessageSpy).not.toHaveBeenCalled(); + }); + + it(`should remove text if attachments are uploaded, but text contains only space characters`, () => { + attachmentService.mapToAttachments.and.returnValue([ + { + type: 'image', + img_url: 'url', + }, + ]); + const textarea = queryTextarea(); + component.textareaValue = ' '; // multiple spaces + textarea?.send.next(); + fixture.detectChanges(); + + expect(sendMessageSpy).toHaveBeenCalledWith( + '', + jasmine.any(Array), + jasmine.any(Object), + undefined, + undefined + ); + }); + it('should apply CSS class if attachments are present', () => { const cssClass = 'str-chat__input-flat-has-attachments'; diff --git a/projects/stream-chat-angular/src/lib/message-input/message-input.component.ts b/projects/stream-chat-angular/src/lib/message-input/message-input.component.ts index 3959383b..ccfc867d 100644 --- a/projects/stream-chat-angular/src/lib/message-input/message-input.component.ts +++ b/projects/stream-chat-angular/src/lib/message-input/message-input.component.ts @@ -290,10 +290,17 @@ export class MessageInputComponent return; } const attachments = this.attachmentService.mapToAttachments(); - const text = this.textareaValue; - if (!text && (!attachments || attachments.length === 0)) { + let text = this.textareaValue; + const textContainsOnlySpaceChars = !text.replace(/ /g, ''); //spcae + if ( + (!text || textContainsOnlySpaceChars) && + (!attachments || attachments.length === 0) + ) { return; } + if (textContainsOnlySpaceChars) { + text = ''; + } if (this.containsLinks && !this.canSendLinks) { this.notificationService.addTemporaryNotification( 'streamChat.Sending links is not allowed in this conversation'