designtopack/public/site/plugins/comments/routes/read.php
2024-11-18 09:36:15 +01:00

28 lines
768 B
PHP

<?php
return [
'pattern' => '(:all)read-comment.json',
'method' => 'POST',
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
try {
$newNotification = kirby()->user()->readNotification($data->notificationId);
if ($newNotification) {
return [
"success" => "Notification read.",
"data" => $newNotification
];
} else {
throw new Exception("Can't find corresponding notification.", 1);
}
} catch (\Throwable $th) {
return [
"error" => $th->getMessage(),
"notificationId" => $data->notificationId,
"userName" => kirby()->user()->name()->value()
];
}
}
];