content notification read working
This commit is contained in:
parent
ffb8252808
commit
94c5737245
21 changed files with 317 additions and 163 deletions
|
|
@ -8,7 +8,7 @@ class Location
|
|||
protected ?string $dialogUri = null;
|
||||
protected ProjectDetails $project;
|
||||
protected ?FileDetails $file = null;
|
||||
protected ?string $parentCommentId = null;
|
||||
protected ?array $parent = null;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
|
|
@ -19,19 +19,17 @@ class Location
|
|||
if (isset($data['file'])) {
|
||||
$this->file = new FileDetails($data["file"]);
|
||||
}
|
||||
if (isset($data["parentCommentId"])) {
|
||||
$this->parentCommentId();
|
||||
if (isset($data["parent"])) {
|
||||
$this->parent = [
|
||||
"author" => [
|
||||
"name" => $data["parent"]["author"]["name"],
|
||||
"email" => $data["parent"]["author"]["email"],
|
||||
],
|
||||
"id" => $data["parent"]["id"]
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
public function setParentCommentId($id) {
|
||||
$this->parentCommentId = $id;
|
||||
}
|
||||
|
||||
public function parentId() {
|
||||
return $this->parentCommentId;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = [
|
||||
"page" => $this->page->toArray(),
|
||||
|
|
@ -46,8 +44,8 @@ class Location
|
|||
$array["file"] = $this->file;
|
||||
}
|
||||
|
||||
if ($this->parentCommentId) {
|
||||
$array["parentId"] = $this->parentCommentId;
|
||||
if ($this->parent) {
|
||||
$array["parent"] = $this->parent;
|
||||
}
|
||||
|
||||
return $array;
|
||||
|
|
|
|||
|
|
@ -24,28 +24,27 @@ return [
|
|||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$replyData = [
|
||||
"location" => [
|
||||
"page" => $page,
|
||||
"project" => $project,
|
||||
"dialogUri" => $data->dialogUri,
|
||||
"file" => $file,
|
||||
],
|
||||
"parentId" => $data->parentId,
|
||||
"position" => [
|
||||
"pageIndex" => $data->position->pageIndex,
|
||||
],
|
||||
"date" => (string) $data->date,
|
||||
"text" => $data->text,
|
||||
"author" => kirby()->user(),
|
||||
"id" => Str::uuid(),
|
||||
"type" => "comment",
|
||||
];
|
||||
|
||||
$newReply = new Reply($replyData);
|
||||
|
||||
foreach ($comments as &$comment) {
|
||||
if ($comment['id'] === $newReply->parentId()) {
|
||||
$isParentComment = $comment['id'] === $data->parentId;
|
||||
if ($isParentComment) {
|
||||
$replyData = [
|
||||
"location" => [
|
||||
"page" => $page,
|
||||
"project" => $project,
|
||||
"dialogUri" => $data->dialogUri,
|
||||
"file" => $file,
|
||||
"parent" => $comment
|
||||
],
|
||||
"position" => [
|
||||
"pageIndex" => $data->position->pageIndex,
|
||||
],
|
||||
"date" => (string) $data->date,
|
||||
"text" => $data->text,
|
||||
"author" => kirby()->user(),
|
||||
"id" => Str::uuid(),
|
||||
"type" => "comment-reply",
|
||||
];
|
||||
$newReply = new Reply($replyData);
|
||||
$comment['replies'][] = $newReply->toArray();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ use adrienpayet\D2P\data\Author;
|
|||
use adrienpayet\D2P\data\Position;
|
||||
|
||||
class BaseComment {
|
||||
protected string $type;
|
||||
protected Location $location;
|
||||
protected Author $author;
|
||||
protected string $text;
|
||||
|
|
|
|||
|
|
@ -7,11 +7,6 @@ class Reply extends BaseComment {
|
|||
|
||||
public function __construct($data) {
|
||||
parent::__construct($data);
|
||||
$this->location->setParentCommentId($data["parentId"]);
|
||||
}
|
||||
|
||||
public function parentId() {
|
||||
return $this->location->parentId();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class Notification
|
|||
protected Author $author;
|
||||
protected string $date;
|
||||
protected string $id;
|
||||
protected string $isRead = "false";
|
||||
protected string $isread = "false";
|
||||
|
||||
protected ?Position $position = null;
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ class Notification
|
|||
"author" => $this->author->toArray(),
|
||||
"date" => $this->date,
|
||||
"id" => $this->id,
|
||||
"isRead" => $this->isRead,
|
||||
"isread" => $this->isread,
|
||||
];
|
||||
|
||||
return $array;
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ return function($notificationId) {
|
|||
foreach ($notifications as $key => $notification) {
|
||||
if (!isset($notification['id'])) continue;
|
||||
if ($notification['id'] === $notificationId) {
|
||||
$notifications[$key]['isRead'] = true;
|
||||
$notifications[$key]['isread'] = "true";
|
||||
$newNotification = $notifications[$key];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ return function() {
|
|||
|
||||
$newNotification = null;
|
||||
foreach ($notifications as $key => $notification) {
|
||||
$notifications[$key]['isRead'] = true;
|
||||
$notifications[$key]['isread'] = true;
|
||||
}
|
||||
|
||||
$updatedUser = $this->update([
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue