feat: add resend notification action with push
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user