From f18bc9bd00d6383b69d8b15e083726020526846a Mon Sep 17 00:00:00 2001 From: ganfra Date: Thu, 27 Jun 2019 19:12:46 +0200 Subject: [PATCH] Dagger: fix no session --- .../internal/session/pushers/DefaultPusherService.kt | 10 ++++++++-- .../gplay/push/fcm/VectorFirebaseMessagingService.kt | 2 +- .../vector/riotredesign/core/pushers/PushersManager.kt | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt index aafe781f..103bdb71 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/pushers/DefaultPusherService.kt @@ -15,8 +15,13 @@ */ package im.vector.matrix.android.internal.session.pushers +import android.content.Context import androidx.lifecycle.LiveData -import androidx.work.* +import androidx.work.BackoffPolicy +import androidx.work.Constraints +import androidx.work.NetworkType +import androidx.work.OneTimeWorkRequestBuilder +import androidx.work.WorkManager import com.zhuinden.monarchy.Monarchy import im.vector.matrix.android.api.MatrixCallback import im.vector.matrix.android.api.auth.data.SessionParams @@ -37,6 +42,7 @@ import javax.inject.Inject internal class DefaultPusherService @Inject constructor( + private val context: Context, private val monarchy: Monarchy, private val sessionParam: SessionParams, private val getPusherTask: GetPushersTask, @@ -93,7 +99,7 @@ internal class DefaultPusherService @Inject constructor( .setInputData(WorkerParamsFactory.toData(params)) .setBackoffCriteria(BackoffPolicy.LINEAR, 10_000L, TimeUnit.MILLISECONDS) .build() - WorkManager.getInstance().enqueue(request) + WorkManager.getInstance(context).enqueue(request) return request.id } diff --git a/vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt index bd30e5c9..6386cb5a 100755 --- a/vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/riotredesign/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -105,7 +105,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { if (refreshedToken == null) { Timber.w("onNewToken:received null token") } else { - if (PreferencesManager.areNotificationEnabledForDevice(applicationContext)) { + if (PreferencesManager.areNotificationEnabledForDevice(applicationContext) && activeSessionHolder.hasActiveSession()) { pusherManager.registerPusherWithFcmKey(refreshedToken) } } diff --git a/vector/src/main/java/im/vector/riotredesign/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/riotredesign/core/pushers/PushersManager.kt index 5d2ee895..cfc77576 100644 --- a/vector/src/main/java/im/vector/riotredesign/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/riotredesign/core/pushers/PushersManager.kt @@ -36,7 +36,7 @@ class PushersManager @Inject constructor( } fun unregisterPusher(pushKey: String, callback: MatrixCallback) { - val currentSession = activeSessionHolder.getActiveSession() + val currentSession = activeSessionHolder.getSafeActiveSession() ?: return currentSession.removeHttpPusher(pushKey, stringProvider.getString(R.string.pusher_app_id), callback) } } \ No newline at end of file