refactor deleteNotification method
This commit is contained in:
parent
82f4aaf904
commit
fe56312f20
6 changed files with 70 additions and 33 deletions
|
|
@ -40,11 +40,14 @@ return [
|
|||
'comments' => $comments
|
||||
]);
|
||||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
try {
|
||||
$user->sendNotification($page->parent()->uri(), $newComment->toArray());
|
||||
} catch (\Throwable $th) {
|
||||
throw new Exception($th->getMessage(), 1);
|
||||
}
|
||||
return getFileData($newFile);
|
||||
|
||||
exit;
|
||||
}
|
||||
];
|
||||
|
|
@ -30,32 +30,16 @@ return [
|
|||
}
|
||||
}
|
||||
|
||||
$comments = array_values($comments); // Réindexe les commentaires
|
||||
$comments = array_values($comments);
|
||||
|
||||
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
|
||||
]);
|
||||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
kirby()->user()->deleteNotification($page, $data->id);
|
||||
|
||||
return getFileData($newFile);
|
||||
exit;
|
||||
}
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue