Stop notification using preference when disabled

This commit is contained in:
Valere 2019-06-24 10:04:03 +02:00 committed by Benoit Marty
parent 74099be316
commit c01af6ac78
4 changed files with 23 additions and 6 deletions

View File

@ -38,6 +38,7 @@ import im.vector.riotredesign.features.notifications.NotifiableEventResolver
import im.vector.riotredesign.features.notifications.NotifiableMessageEvent
import im.vector.riotredesign.features.notifications.NotificationDrawerManager
import im.vector.riotredesign.features.notifications.SimpleNotifiableEvent
import im.vector.riotredesign.features.settings.PreferencesManager
import org.koin.android.ext.android.inject
import timber.log.Timber

@ -61,6 +62,11 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
* @param message the message
*/
override fun onMessageReceived(message: RemoteMessage?) {
if (!PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
Timber.i("Notification are disabled for this device")
return
}

if (message == null || message.data == null) {
Timber.e("## onMessageReceived() : received a null message or message with no data")
return
@ -91,7 +97,9 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() {
if (refreshedToken == null) {
Timber.w("onNewToken:received null token")
} else {
pusherManager.registerPusherWithFcmKey(refreshedToken)
if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
pusherManager.registerPusherWithFcmKey(refreshedToken)
}
}
}


View File

@ -54,6 +54,7 @@ import im.vector.riotredesign.features.notifications.PushRuleTriggerListener
import im.vector.riotredesign.features.rageshake.VectorFileLogger
import im.vector.riotredesign.features.rageshake.VectorUncaughtExceptionHandler
import im.vector.riotredesign.features.roomdirectory.RoomDirectoryModule
import im.vector.riotredesign.features.settings.PreferencesManager
import im.vector.riotredesign.features.version.getVersion
import im.vector.riotredesign.push.fcm.FcmHelper
import org.koin.android.ext.android.get
@ -137,11 +138,12 @@ class VectorApplication : Application() {
} else {
//TODO check if notifications are enabled for this device
//We need to use alarm in this mode
if (Matrix.getInstance().currentSession != null) {
AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L)
Timber.i("Alarm scheduled to restart service")
if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) {
if (Matrix.getInstance().currentSession != null) {
AlarmSyncBroadcastReceiver.scheduleAlarm(applicationContext, 4_000L)
Timber.i("Alarm scheduled to restart service")
}
}

}
}


View File

@ -27,6 +27,7 @@ import im.vector.matrix.android.api.session.content.ContentUrlResolver
import im.vector.riotredesign.BuildConfig
import im.vector.riotredesign.R
import im.vector.riotredesign.core.utils.SecretStoringUtils
import im.vector.riotredesign.features.settings.PreferencesManager
import timber.log.Timber
import java.io.File
import java.io.FileInputStream
@ -65,6 +66,10 @@ class NotificationDrawerManager(val context: Context,
Events might be grouped and there might not be one notification per event!
*/
fun onNotifiableEventReceived(notifiableEvent: NotifiableEvent) {
if (!PreferencesManager.areNotificationEnabledForDevice(context)) {
Timber.i("Notification are disabled for this device")
return
}
//If we support multi session, event list should be per userId
//Currently only manage single session
if (BuildConfig.LOW_PRIVACY_LOG_ENABLE) {

View File

@ -35,7 +35,9 @@ class VectorSettingsNotificationPreferenceFragment : VectorPreferenceFragment()
val switchPref = preference as SwitchPreference
if (switchPref.isChecked) {
FcmHelper.getFcmToken(requireContext())?.let {
pushManager.registerPusherWithFcmKey(it)
if (PreferencesManager.areNotificationEnabledForDevice(requireContext())) {
pushManager.registerPusherWithFcmKey(it)
}
}
} else {
FcmHelper.getFcmToken(requireContext())?.let {