mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-26 03:16:02 +03:00
Move WifiDetector to the app side
And protect the call to getEvent()
This commit is contained in:
parent
dead57b9fe
commit
7309c1066c
5 changed files with 19 additions and 18 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<ConnectivityManager>()!!
|
Loading…
Reference in a new issue