feat: add resend notification action with push

This commit is contained in:
2026-06-14 10:05:19 -04:00
parent aea0a4d189
commit a25ebdcb75
4 changed files with 65 additions and 5 deletions

View File

@@ -315,6 +315,41 @@ class AdminController
$this->view->json(['success' => true, 'message' => 'Notification deleted.']);
}
public function resendNotification(int $id): void
{
$this->requireSuperAdmin();
$notificationModel = new Notification();
$note = $notificationModel->findById($id);
if (!$note) {
$this->view->json(['success' => false, 'message' => 'Notification not found.'], 404);
}
$title = $note['title'];
$message = $note['message'];
$type = $note['type'] ?? 'info';
$userId = $note['user_id'] ? (int) $note['user_id'] : null;
$fcm = new FCMService();
$pushResult = '';
if ($userId) {
$sent = $fcm->sendToUser($userId, $title, $message, $type, $id);
$pushResult = $sent ? ' (push sent)' : ($fcm->isConfigured() ? ' (push failed)' : '');
} else {
$count = $fcm->sendToAll($title, $message, $type, $id);
$pushResult = $fcm->isConfigured() ? " (push sent to {$count} devices)" : '';
}
$this->auditService->log('notification_resent', 'notification', $id, [
'title' => $title,
'target' => $userId ? "user #{$userId}" : 'all users',
'push' => $fcm->isConfigured() ? 'sent' : 'not_configured',
]);
$this->view->json(['success' => true, 'message' => 'Notification resent successfully.' . $pushResult]);
}
public function sendNotification(): void
{
$this->requireSuperAdmin();