add / readNotification working

This commit is contained in:
isUnknown 2024-10-28 17:50:40 +01:00
parent 722c6b198e
commit ed73b33234
6 changed files with 159 additions and 20 deletions

View file

@ -26,4 +26,54 @@ Comments:
text: Autre commentaire
username: Utilisateur Dior
date: 2024-10-28T16:52:39+01:00
id: m2t76m4t
id: m2t76m4t
m2t7pg5m:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 1
text: Nouveau commentaire
username: Adrien Payet
date: 2024-10-28T17:07:18+01:00
id: m2t7pg5m
m2t82m8c:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 1
text: test
username: Adrien Payet
date: 2024-10-28T17:17:32+01:00
id: m2t82m8c
m2t83fp2:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 1
text: tt
username: Adrien Payet
date: 2024-10-28T17:18:11+01:00
id: m2t83fp2
m2t83syr:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 1
text: test
username: Adrien Payet
date: 2024-10-28T17:18:28+01:00
id: m2t83syr
m2t85i0w:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 1
text: test
username: Adrien Payet
date: 2024-10-28T17:19:47+01:00
id: m2t85i0w
m2t8ayc5:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 1
text: test
username: Adrien Payet
date: 2024-10-28T17:24:01+01:00
id: m2t8ayc5
2:
m2t8bv59:
fileUuid: file://s0lNtRA0Z7ybTCWG
page: 2
text: test 40
username: Adrien Payet
date: 2024-10-28T17:24:44+01:00
id: m2t8bv59

View file

@ -27,6 +27,7 @@ return [
require(__DIR__ . '/routes/remove-file.php'),
require(__DIR__ . '/routes/upload-pdf.php'),
require(__DIR__ . '/routes/add-comment.php'),
require(__DIR__ . '/routes/read-notification.php'),
],
'hooks' => [
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),

View file

@ -0,0 +1,15 @@
<?php
return [
'pattern' => '(:all)read-notification.json',
'method' => 'POST',
'action' => function () {
$json = file_get_contents('php://input');
$data = json_decode($json);
$user = kirby()->user($data->userUuid);
$newNotifications = $user->readNotification($data->group, $data->notificationId);
return $newNotifications;
}
];

View file

@ -13,6 +13,9 @@ Kirby::plugin('adrienpayet/pdc-user-methods', [
$notifications[$group] = [];
}
$data['isRead'] = false;
$notifications[$group][$data['id']] = $data;
$otherUser->update([
@ -22,6 +25,20 @@ Kirby::plugin('adrienpayet/pdc-user-methods', [
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
}
}
},
'readNotification' => function ($group, $notificationId) {
$notifications = Yaml::decode($this->notifications()->value());
try {
$notifications[$group][$notificationId]['isRead'] = true;
} catch (\Throwable $th) {
//throw $th;
}
$this->update([
"notifications" => $notifications
]);
return $notifications;
}
]
]);