From d022a9094b9d9881aeef21e36dba2c155d728b78 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Tue, 11 Feb 2025 18:45:23 +0100 Subject: [PATCH] comments : do not add duplicate comments --- public/site/plugins/comments/routes/create.php | 6 ++++++ src/components/comments/Comments.vue | 1 + 2 files changed, 7 insertions(+) diff --git a/public/site/plugins/comments/routes/create.php b/public/site/plugins/comments/routes/create.php index 3068d0d..c2f67b7 100644 --- a/public/site/plugins/comments/routes/create.php +++ b/public/site/plugins/comments/routes/create.php @@ -19,6 +19,12 @@ return [ $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); + foreach ($comments as $existingComment) { + if ($existingComment['author']['email'] === $user->email() && $existingComment['text'] === $data->text) { + return json_encode(null); + } + } + $commentData = [ 'location' => [ 'page' => $page, diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index 9d31aff..df729a1 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -222,6 +222,7 @@ async function addComment(newComment) { const newFile = await api.addComment(newComment); resetDraftComment(); isAddOpen.value = false; + if (!newFile) return; dialog.updateFile(newFile); if (activeTracks.value) { activeTracks.value = activeTracks.value.map((track) => {