fix: filter FCM sends by notifications_enabled preference
This commit is contained in:
@@ -299,6 +299,18 @@ class AdminController
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($userId) {
|
||||||
|
$userModel = new User();
|
||||||
|
$targetUser = $userModel->findById($userId);
|
||||||
|
if (!$targetUser || empty($targetUser['notifications_enabled'])) {
|
||||||
|
$this->view->json([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Notification saved to database. User has notifications disabled.',
|
||||||
|
]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$notificationModel = new Notification();
|
$notificationModel = new Notification();
|
||||||
$noteId = $notificationModel->create([
|
$noteId = $notificationModel->create([
|
||||||
'user_id' => $userId,
|
'user_id' => $userId,
|
||||||
|
|||||||
@@ -54,6 +54,12 @@ class FCMService
|
|||||||
{
|
{
|
||||||
if (!$this->isConfigured()) return false;
|
if (!$this->isConfigured()) return false;
|
||||||
|
|
||||||
|
$enabled = $this->db->fetch(
|
||||||
|
'SELECT notifications_enabled FROM users WHERE id = ? AND notifications_enabled = 1',
|
||||||
|
[$userId]
|
||||||
|
);
|
||||||
|
if (!$enabled) return false;
|
||||||
|
|
||||||
$tokens = $this->db->fetchAll(
|
$tokens = $this->db->fetchAll(
|
||||||
'SELECT id, token FROM user_fcm_tokens WHERE user_id = ?',
|
'SELECT id, token FROM user_fcm_tokens WHERE user_id = ?',
|
||||||
[$userId]
|
[$userId]
|
||||||
@@ -78,7 +84,11 @@ class FCMService
|
|||||||
{
|
{
|
||||||
if (!$this->isConfigured()) return 0;
|
if (!$this->isConfigured()) return 0;
|
||||||
|
|
||||||
$tokens = $this->db->fetchAll('SELECT id, token FROM user_fcm_tokens');
|
$tokens = $this->db->fetchAll(
|
||||||
|
'SELECT f.id, f.token FROM user_fcm_tokens f
|
||||||
|
JOIN users u ON u.id = f.user_id
|
||||||
|
WHERE u.notifications_enabled = 1'
|
||||||
|
);
|
||||||
if (empty($tokens)) return 0;
|
if (empty($tokens)) return 0;
|
||||||
|
|
||||||
$sent = 0;
|
$sent = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user