From 0a674941d63587b0458c26510c9f04750bc62d60 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 May 2023 07:15:28 +0200 Subject: [PATCH 1/2] fix(chat): Prevent empty chat messages on API level Signed-off-by: Joas Schilling --- lib/Controller/ChatController.php | 4 ++++ tests/integration/features/chat/group.feature | 1 + 2 files changed, 5 insertions(+) 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/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 | [] | From 26131c77f8bae84ccb7cab1f858e4d7d2b7193c7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Wed, 10 May 2023 07:15:49 +0200 Subject: [PATCH 2/2] fix(chat): Prevent submitting empty messages in the UI Signed-off-by: Joas Schilling --- src/components/NewMessageForm/NewMessageForm.vue | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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)