#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
|
|
@ -12,7 +12,7 @@ class Notification
|
|||
protected Author $author;
|
||||
protected string $date;
|
||||
protected string $id;
|
||||
protected string $isRead;
|
||||
protected string $isRead = "false";
|
||||
|
||||
protected ?Position $position = null;
|
||||
|
||||
|
|
@ -23,11 +23,6 @@ class Notification
|
|||
$this->author = new Author($data["author"]);
|
||||
$this->date = $data["date"];
|
||||
$this->id = $data["id"];
|
||||
$this->isRead = "false";
|
||||
|
||||
if ($data["type"] === "comment") {
|
||||
$this->position = new Position($data["position"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
|
|
@ -40,9 +35,6 @@ class Notification
|
|||
"id" => $this->id,
|
||||
"isRead" => $this->isRead,
|
||||
];
|
||||
if ($this->type === "comment") {
|
||||
$array["position"] = $this->position->toArray();
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,27 +16,26 @@ use adrienpayet\notifications\Notification;
|
|||
*/
|
||||
|
||||
return function ($project, $notificationData) {
|
||||
$recipients = $project->managers()->without($this);
|
||||
$recipients = $project->managers()->without($this);
|
||||
|
||||
if ($recipients->isEmpty()) return;
|
||||
if ($recipients->isEmpty()) return;
|
||||
|
||||
$notificationData['isRead'] = false;
|
||||
$newNotification = new Notification($notificationData);
|
||||
|
||||
foreach ($recipients as $otherUser) {
|
||||
try {
|
||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||
? Yaml::decode($otherUser->notifications()->value())
|
||||
: [];
|
||||
|
||||
$newNotification = new Notification($notificationData);
|
||||
$notifications[] = $newNotification->toArray();
|
||||
foreach ($recipients as $otherUser) {
|
||||
try {
|
||||
$notifications = $otherUser->notifications()->isNotEmpty()
|
||||
? Yaml::decode($otherUser->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $newNotification->toArray();
|
||||
|
||||
$otherUser->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage());
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
}
|
||||
$otherUser->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
error_log("Notification error for user " . $otherUser->email() . ": " . $th->getMessage());
|
||||
throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue