change notifications structure from object to array

This commit is contained in:
isUnknown 2024-10-30 12:15:28 +01:00
parent 0d25794b87
commit 20824983a6
8 changed files with 64 additions and 50 deletions

View file

@ -12,23 +12,43 @@ Template: document
Comments:
m2vpa4tb:
-
page:
uri: >
projects/miss-dior-blooming-bouquet/client-brief
title: Brief client
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
pageIndex: 1
replies: [ ]
text: test
user:
text: Premier commentaire
author:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-10-30T10:54:49+01:00
id: m2vpa4tb
date: 2024-10-30T12:08:36+01:00
id: m2vrx0ls
type: comment
isRead: false
position:
x: null
y: null
-
page:
uri: projects/miss-dior-blooming-bouquet
title: Miss Dior Blooming Bouquet
file:
uuid: file://s0lNtRA0Z7ybTCWG
pageIndex: 1
replies: [ ]
text: Deuxième commentaire
author:
name: Utilisateur Dior
email: utilisateur@dior.com
uuid: user://HfuumN8s
role: client
date: 2024-10-30T12:08:41+01:00
id: m2vrx4zz
type: comment
isRead: false
position:

View file

@ -26,7 +26,7 @@ return [
],
'replies' => [],
'text' => $data->text,
'user' => $user,
'author' => $user,
'date' => (string) $data->date,
'id' => $data->id,
'type' => 'comment'
@ -34,13 +34,13 @@ return [
$newComment = new Comment($data);
$comments[$newComment->id()] = $newComment->toArray();
$comments[] = $newComment->toArray();
$newFile = $file->update([
'comments' => $comments
]);
$user->sendNotification('comments', $newComment);
$user->sendNotification($newComment);
return getFileData($newFile);
}

View file

@ -9,7 +9,7 @@ class BaseComment {
protected $position;
protected $replies;
protected $text;
protected $user;
protected $author;
protected $date;
protected $id;
protected $type;
@ -21,7 +21,7 @@ class BaseComment {
$filePageIndex = $data['filePageIndex'];
$replies = $data['replies'] ?? [];
$text = $data['text'];
$user = $data['user'];
$author = $data['author'];
$date = $data['date'];
$id = $data['id'];
$type = $data['type'] ?? 'comment';
@ -36,11 +36,11 @@ class BaseComment {
];
$this->replies = $replies ?? [];
$this->text = $text;
$this->user = [
'name' => (string) $user->name(),
'email' => (string) $user->email(),
'uuid' => (string) $user->uuid(),
'role' => (string) $user->role(),
$this->author = [
'name' => (string) $author->name(),
'email' => (string) $author->email(),
'uuid' => (string) $author->uuid(),
'role' => (string) $author->role(),
];
$this->date = $date;
$this->id = $id;
@ -64,8 +64,8 @@ class BaseComment {
return $this->text;
}
public function user() {
return $this->user;
public function author() {
return $this->author;
}
public function date() {
@ -100,7 +100,7 @@ class BaseComment {
'file' => $this->file,
'replies' => $this->replies,
'text' => $this->text,
'user' => $this->user,
'author' => $this->author,
'date' => $this->date,
'id' => $this->id,
'type' => $this->type,

View file

@ -1,17 +1,13 @@
<?php
return function ($group, $item) {
return function ($item) {
foreach (kirby()->users()->not($this) as $otherUser) {
try {
$notifications = $otherUser->notifications()->isNotEmpty()
? Yaml::decode($otherUser->notifications()->value())
: [];
if (!isset($notifications[$group])) {
$notifications[$group] = [];
}
$notifications[$group][$item->id()] = $item->toArray();
$notifications[] = $item->toArray();
$otherUser->update([
'notifications' => $notifications