Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show no connection banner faster [#WPB-11568] #3776

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ import com.wire.android.util.CurrentScreenManager
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.call.Call
import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.sync.SyncState
import com.wire.kalium.logic.data.sync.SyncState.Failed
import com.wire.kalium.logic.data.sync.SyncState.GatheringPendingEvents
import com.wire.kalium.logic.data.sync.SyncState.Live
import com.wire.kalium.logic.data.sync.SyncState.SlowSync
import com.wire.kalium.logic.data.sync.SyncState.Waiting
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import com.wire.kalium.network.NetworkState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
Expand All @@ -40,7 +45,6 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import org.jetbrains.annotations.VisibleForTesting
import javax.inject.Inject
Expand All @@ -59,12 +63,19 @@ class CommonTopAppBarViewModel @Inject constructor(

private fun connectivityFlow(userId: UserId): Flow<Connectivity> =
coreLogic.sessionScope(userId) {
observeSyncState().map {
when (it) {
SyncState.Waiting -> Connectivity.WaitingConnection(null, null)
is SyncState.Failed -> Connectivity.WaitingConnection(it.cause, it.retryDelay)
SyncState.GatheringPendingEvents, SyncState.SlowSync -> Connectivity.Connecting
SyncState.Live -> Connectivity.Connected
combine(observeSyncState(), coreLogic.networkStateObserver.observeNetworkState()) { syncState, networkState ->
when (syncState) {
is Waiting -> Connectivity.WaitingConnection(null, null)
is Failed -> Connectivity.WaitingConnection(syncState.cause, syncState.retryDelay)
is GatheringPendingEvents,
is SlowSync -> Connectivity.Connecting

is Live ->
if (networkState is NetworkState.ConnectedWithInternet) {
Connectivity.Connected
} else {
Connectivity.WaitingConnection(null, null)
}
}
}
}
Expand Down
Loading