diff --git a/lib/Controller/ChatController.php b/lib/Controller/ChatController.php index 06b93319659..ea410faf840 100644 --- a/lib/Controller/ChatController.php +++ b/lib/Controller/ChatController.php @@ -214,6 +214,10 @@ public function parseCommentToResponse(IComment $comment, Message $parentMessage #[RequirePermission(permission: RequirePermission::CHAT)] #[RequireReadWriteConversation] 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 146518a3f17..7a9d5072481 100644 --- a/src/components/NewMessageForm/NewMessageForm.vue +++ b/src/components/NewMessageForm/NewMessageForm.vue @@ -439,7 +439,7 @@ export default { }, hasText() { - return this.text !== '' + return this.text.trim() !== '' }, containerElement() { @@ -592,12 +592,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 | [] |