#68 - create comment create working (notification to adapt)
This commit is contained in:
parent
3d4ddc12fc
commit
cf83edc1e6
11 changed files with 106 additions and 158 deletions
|
|
@ -9,49 +9,53 @@ return [
|
|||
$json = file_get_contents('php://input');
|
||||
$data = json_decode($json);
|
||||
|
||||
$parsedUrl = parse_url($data->path);
|
||||
$parsedUrl = parse_url($data->dialogUri);
|
||||
$query = $parsedUrl['query'] ?? null;
|
||||
parse_str($query, $queryParams);
|
||||
$stepSlug = $queryParams['dialog'] ?? null;
|
||||
|
||||
$targetPageUri = $stepSlug ? $parsedUrl['path'] . '/' . $stepSlug : $parsedUrl['path'];
|
||||
|
||||
$project = page($parsedUrl['path']);
|
||||
$page = page($targetPageUri);
|
||||
$file = $page->file($data->fileName);
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
$user = kirby()->user($data->userUuid);
|
||||
|
||||
$comments = $file->comments()->isEmpty() == true ? [] : Yaml::decode($file->comments()->value());
|
||||
|
||||
$data = [
|
||||
'href' => $data->path,
|
||||
'page' => $page,
|
||||
'file' => $file,
|
||||
'position' => [
|
||||
'pageIndex' => $data->position->pageIndex,
|
||||
'x' => $data->position->x,
|
||||
'y' => $data->position->y
|
||||
$commentData = [
|
||||
"location" => [
|
||||
"page" => $page,
|
||||
"project" => $project,
|
||||
"dialogUri" => $data->dialogUri,
|
||||
"file" => $file
|
||||
],
|
||||
'replies' => [],
|
||||
'text' => $data->text,
|
||||
'author' => $user,
|
||||
'date' => (string) $data->date,
|
||||
'id' => $data->id,
|
||||
'type' => 'comment'
|
||||
"position" => [
|
||||
"pageIndex" => $data->position->pageIndex,
|
||||
"x" => $data->position->x,
|
||||
"y" => $data->position->y
|
||||
],
|
||||
"date" => (string) $data->date,
|
||||
"text" => $data->text,
|
||||
"author" => kirby()->user(),
|
||||
"id" => Str::uuid(),
|
||||
"type" => "comment",
|
||||
];
|
||||
|
||||
$newComment = new Comment($data);
|
||||
$user->sendNotification($project, $commentData);
|
||||
|
||||
$newComment = new Comment($commentData);
|
||||
|
||||
$comments[] = $newComment->toArray();
|
||||
|
||||
$newFile = $file->update([
|
||||
'comments' => $comments
|
||||
]);
|
||||
]);
|
||||
|
||||
echo json_encode(getFileData($newFile));
|
||||
|
||||
try {
|
||||
$user->sendNotification($page->parent(), $newComment->toArray());
|
||||
$user->sendNotification($project, $commentData);
|
||||
} catch (\Throwable $th) {
|
||||
echo json_encode([
|
||||
"error" => $th->getMessage() . " in " . $th->getFile() . " line " . $th->getLine(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue