add notifications plugin + created reply comment route
This commit is contained in:
parent
b332c6d871
commit
c3860d4a38
6 changed files with 53 additions and 5 deletions
|
|
@ -26,7 +26,6 @@ return [
|
|||
require(__DIR__ . '/routes/save-file.php'),
|
||||
require(__DIR__ . '/routes/remove-file.php'),
|
||||
require(__DIR__ . '/routes/upload-pdf.php'),
|
||||
require(__DIR__ . '/routes/read-notification.php'),
|
||||
],
|
||||
'hooks' => [
|
||||
'page.create:after' => require_once(__DIR__ . '/hooks/create-steps.php'),
|
||||
|
|
|
|||
42
public/site/plugins/comments/routes/reply.php
Normal file
42
public/site/plugins/comments/routes/reply.php
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)create-comment.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$page = page($data->pageUri);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$newComment = [
|
||||
'pageUri' => $data->pageUri,
|
||||
'fileUuid' => (string) $file->uuid(),
|
||||
'filePageTarget' => $data->targetPage,
|
||||
'text' => $data->text,
|
||||
'user' => [
|
||||
'name' => (string) $user->name(),
|
||||
'email' => (string) $user->email(),
|
||||
'uuid' => (string) $user->uuid(),
|
||||
'role' => (string) $user->role()
|
||||
],
|
||||
'date' => (string) $data->date,
|
||||
'id' => $data->id,
|
||||
];
|
||||
|
||||
$comments[$data->parentId]['replies'][$data->id] = $newComment;
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
]);
|
||||
|
||||
$user->sendNotification('comments', $newComment);
|
||||
|
||||
return getFileData($newFile);
|
||||
}
|
||||
];
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)create-comment.json',
|
||||
'pattern' => '(:all)update-comment.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
|
|
@ -21,7 +21,7 @@ return [
|
|||
'comments' => $comments
|
||||
]);
|
||||
|
||||
// $user->sendNotification('comments', $comments[$data->id]);
|
||||
$user->sendNotification('comments', $comments[$data->id]);
|
||||
|
||||
return getFileData($newFile);
|
||||
}
|
||||
|
|
|
|||
7
public/site/plugins/notifications/index.php
Normal file
7
public/site/plugins/notifications/index.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
Kirby::plugin('adrienpayet/pdc-notifications', [
|
||||
'routes' => [
|
||||
require(__DIR__ . '/routes/mark-as-read.php'),
|
||||
]
|
||||
]);
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
'pattern' => '(:all)read-notification.json',
|
||||
'pattern' => '(:all)mark-as-read.json',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$json = file_get_contents('php://input');
|
||||
|
|
@ -154,7 +154,7 @@ export const useApiStore = defineStore("api", () => {
|
|||
}),
|
||||
};
|
||||
try {
|
||||
const response = await fetch("/read-notification.json", headers);
|
||||
const response = await fetch("/mark-as-read.json", headers);
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue