feat: track notification read receipts per user

- New notification_reads table (migration 008) with unique (notification_id, user_id)
- Notification model: markAsRead inserts into notification_reads; getForUser JOINs
  to show per-user read status; getUnreadCount checks NOT EXISTS in reads table
- getAll() includes read_count subquery for admin view
- Admin view shows 'X / Y' read count for broadcast notifications,
  'Read'/'Unread' badge for user-targeted ones
- Migrates existing read notifications into notification_reads
- AGENTS.md updated with new conventions
This commit is contained in:
2026-06-13 11:48:05 -04:00
parent b94ae16f69
commit 12c3e23d9c
6 changed files with 106 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
<?php
$notifications = $notifications ?? [];
$users = $users ?? [];
$totalActiveUsers = $totalActiveUsers ?? 0;
$data = $notifications['data'] ?? [];
?>
@@ -27,7 +28,7 @@ $data = $notifications['data'] ?? [];
<th>Title</th>
<th>Message</th>
<th>Target</th>
<th>Status</th>
<th>Read by</th>
</tr>
</thead>
<tbody>
@@ -53,9 +54,16 @@ $data = $notifications['data'] ?? [];
<td><?= htmlspecialchars(mb_substr($note['message'] ?? '', 0, 80)) ?><?= mb_strlen($note['message'] ?? '') > 80 ? '...' : '' ?></td>
<td><?= $note['user_id'] ? htmlspecialchars($note['target_username'] ?? "User #{$note['user_id']}") : '<em>All Users</em>' ?></td>
<td>
<span class="status-badge <?= $note['is_read'] ? 'status-online' : 'status-offline' ?>">
<?= $note['is_read'] ? 'Read' : 'Unread' ?>
</span>
<?php if ($note['user_id']): ?>
<span class="status-badge <?= ($note['read_count'] ?? 0) > 0 ? 'status-online' : 'status-offline' ?>">
<?= ($note['read_count'] ?? 0) > 0 ? 'Read' : 'Unread' ?>
</span>
<?php else: ?>
<?php $rc = (int) ($note['read_count'] ?? 0); ?>
<span class="badge badge-<?= $rc >= $totalActiveUsers ? 'success' : ($rc > 0 ? 'warning' : 'secondary') ?>">
<?= $rc ?> / <?= $totalActiveUsers ?>
</span>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>