'(:all)reply-comment.json', 'method' => 'POST', 'action' => function () { $json = file_get_contents('php://input'); $data = json_decode($json); $page = page($data->fileParentUri); $file = $page->file($data->fileName); $comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value()); foreach ($comments as &$comment) { $isParentComment = $comment['id'] === $data->parentId; if ($isParentComment) { $replyData = [ "location" => [ "page" => $page, "file" => $file, "parent" => $comment ], "position" => [ "pageIndex" => $data->position->pageIndex ?? null, ], "date" => (string) $data->date, "text" => $data->text, "author" => kirby()->user(), "id" => Str::uuid(), "type" => "comment-reply", "readby" => [], // Pour le système de notifications dérivées ]; $newReply = new Reply($replyData); $comment['replies'][] = $newReply->toArray(); } } $newFile = $file->update([ 'comments' => $comments ]); // Note: Les notifications sont maintenant dérivées des commentaires. // Plus besoin d'appeler createNotification(). return getFileData($newFile); } ];