From f1320499480449b294eab1635a5de8df8a27d5fb Mon Sep 17 00:00:00 2001 From: isUnknown Date: Mon, 28 Oct 2024 15:02:28 +0100 Subject: [PATCH] fix send notification to users and create custom user method --- ...-bureaux-artistiquement-consideree.pdf.txt | 105 ++++++++++++++++++ public/site/config/routes/add-comment.php | 13 +-- public/site/plugins/user-methods/index.php | 27 +++++ 3 files changed, 133 insertions(+), 12 deletions(-) create mode 100644 public/site/plugins/user-methods/index.php diff --git a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt index 3054ff7..8226ab1 100644 --- a/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt +++ b/public/content/projects/1_miss-dior-blooming-bouquet/1_client-brief/38969543_extrait-de-louis-sullivan-form-follow-function.-de-la-tour-de-bureaux-artistiquement-consideree.pdf.txt @@ -18,6 +18,111 @@ Comments: username: Adrien Payet date: 2024-10-23T16:22:47+02:00 id: m2lyrs06 + m2t206b6: + text: Nouveau com + username: Adrien Payet + date: 2024-10-28T14:27:41+01:00 + id: m2t206b6 + m2t20ei0: + text: Et ebcore + username: Adrien Payet + date: 2024-10-28T14:27:51+01:00 + id: m2t20ei0 + m2t213jw: + text: test2 + username: Adrien Payet + date: 2024-10-28T14:28:24+01:00 + id: m2t213jw + m2t21e5f: + text: autre + username: Adrien Payet + date: 2024-10-28T14:28:38+01:00 + id: m2t21e5f + m2t21h7k: + text: sfgd + username: Adrien Payet + date: 2024-10-28T14:28:42+01:00 + id: m2t21h7k + m2t2sgrk: + text: test3 + username: Adrien Payet + date: 2024-10-28T14:49:41+01:00 + id: m2t2sgrk + m2t2sn60: + text: test4 + username: Adrien Payet + date: 2024-10-28T14:49:49+01:00 + id: m2t2sn60 + m2t2ux6u: + text: test5 + username: Adrien Payet + date: 2024-10-28T14:51:35+01:00 + id: m2t2ux6u + m2t2v0ba: + text: test6 + username: Adrien Payet + date: 2024-10-28T14:51:39+01:00 + id: m2t2v0ba + m2t2wak4: + text: test8 + username: Adrien Payet + date: 2024-10-28T14:52:39+01:00 + id: m2t2wak4 + m2t2z30f: + text: jfhj + username: Adrien Payet + date: 2024-10-28T14:54:49+01:00 + id: m2t2z30f + m2t2ze81: + text: qsvfh + username: Adrien Payet + date: 2024-10-28T14:55:04+01:00 + id: m2t2ze81 + m2t30udw: + text: fdgjh + username: Adrien Payet + date: 2024-10-28T14:56:12+01:00 + id: m2t30udw + m2t31bxv: + text: testl + username: Adrien Payet + date: 2024-10-28T14:56:34+01:00 + id: m2t31bxv + m2t32i8i: + text: dlakeja + username: Adrien Payet + date: 2024-10-28T14:57:29+01:00 + id: m2t32i8i + m2t33dra: + text: hfdts + username: Adrien Payet + date: 2024-10-28T14:58:10+01:00 + id: m2t33dra + m2t34im4: + text: lkqs + username: Adrien Payet + date: 2024-10-28T14:59:03+01:00 + id: m2t34im4 + m2t359np: + text: lqsjd + username: Adrien Payet + date: 2024-10-28T14:59:38+01:00 + id: m2t359np + m2t362kx: + text: ;sjn + username: Adrien Payet + date: 2024-10-28T15:00:16+01:00 + id: m2t362kx + m2t36rex: + text: jfghy + username: Adrien Payet + date: 2024-10-28T15:00:48+01:00 + id: m2t36rex + m2t37dx2: + text: dkdjsfn + username: Adrien Payet + date: 2024-10-28T15:01:17+01:00 + id: m2t37dx2 2: m2lys1bs: text: test diff --git a/public/site/config/routes/add-comment.php b/public/site/config/routes/add-comment.php index bf395c2..0a1eb01 100644 --- a/public/site/config/routes/add-comment.php +++ b/public/site/config/routes/add-comment.php @@ -29,18 +29,7 @@ return [ 'comments' => $comments ]); - foreach (kirby()->users()->without($user) as $otherUser) { - try { - $notifications = $otherUser->notifications()->isNotEmpty() ? $otherUser->notifications()->toArray() : ["comments" => []]; - $notifications['comments'][$data->id] = $newComment; - $otherUser->update([ - "notifications" => $notifications - ]); - } catch (\Throwable $th) { - throw new Exception($th->getMessage(), 1); - - } - } + $user->sendNotification('comments', $newComment); return getFileData($newFile); } diff --git a/public/site/plugins/user-methods/index.php b/public/site/plugins/user-methods/index.php new file mode 100644 index 0000000..1ec4257 --- /dev/null +++ b/public/site/plugins/user-methods/index.php @@ -0,0 +1,27 @@ + [ + 'sendNotification' => function ($group, $data) { + 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][$data['id']] = $data; + + $otherUser->update([ + 'notifications' => $notifications + ]); + } catch (\Throwable $th) { + throw new Exception("Error updating notifications: " . $th->getMessage() . ' line ' . $th->getLine(), 1); + } + } + } + ] +]);