Skip to content

Commit b76b751

Browse files
authored
Merge pull request #261 from GetStream/fix-message-with-spaces
Fix message with spaces
2 parents 14ef557 + f7a08c6 commit b76b751

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
"@ctrl/ngx-emoji-mart": "^6.2.0",
112112
"@ngx-translate/core": "^13.0.0",
113113
"@ngx-translate/http-loader": "^6.0.0",
114-
"@stream-io/stream-chat-css": "2.7.0",
114+
"@stream-io/stream-chat-css": "2.8.1",
115115
"@stream-io/transliterate": "^1.5.2",
116116
"angular-mentions": "^1.4.0",
117117
"dayjs": "^1.10.7",

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,36 @@ describe('MessageInputComponent', () => {
441441
expect(sendMessageSpy).not.toHaveBeenCalled();
442442
});
443443

444+
it(`shouldn't send messages with only spaces`, () => {
445+
const textarea = queryTextarea();
446+
component.textareaValue = ' '; // single space
447+
textarea?.send.next();
448+
fixture.detectChanges();
449+
450+
expect(sendMessageSpy).not.toHaveBeenCalled();
451+
});
452+
453+
it(`should remove text if attachments are uploaded, but text contains only space characters`, () => {
454+
attachmentService.mapToAttachments.and.returnValue([
455+
{
456+
type: 'image',
457+
img_url: 'url',
458+
},
459+
]);
460+
const textarea = queryTextarea();
461+
component.textareaValue = ' '; // multiple spaces
462+
textarea?.send.next();
463+
fixture.detectChanges();
464+
465+
expect(sendMessageSpy).toHaveBeenCalledWith(
466+
'',
467+
jasmine.any(Array),
468+
jasmine.any(Object),
469+
undefined,
470+
undefined
471+
);
472+
});
473+
444474
it('should apply CSS class if attachments are present', () => {
445475
const cssClass = 'str-chat__input-flat-has-attachments';
446476

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,17 @@ export class MessageInputComponent
290290
return;
291291
}
292292
const attachments = this.attachmentService.mapToAttachments();
293-
const text = this.textareaValue;
294-
if (!text && (!attachments || attachments.length === 0)) {
293+
let text = this.textareaValue;
294+
const textContainsOnlySpaceChars = !text.replace(/ /g, ''); //spcae
295+
if (
296+
(!text || textContainsOnlySpaceChars) &&
297+
(!attachments || attachments.length === 0)
298+
) {
295299
return;
296300
}
301+
if (textContainsOnlySpaceChars) {
302+
text = '';
303+
}
297304
if (this.containsLinks && !this.canSendLinks) {
298305
this.notificationService.addTemporaryNotification(
299306
'streamChat.Sending links is not allowed in this conversation'

0 commit comments

Comments
 (0)