diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt index fe45d56..83d0a8e 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt @@ -19,53 +19,15 @@ Comments: file: uuid: file://s0lNtRA0Z7ybTCWG pageIndex: 1 - replies: - - - page: - uri: projects/miss-dior-blooming-bouquet - title: Miss Dior Blooming Bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - pageIndex: 1 - replies: [ ] - text: Test de réponse - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-10-30T12:26:44+01:00 - id: m2vskcko - type: comment - isRead: false - parentId: m2vsk6jn - - - page: - uri: projects/miss-dior-blooming-bouquet - title: Miss Dior Blooming Bouquet - file: - uuid: file://s0lNtRA0Z7ybTCWG - pageIndex: 1 - replies: [ ] - text: deuxième réponse - author: - name: Adrien Payet - email: adrien.payet@outlook.com - uuid: user://WWjXgPWk - role: admin - date: 2024-10-30T12:27:42+01:00 - id: m2vslkxg - type: comment - isRead: false - parentId: m2vsk6jn - text: Un premier commentaire + replies: [ ] + text: Un certain commentaire author: name: Adrien Payet email: adrien.payet@outlook.com uuid: user://WWjXgPWk role: admin - date: 2024-10-30T12:26:37+01:00 - id: m2vsk6jn + date: 2024-10-30T16:26:22+01:00 + id: m2w14iph type: comment isRead: false position: diff --git a/public/site/plugins/comments/routes/delete.php b/public/site/plugins/comments/routes/delete.php index 9c5bced..cc3ac57 100644 --- a/public/site/plugins/comments/routes/delete.php +++ b/public/site/plugins/comments/routes/delete.php @@ -7,14 +7,50 @@ return [ $json = file_get_contents('php://input'); $data = json_decode($json); - $page = page($data->pageUri); - $file = $page->file($data->fileName); - $user = kirby()->user($data->userUuid); - + $page = page($data->page->uri); + $file = $page->file($data->file->uuid); + $isReply = $data->parentId ?? false; $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); - unset($comments[$data->id] ); + foreach ($comments as $key => &$comment) { + if ($isReply) { + if ($comment['id'] === $data->parentId) { + foreach ($comment['replies'] as $replyKey => $reply) { + if ($reply['id'] === $data->id) { + unset($comment['replies'][$replyKey]); + $comment['replies'] = array_values($comment['replies']); + } + } + } + } else { + if ($comment['id'] === $data->id) { + unset($comments[$key]); + } + } + } + + $comments = array_values($comments); // Réindexe les commentaires + + foreach (kirby()->users() as $user) { + try { + $notifications = $user->notifications()->isNotEmpty() + ? Yaml::decode($user->notifications()->value()) + : []; + + foreach ($notifications as $key => $notification) { + if ($notification['id'] === $data->id) { + unset($notifications[$key]); + } + } + + $user->update([ + 'notifications' => $notifications + ]); + } catch (\Throwable $th) { + throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); + } + } $newFile = $file->update([ 'comments' => $comments @@ -22,4 +58,4 @@ return [ return getFileData($newFile); } -]; \ No newline at end of file +]; diff --git a/src/components/comments/Comment.vue b/src/components/comments/Comment.vue index 9c249fa..370af66 100644 --- a/src/components/comments/Comment.vue +++ b/src/components/comments/Comment.vue @@ -8,20 +8,36 @@ • Page {{ comment.file.pageIndex }} - +
{{ comment.text }}
-