diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/EventService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/EventService.kt index 3169c8107c..297f277497 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/EventService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/session/events/EventService.kt @@ -23,10 +23,7 @@ interface EventService { /** * Ask the homeserver for an event content. The SDK will try to decrypt it if it is possible * The result will not be stored into cache - * @param onlyOnWifi if true and if WiFi is not available, no request will be done, - * and null will be returned */ suspend fun getEvent(roomId: String, - eventId: String, - onlyOnWifi: Boolean): Event? + eventId: String): Event } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt index 45b772f138..d7e9ef2ee0 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/events/DefaultEventService.kt @@ -18,24 +18,16 @@ package org.matrix.android.sdk.internal.session.events import org.matrix.android.sdk.api.session.events.EventService import org.matrix.android.sdk.api.session.events.model.Event -import org.matrix.android.sdk.internal.network.WifiDetector import org.matrix.android.sdk.internal.session.call.CallEventProcessor import org.matrix.android.sdk.internal.session.room.timeline.GetEventTask -import timber.log.Timber import javax.inject.Inject internal class DefaultEventService @Inject constructor( private val getEventTask: GetEventTask, - private val callEventProcessor: CallEventProcessor, - private val wifiDetector: WifiDetector + private val callEventProcessor: CallEventProcessor ) : EventService { - override suspend fun getEvent(roomId: String, eventId: String, onlyOnWifi: Boolean): Event? { - if (onlyOnWifi && !wifiDetector.isConnectedToWifi()) { - Timber.d("No WiFi network, do not get Event") - return null - } - + override suspend fun getEvent(roomId: String, eventId: String): Event { val event = getEventTask.execute(GetEventTask.Params(roomId, eventId)) // Fast lane to the call event processors: try to make the incoming call ring faster diff --git a/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt b/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt index edde8e69b9..4cefeadb62 100755 --- a/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/push/fcm/VectorFirebaseMessagingService.kt @@ -31,6 +31,7 @@ import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.extensions.vectorComponent +import im.vector.app.core.network.WifiDetector import im.vector.app.core.pushers.PushersManager import im.vector.app.features.badge.BadgeProxy import im.vector.app.features.notifications.NotifiableEventResolver @@ -43,6 +44,7 @@ import im.vector.app.push.fcm.FcmHelper import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.pushrules.Action import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.events.model.Event @@ -58,6 +60,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { private lateinit var pusherManager: PushersManager private lateinit var activeSessionHolder: ActiveSessionHolder private lateinit var vectorPreferences: VectorPreferences + private lateinit var wifiDetector: WifiDetector private val coroutineScope = CoroutineScope(SupervisorJob()) @@ -74,6 +77,7 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { pusherManager = pusherManager() activeSessionHolder = activeSessionHolder() vectorPreferences = vectorPreferences() + wifiDetector = wifiDetector() } } @@ -188,9 +192,14 @@ class VectorFirebaseMessagingService : FirebaseMessagingService() { return } + if (wifiDetector.isConnectedToWifi().not()) { + Timber.d("No WiFi network, do not get Event") + return + } + coroutineScope.launch { Timber.d("Fast lane: start request") - val event = session.getEvent(roomId, eventId, onlyOnWifi = true) ?: return@launch + val event = tryOrNull { session.getEvent(roomId, eventId) } ?: return@launch val resolvedEvent = notifiableEventResolver.resolveInMemoryEvent(session, event) diff --git a/vector/src/main/java/im/vector/app/core/di/VectorComponent.kt b/vector/src/main/java/im/vector/app/core/di/VectorComponent.kt index cae7a2ece6..4b88ff6767 100644 --- a/vector/src/main/java/im/vector/app/core/di/VectorComponent.kt +++ b/vector/src/main/java/im/vector/app/core/di/VectorComponent.kt @@ -26,6 +26,7 @@ import im.vector.app.EmojiCompatWrapper import im.vector.app.VectorApplication import im.vector.app.core.dialogs.UnrecognizedCertificateDialog import im.vector.app.core.error.ErrorFormatter +import im.vector.app.core.network.WifiDetector import im.vector.app.core.pushers.PushersManager import im.vector.app.core.utils.AssetReader import im.vector.app.core.utils.DimensionConverter @@ -140,6 +141,8 @@ interface VectorComponent { fun vectorPreferences(): VectorPreferences + fun wifiDetector(): WifiDetector + fun vectorFileLogger(): VectorFileLogger fun uiStateRepository(): UiStateRepository diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/WifiDetector.kt b/vector/src/main/java/im/vector/app/core/network/WifiDetector.kt similarity index 90% rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/WifiDetector.kt rename to vector/src/main/java/im/vector/app/core/network/WifiDetector.kt index b1ae4e3b94..34b2a7590d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/WifiDetector.kt +++ b/vector/src/main/java/im/vector/app/core/network/WifiDetector.kt @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 The Matrix.org Foundation C.I.C. + * Copyright (c) 2021 New Vector Ltd * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.matrix.android.sdk.internal.network +package im.vector.app.core.network import android.content.Context import android.net.ConnectivityManager @@ -25,7 +25,7 @@ import org.matrix.android.sdk.api.extensions.orFalse import timber.log.Timber import javax.inject.Inject -internal class WifiDetector @Inject constructor( +class WifiDetector @Inject constructor( context: Context ) { private val connectivityManager = context.getSystemService()!!