From 65a2bbaa8da7c44b5aaef247f42342646885bcb6 Mon Sep 17 00:00:00 2001 From: isUnknown Date: Wed, 23 Oct 2024 16:19:33 +0200 Subject: [PATCH] mark as unread if comment is in notifications working --- ...r-de-bureaux-artistiquement-consideree.pdf.txt | 13 ++++++++++++- public/site/config/routes/add-comment.php | 15 ++++++++++++++- public/site/snippets/footer.php | 1 + src/components/comments/Comments.vue | 10 +++++++++- 4 files changed, 36 insertions(+), 3 deletions(-) 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 cb27a3c..3460644 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 @@ -6,4 +6,15 @@ Uuid: s0lNtRA0Z7ybTCWG ---- -Template: document \ No newline at end of file +Template: document + +---- + +Comments: + +1: + m2lyhnf7: + text: nouveau com + username: Adrien Payet + date: 2024-10-23T16:14:54+02:00 + id: m2lyhnf7 \ No newline at end of file diff --git a/public/site/config/routes/add-comment.php b/public/site/config/routes/add-comment.php index 7090833..bf395c2 100644 --- a/public/site/config/routes/add-comment.php +++ b/public/site/config/routes/add-comment.php @@ -20,15 +20,28 @@ return [ 'text' => $data->text, 'username' => $user->name()->isNotEmpty() ? (string) $user->name() : (string) $user->email(), 'date' => (string) $data->date, + 'id' => $data->id ]; $comments[$data->targetPage][$data->id] = $newComment; - $newFile = $file->update([ '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); + + } + } + return getFileData($newFile); } ]; \ No newline at end of file diff --git a/public/site/snippets/footer.php b/public/site/snippets/footer.php index 0526bd8..598ef71 100644 --- a/public/site/snippets/footer.php +++ b/public/site/snippets/footer.php @@ -4,6 +4,7 @@ user: { role: 'user()->role() ?>', uuid: 'user()->uuid() ?>', + notifications: user()->notifications()->value())) ?> user()->role() == 'client'): ?> client: { name: 'user()->client()->toPage()->title() ?>', diff --git a/src/components/comments/Comments.vue b/src/components/comments/Comments.vue index dd6cc65..d77c8ae 100644 --- a/src/components/comments/Comments.vue +++ b/src/components/comments/Comments.vue @@ -7,7 +7,7 @@ v-for="(comment, commentIndex) in Object.values(page)" :key="pageIndex + commentIndex" class="comment | flow" - data-status="unread" + :data-status="setStatus(comment)" >

@@ -131,4 +131,12 @@ function closeAddField() { isAddOpen.value = false; newCommentText.value = ""; } + +function setStatus(comment) { + if (user?.notifications?.comments.hasOwnProperty(comment.id)) { + return "unread"; + } else { + return undefined; + } +}