2024-10-29 11:35:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
2024-10-30 09:56:16 +01:00
|
|
|
use adrienpayet\comments\Reply;
|
|
|
|
|
|
2024-10-29 11:35:48 +01:00
|
|
|
return [
|
2024-10-29 16:51:31 +01:00
|
|
|
'pattern' => '(:all)reply-comment.json',
|
2024-10-29 11:35:48 +01:00
|
|
|
'method' => 'POST',
|
|
|
|
|
'action' => function () {
|
|
|
|
|
$json = file_get_contents('php://input');
|
|
|
|
|
$data = json_decode($json);
|
|
|
|
|
|
2024-12-20 12:36:21 +01:00
|
|
|
$page = page($data->fileParentUri);
|
2025-01-15 14:18:48 +01:00
|
|
|
|
2024-10-29 11:35:48 +01:00
|
|
|
$file = $page->file($data->fileName);
|
2024-12-18 18:39:45 +01:00
|
|
|
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
2024-10-29 11:35:48 +01:00
|
|
|
|
2024-10-30 13:29:26 +01:00
|
|
|
foreach ($comments as &$comment) {
|
2024-12-19 10:32:48 +01:00
|
|
|
$isParentComment = $comment['id'] === $data->parentId;
|
|
|
|
|
if ($isParentComment) {
|
|
|
|
|
$replyData = [
|
|
|
|
|
"location" => [
|
|
|
|
|
"page" => $page,
|
|
|
|
|
"file" => $file,
|
|
|
|
|
"parent" => $comment
|
|
|
|
|
],
|
|
|
|
|
"position" => [
|
2024-12-20 12:36:21 +01:00
|
|
|
"pageIndex" => $data->position->pageIndex ?? null,
|
2024-12-19 10:32:48 +01:00
|
|
|
],
|
|
|
|
|
"date" => (string) $data->date,
|
|
|
|
|
"text" => $data->text,
|
|
|
|
|
"author" => kirby()->user(),
|
|
|
|
|
"id" => Str::uuid(),
|
|
|
|
|
"type" => "comment-reply",
|
2026-01-15 10:31:31 +01:00
|
|
|
"readby" => [], // Pour le système de notifications dérivées
|
2024-12-19 10:32:48 +01:00
|
|
|
];
|
|
|
|
|
$newReply = new Reply($replyData);
|
2024-10-30 13:29:26 +01:00
|
|
|
$comment['replies'][] = $newReply->toArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-15 10:31:31 +01:00
|
|
|
|
2024-10-29 11:35:48 +01:00
|
|
|
$newFile = $file->update([
|
|
|
|
|
'comments' => $comments
|
|
|
|
|
]);
|
|
|
|
|
|
2026-01-15 10:31:31 +01:00
|
|
|
// Note: Les notifications sont maintenant dérivées des commentaires.
|
|
|
|
|
// Plus besoin d'appeler createNotification().
|
2024-10-29 11:35:48 +01:00
|
|
|
|
|
|
|
|
return getFileData($newFile);
|
|
|
|
|
}
|
|
|
|
|
];
|