|
|
@ -24,11 +24,11 @@ import org.thoughtcrime.securesms.crypto.KeyPairUtilities
|
|
|
|
import org.thoughtcrime.securesms.dependencies.ConfigFactory
|
|
|
|
import org.thoughtcrime.securesms.dependencies.ConfigFactory
|
|
|
|
|
|
|
|
|
|
|
|
internal class PickDisplayNameViewModel(
|
|
|
|
internal class PickDisplayNameViewModel(
|
|
|
|
pickNewName: Boolean,
|
|
|
|
private val loadFailed: Boolean,
|
|
|
|
private val prefs: TextSecurePreferences,
|
|
|
|
private val prefs: TextSecurePreferences,
|
|
|
|
private val configFactory: ConfigFactory
|
|
|
|
private val configFactory: ConfigFactory
|
|
|
|
): ViewModel() {
|
|
|
|
): ViewModel() {
|
|
|
|
private val _states = MutableStateFlow(if (pickNewName) pickNewNameState() else State())
|
|
|
|
private val _states = MutableStateFlow(if (loadFailed) pickNewNameState() else State())
|
|
|
|
val states = _states.asStateFlow()
|
|
|
|
val states = _states.asStateFlow()
|
|
|
|
|
|
|
|
|
|
|
|
private val _events = MutableSharedFlow<Event>()
|
|
|
|
private val _events = MutableSharedFlow<Event>()
|
|
|
@ -48,6 +48,7 @@ internal class PickDisplayNameViewModel(
|
|
|
|
else -> {
|
|
|
|
else -> {
|
|
|
|
prefs.setProfileName(displayName)
|
|
|
|
prefs.setProfileName(displayName)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!loadFailed) {
|
|
|
|
// This is here to resolve a case where the app restarts before a user completes onboarding
|
|
|
|
// This is here to resolve a case where the app restarts before a user completes onboarding
|
|
|
|
// which can result in an invalid database state
|
|
|
|
// which can result in an invalid database state
|
|
|
|
database.clearAllLastMessageHashes()
|
|
|
|
database.clearAllLastMessageHashes()
|
|
|
@ -65,6 +66,7 @@ internal class PickDisplayNameViewModel(
|
|
|
|
prefs.setLocalRegistrationId(registrationID)
|
|
|
|
prefs.setLocalRegistrationId(registrationID)
|
|
|
|
prefs.setLocalNumber(userHexEncodedPublicKey)
|
|
|
|
prefs.setLocalNumber(userHexEncodedPublicKey)
|
|
|
|
prefs.setRestorationTime(0)
|
|
|
|
prefs.setRestorationTime(0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
viewModelScope.launch { _events.emit(Event.DONE) }
|
|
|
|
viewModelScope.launch { _events.emit(Event.DONE) }
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,18 +84,18 @@ internal class PickDisplayNameViewModel(
|
|
|
|
|
|
|
|
|
|
|
|
@dagger.assisted.AssistedFactory
|
|
|
|
@dagger.assisted.AssistedFactory
|
|
|
|
interface AssistedFactory {
|
|
|
|
interface AssistedFactory {
|
|
|
|
fun create(pickNewName: Boolean): Factory
|
|
|
|
fun create(loadFailed: Boolean): Factory
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
|
|
@Suppress("UNCHECKED_CAST")
|
|
|
|
class Factory @AssistedInject constructor(
|
|
|
|
class Factory @AssistedInject constructor(
|
|
|
|
@Assisted private val pickNewName: Boolean,
|
|
|
|
@Assisted private val loadFailed: Boolean,
|
|
|
|
private val prefs: TextSecurePreferences,
|
|
|
|
private val prefs: TextSecurePreferences,
|
|
|
|
private val configFactory: ConfigFactory
|
|
|
|
private val configFactory: ConfigFactory
|
|
|
|
) : ViewModelProvider.Factory {
|
|
|
|
) : ViewModelProvider.Factory {
|
|
|
|
|
|
|
|
|
|
|
|
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
|
|
|
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
|
|
|
return PickDisplayNameViewModel(pickNewName, prefs, configFactory) as T
|
|
|
|
return PickDisplayNameViewModel(loadFailed, prefs, configFactory) as T
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|