diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index bafa1b1ab64..cb3a570f0b5 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -204,6 +204,10 @@ public function parseCommentToResponse(IComment $comment, Message $parentMessage * found". */ public function sendMessage(string $message, string $actorDisplayName = '', string $referenceId = '', int $replyTo = 0, bool $silent = false): DataResponse { + if (trim($message) === '') { + return new DataResponse([], Http::STATUS_BAD_REQUEST); + } + [$actorType, $actorId] = $this->getActorInfo($actorDisplayName); if (!$actorId) { return new DataResponse([], Http::STATUS_NOT_FOUND); diff --git a/src/components/NewMessageForm/NewMessageForm.vue b/src/components/NewMessageForm/NewMessageForm.vue index 782435381a4..bd3528afa22 100644 --- a/src/components/NewMessageForm/NewMessageForm.vue +++ b/src/components/NewMessageForm/NewMessageForm.vue @@ -407,7 +407,7 @@ export default { }, hasText() { - return this.text !== '' + return this.text.trim() !== '' }, containerElement() { @@ -540,12 +540,15 @@ export default { } } - if (this.text !== '') { + if (this.hasText) { // FIXME: remove after issue is resolved: https://github.com/nextcloud/nextcloud-vue/issues/3264 const temp = document.createElement('textarea') temp.innerHTML = this.text this.text = temp.value - const temporaryMessage = await this.$store.dispatch('createTemporaryMessage', { text: this.text, token: this.token }) + const temporaryMessage = await this.$store.dispatch('createTemporaryMessage', { + text: this.text.trim(), + token: this.token, + }) // FIXME: move "addTemporaryMessage" into "postNewMessage" as it's a pre-requisite anyway ? if (!this.broadcast) { await this.$store.dispatch('addTemporaryMessage', temporaryMessage) diff --git a/tests/integration/features/chat/group.feature b/tests/integration/features/chat/group.feature index 9021ce8c90f..b8cb1ec22ca 100644 --- a/tests/integration/features/chat/group.feature +++ b/tests/integration/features/chat/group.feature @@ -59,6 +59,7 @@ Feature: chat/group | invite | attendees1 | When user "participant1" sends message "Message 1" to room "group room" with 201 And user "participant2" sends message "Message 2" to room "group room" with 201 + And user "participant2" sends message "" to room "group room" with 400 Then user "participant1" sees the following messages in room "group room" with 200 | room | actorType | actorId | actorDisplayName | message | messageParameters | | group room | users | participant2 | participant2-displayname | Message 2 | [] |