Merge pull request 'fix: remove redundant NotificationPoller to prevent duplicate notifications' (#82) from feat/version-update-notification into master
Reviewed-on: #82
This commit was merged in pull request #82.
This commit is contained in:
@@ -13,8 +13,8 @@ android {
|
|||||||
applicationId = "com.devlab.app"
|
applicationId = "com.devlab.app"
|
||||||
minSdk = 26
|
minSdk = 26
|
||||||
targetSdk = 37
|
targetSdk = 37
|
||||||
versionCode = 16
|
versionCode = 17
|
||||||
versionName = "1.8.4"
|
versionName = "1.8.5"
|
||||||
}
|
}
|
||||||
|
|
||||||
buildTypes {
|
buildTypes {
|
||||||
|
|||||||
@@ -62,19 +62,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
requestNotificationPermission()
|
requestNotificationPermission()
|
||||||
checkForUpdates()
|
checkForUpdates()
|
||||||
|
|
||||||
lifecycle.addObserver(LifecycleEventObserver { _, event ->
|
|
||||||
when (event) {
|
|
||||||
Lifecycle.Event.ON_RESUME -> {
|
|
||||||
ServerManagerApp.instance.notificationPoller?.start()
|
|
||||||
ServerManagerApp.instance.notificationPoller?.checkNow()
|
|
||||||
}
|
|
||||||
Lifecycle.Event.ON_PAUSE -> {
|
|
||||||
ServerManagerApp.instance.notificationPoller?.stop()
|
|
||||||
}
|
|
||||||
else -> {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
setContent {
|
setContent {
|
||||||
ServerManagerTheme {
|
ServerManagerTheme {
|
||||||
AppRoot()
|
AppRoot()
|
||||||
@@ -158,15 +145,6 @@ fun AppRoot() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DisposableEffect(Unit) {
|
|
||||||
ServerManagerApp.instance.notificationPoller?.onCountChanged = { count ->
|
|
||||||
unreadCount = count
|
|
||||||
}
|
|
||||||
onDispose {
|
|
||||||
ServerManagerApp.instance.notificationPoller?.onCountChanged = null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
bottomBar = {
|
bottomBar = {
|
||||||
if (inLoggedInArea) {
|
if (inLoggedInArea) {
|
||||||
|
|||||||
@@ -3,20 +3,15 @@ package com.devlab.app
|
|||||||
import android.app.Application
|
import android.app.Application
|
||||||
import com.devlab.app.service.NotificationForegroundService
|
import com.devlab.app.service.NotificationForegroundService
|
||||||
import com.devlab.app.util.NotificationHelper
|
import com.devlab.app.util.NotificationHelper
|
||||||
import com.devlab.app.util.NotificationPoller
|
|
||||||
import com.devlab.app.worker.NotificationWorker
|
import com.devlab.app.worker.NotificationWorker
|
||||||
|
|
||||||
class ServerManagerApp : Application() {
|
class ServerManagerApp : Application() {
|
||||||
var notificationPoller: NotificationPoller? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
override fun onCreate() {
|
override fun onCreate() {
|
||||||
super.onCreate()
|
super.onCreate()
|
||||||
instance = this
|
instance = this
|
||||||
NotificationHelper.createChannels(this)
|
NotificationHelper.createChannels(this)
|
||||||
NotificationWorker.schedule(this)
|
NotificationWorker.schedule(this)
|
||||||
NotificationForegroundService.start(this)
|
NotificationForegroundService.start(this)
|
||||||
notificationPoller = NotificationPoller(this)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
Binary file not shown.
@@ -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