mark as unread if comment is in notifications working
This commit is contained in:
parent
b99f7c81dd
commit
65a2bbaa8d
4 changed files with 36 additions and 3 deletions
|
|
@ -6,4 +6,15 @@ Uuid: s0lNtRA0Z7ybTCWG
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
Template: document
|
Template: document
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
Comments:
|
||||||
|
|
||||||
|
1:
|
||||||
|
m2lyhnf7:
|
||||||
|
text: nouveau com
|
||||||
|
username: Adrien Payet
|
||||||
|
date: 2024-10-23T16:14:54+02:00
|
||||||
|
id: m2lyhnf7
|
||||||
|
|
@ -20,15 +20,28 @@ return [
|
||||||
'text' => $data->text,
|
'text' => $data->text,
|
||||||
'username' => $user->name()->isNotEmpty() ? (string) $user->name() : (string) $user->email(),
|
'username' => $user->name()->isNotEmpty() ? (string) $user->name() : (string) $user->email(),
|
||||||
'date' => (string) $data->date,
|
'date' => (string) $data->date,
|
||||||
|
'id' => $data->id
|
||||||
];
|
];
|
||||||
|
|
||||||
$comments[$data->targetPage][$data->id] = $newComment;
|
$comments[$data->targetPage][$data->id] = $newComment;
|
||||||
|
|
||||||
|
|
||||||
$newFile = $file->update([
|
$newFile = $file->update([
|
||||||
'comments' => $comments
|
'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);
|
return getFileData($newFile);
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
user: {
|
user: {
|
||||||
role: '<?= $kirby->user()->role() ?>',
|
role: '<?= $kirby->user()->role() ?>',
|
||||||
uuid: '<?= $kirby->user()->uuid() ?>',
|
uuid: '<?= $kirby->user()->uuid() ?>',
|
||||||
|
notifications: <?= json_encode(Yaml::decode($kirby->user()->notifications()->value())) ?>
|
||||||
<?php if ($kirby->user()->role() == 'client'): ?>
|
<?php if ($kirby->user()->role() == 'client'): ?>
|
||||||
client: {
|
client: {
|
||||||
name: '<?= $kirby->user()->client()->toPage()->title() ?>',
|
name: '<?= $kirby->user()->client()->toPage()->title() ?>',
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
v-for="(comment, commentIndex) in Object.values(page)"
|
v-for="(comment, commentIndex) in Object.values(page)"
|
||||||
:key="pageIndex + commentIndex"
|
:key="pageIndex + commentIndex"
|
||||||
class="comment | flow"
|
class="comment | flow"
|
||||||
data-status="unread"
|
:data-status="setStatus(comment)"
|
||||||
>
|
>
|
||||||
<header>
|
<header>
|
||||||
<p>
|
<p>
|
||||||
|
|
@ -131,4 +131,12 @@ function closeAddField() {
|
||||||
isAddOpen.value = false;
|
isAddOpen.value = false;
|
||||||
newCommentText.value = "";
|
newCommentText.value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setStatus(comment) {
|
||||||
|
if (user?.notifications?.comments.hasOwnProperty(comment.id)) {
|
||||||
|
return "unread";
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue