read comment working
This commit is contained in:
parent
583daa1759
commit
39fc379541
12 changed files with 125 additions and 78 deletions
|
|
@ -12,5 +12,6 @@ Kirby::plugin('adrienpayet/kirby4-comments', [
|
|||
require(__DIR__ . '/routes/update.php'),
|
||||
require(__DIR__ . '/routes/delete.php'),
|
||||
require(__DIR__ . '/routes/reply.php'),
|
||||
require(__DIR__ . '/routes/read.php'),
|
||||
]
|
||||
]);
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ return [
|
|||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
kirby()->user()->deleteNotification($page, $data->id);
|
||||
kirby()->user()->deleteNotification($page->managers()->toUsers(), $data->id);
|
||||
|
||||
exit;
|
||||
}
|
||||
|
|
|
|||
28
public/site/plugins/comments/routes/read.php
Normal file
28
public/site/plugins/comments/routes/read.php
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<?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()
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
|
|
@ -43,6 +43,7 @@ class BaseComment {
|
|||
$this->date = $date;
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
$this->isRead = false;
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
|
|
@ -78,6 +79,20 @@ class BaseComment {
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
public function isRead() {
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function read() {
|
||||
$this->isRead = true;
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function unread() {
|
||||
$this->isRead = false;
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function pageIndex() {
|
||||
$this->position['pageIndex'];
|
||||
}
|
||||
|
|
@ -93,6 +108,7 @@ class BaseComment {
|
|||
'date' => $this->date,
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
'isRead' => $this->isRead
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue