Only show connection warning if not actively connected.
This commit is contained in:
parent
3310762970
commit
4446510916
3 changed files with 30 additions and 5 deletions
|
@ -2,12 +2,11 @@ package org.thoughtcrime.securesms.dependencies
|
|||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Application
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||
import io.reactivex.rxjava3.subjects.Subject
|
||||
import okhttp3.OkHttpClient
|
||||
import org.signal.core.util.billing.BillingApi
|
||||
import org.signal.core.util.concurrent.DeadlockDetector
|
||||
import org.signal.core.util.concurrent.LatestValueObservable
|
||||
import org.signal.core.util.resettableLazy
|
||||
import org.signal.libsignal.net.Network
|
||||
import org.signal.libsignal.zkgroup.profiles.ClientZkProfileOperations
|
||||
|
@ -209,14 +208,14 @@ object AppDependencies {
|
|||
provider.provideBillingApi()
|
||||
}
|
||||
|
||||
private val _webSocketObserver: Subject<WebSocketConnectionState> = BehaviorSubject.create()
|
||||
private val _webSocketObserver: BehaviorSubject<WebSocketConnectionState> = BehaviorSubject.create()
|
||||
|
||||
/**
|
||||
* An observable that emits the current state of the WebSocket connection across the various lifecycles
|
||||
* of the [signalWebSocket].
|
||||
*/
|
||||
@JvmStatic
|
||||
val webSocketObserver: Observable<WebSocketConnectionState> = _webSocketObserver
|
||||
val webSocketObserver: LatestValueObservable<WebSocketConnectionState> = LatestValueObservable(_webSocketObserver)
|
||||
|
||||
private val _networkModule = resettableLazy {
|
||||
NetworkDependenciesModule(application, provider, _webSocketObserver)
|
||||
|
|
|
@ -14,10 +14,12 @@ import io.reactivex.rxjava3.schedulers.Schedulers
|
|||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||
import org.thoughtcrime.securesms.crash.CrashConfig
|
||||
import org.thoughtcrime.securesms.database.LogDatabase
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.notifications.DeviceSpecificNotificationConfig.ShowCondition
|
||||
import org.thoughtcrime.securesms.util.ConnectivityWarning
|
||||
import org.thoughtcrime.securesms.util.NetworkUtil
|
||||
import org.whispersystems.signalservice.api.websocket.WebSocketConnectionState
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.time.Duration.Companion.days
|
||||
|
||||
|
@ -72,8 +74,9 @@ class VitalsViewModel(private val context: Application) : AndroidViewModel(conte
|
|||
|
||||
val timeSinceLastConnection = System.currentTimeMillis() - SignalStore.misc.lastWebSocketConnectTime
|
||||
val timeSinceLastConnectionWarning = System.currentTimeMillis() - SignalStore.misc.lastConnectivityWarningTime
|
||||
val connectedToWebSocket = AppDependencies.webSocketObserver.value == WebSocketConnectionState.CONNECTED
|
||||
|
||||
if (ConnectivityWarning.isEnabled && timeSinceLastConnection > ConnectivityWarning.threshold && timeSinceLastConnectionWarning > 14.days.inWholeMilliseconds && NetworkUtil.isConnected(context) && SignalStore.account.isRegistered) {
|
||||
if (ConnectivityWarning.isEnabled && timeSinceLastConnection > ConnectivityWarning.threshold && timeSinceLastConnectionWarning > 14.days.inWholeMilliseconds && NetworkUtil.isConnected(context) && SignalStore.account.isRegistered && !connectedToWebSocket) {
|
||||
return@fromCallable if (ConnectivityWarning.isDebugPromptEnabled) {
|
||||
State.PROMPT_DEBUGLOGS_FOR_CONNECTIVITY_WARNING
|
||||
} else {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.util.concurrent
|
||||
|
||||
import io.reactivex.rxjava3.core.Observable
|
||||
import io.reactivex.rxjava3.core.Observer
|
||||
import io.reactivex.rxjava3.subjects.BehaviorSubject
|
||||
|
||||
/**
|
||||
* An Observer that provides instant access to the latest emitted value.
|
||||
* Basically a read-only version of [BehaviorSubject].
|
||||
*/
|
||||
class LatestValueObservable<T : Any>(private val subject: BehaviorSubject<T>) : Observable<T>() {
|
||||
val value: T?
|
||||
get() = subject.value
|
||||
|
||||
override fun subscribeActual(observer: Observer<in T>) {
|
||||
subject.subscribe(observer)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue