Skip to content

Commit 735a219

Browse files
Merge pull request #1827 from session-foundation/fix/SES-5105-debug-pro-stats
SES-5105 - Make sure the debug loading state is also used for pro stats
2 parents 051f204 + f56770b commit 735a219

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

app/src/main/java/org/thoughtcrime/securesms/preferences/prosettings/ProSettingsViewModel.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import org.session.libsession.utilities.TextSecurePreferences
4747
import org.session.libsession.utilities.withMutableUserConfigs
4848
import org.session.libsignal.utilities.Log
4949
import org.thoughtcrime.securesms.debugmenu.DebugLogGroup
50+
import org.thoughtcrime.securesms.debugmenu.DebugMenuViewModel
5051
import org.thoughtcrime.securesms.preferences.prosettings.ProSettingsViewModel.Commands.ShowOpenUrlDialog
5152
import org.thoughtcrime.securesms.pro.ProDataState
5253
import org.thoughtcrime.securesms.pro.ProDetailsRepository
@@ -850,10 +851,18 @@ class ProSettingsViewModel @AssistedInject constructor(
850851

851852
private fun refreshProStats(){
852853
viewModelScope.launch {
854+
// if we have a debug toggle for the loading state, respect it
855+
val currentDebugState = prefs.getDebugProPlanStatus()
856+
val debugState = when(currentDebugState) {
857+
DebugMenuViewModel.DebugProPlanStatus.LOADING -> State.Loading
858+
DebugMenuViewModel.DebugProPlanStatus.ERROR -> State.Error(Exception())
859+
else -> null
860+
}
861+
853862
// show a loader for the stats
854863
_proSettingsUIState.update {
855864
it.copy(
856-
proStats = State.Loading
865+
proStats = debugState ?: State.Loading
857866
)
858867
}
859868

@@ -882,14 +891,14 @@ class ProSettingsViewModel @AssistedInject constructor(
882891

883892
// update ui with results
884893
_proSettingsUIState.update {
885-
it.copy(proStats = State.Success(stats))
894+
it.copy(proStats = debugState ?: State.Success(stats))
886895
}
887896
} catch (e: Exception) {
888897
// currently the UI doesn't have an error display
889898
// it will look like it's still loading
890899
// but the logic is there in case we have a look for stats errors
891900
_proSettingsUIState.update {
892-
it.copy(proStats = State.Error(e))
901+
it.copy(proStats = debugState ?: State.Error(e))
893902
}
894903
}
895904
}

0 commit comments

Comments
 (0)