Skip to content

Commit b1ef4dd

Browse files
committed
defaulting the display name to the username segment of the account the user has created
1 parent ee5cc19 commit b1ef4dd

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

vector/src/main/java/im/vector/app/features/onboarding/OnboardingViewModel.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ class OnboardingViewModel @AssistedInject constructor(
645645
val homeServerCapabilities = session.homeServerCapabilitiesService().getHomeServerCapabilities()
646646
val capabilityOverrides = vectorOverrides.forceHomeserverCapabilities?.firstOrNull()
647647
state.personalizationState.copy(
648+
displayName = state.registrationState.selectedMatrixId?.let { MatrixPatterns.extractUserNameFromId(it) },
648649
supportsChangingDisplayName = capabilityOverrides?.canChangeDisplayName ?: homeServerCapabilities.canChangeDisplayName,
649650
supportsChangingProfilePicture = capabilityOverrides?.canChangeAvatar ?: homeServerCapabilities.canChangeAvatar
650651
)

vector/src/test/java/im/vector/app/features/onboarding/OnboardingViewModelTest.kt

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ private val SELECTED_HOMESERVER_STATE = SelectedHomeserverState(preferredLoginMo
7272
private val SELECTED_HOMESERVER_STATE_SUPPORTED_LOGOUT_DEVICES = SelectedHomeserverState(isLogoutDevicesSupported = true)
7373
private const val AN_EMAIL = "[email protected]"
7474
private const val A_PASSWORD = "a-password"
75+
private const val A_USERNAME = "hello-world"
76+
private const val A_MATRIX_ID = "@$A_USERNAME:matrix.org"
7577

7678
class OnboardingViewModelTest {
7779

@@ -405,15 +407,6 @@ class OnboardingViewModelTest {
405407
.finish()
406408
}
407409

408-
private fun availableRegistrationState(userName: String, homeServerUrl: String) = RegistrationState(
409-
isUserNameAvailable = true,
410-
selectedMatrixId = "@$userName:${homeServerUrl.removePrefix("https://")}"
411-
)
412-
413-
private fun initialRegistrationState(homeServerUrl: String) = initialState.copy(
414-
onboardingFlow = OnboardingFlow.SignUp, selectedHomeserver = SelectedHomeserverState(userFacingUrl = homeServerUrl)
415-
)
416-
417410
@Test
418411
fun `given in the sign up flow, when editing homeserver errors, then does not update the selected homeserver state and emits error`() = runTest {
419412
viewModelWith(initialState.copy(onboardingFlow = OnboardingFlow.SignUp))
@@ -433,7 +426,8 @@ class OnboardingViewModelTest {
433426
}
434427

435428
@Test
436-
fun `given personalisation enabled, when registering account, then updates state and emits account created event`() = runTest {
429+
fun `given matrix id and personalisation enabled, when registering account, then updates state and emits account created event`() = runTest {
430+
viewModelWith(initialState.copy(registrationState = RegistrationState(selectedMatrixId = A_MATRIX_ID)))
437431
fakeVectorFeatures.givenPersonalisationEnabled()
438432
givenSuccessfullyCreatesAccount(A_HOMESERVER_CAPABILITIES)
439433
givenRegistrationResultFor(RegisterAction.StartRegistration, RegistrationActionHandler.Result.RegistrationComplete(fakeSession))
@@ -445,7 +439,7 @@ class OnboardingViewModelTest {
445439
.assertStatesChanges(
446440
initialState,
447441
{ copy(isLoading = true) },
448-
{ copy(isLoading = false, personalizationState = A_HOMESERVER_CAPABILITIES.toPersonalisationState()) }
442+
{ copy(isLoading = false, personalizationState = A_HOMESERVER_CAPABILITIES.toPersonalisationState(A_USERNAME)) }
449443
)
450444
.assertEvents(OnboardingViewEvents.OnAccountCreated)
451445
.finish()
@@ -738,9 +732,20 @@ class OnboardingViewModelTest {
738732
private fun givenUserNameIsUnavailable(userName: String, failure: Failure.ServerError) {
739733
fakeAuthenticationService.givenRegistrationWizard(FakeRegistrationWizard().also { it.givenUserNameIsUnavailable(userName, failure) })
740734
}
735+
736+
private fun availableRegistrationState(userName: String, homeServerUrl: String) = RegistrationState(
737+
isUserNameAvailable = true,
738+
selectedMatrixId = "@$userName:${homeServerUrl.removePrefix("https://")}"
739+
)
740+
741+
private fun initialRegistrationState(homeServerUrl: String) = initialState.copy(
742+
onboardingFlow = OnboardingFlow.SignUp, selectedHomeserver = SelectedHomeserverState(userFacingUrl = homeServerUrl)
743+
)
744+
741745
}
742746

743-
private fun HomeServerCapabilities.toPersonalisationState() = PersonalizationState(
747+
private fun HomeServerCapabilities.toPersonalisationState(displayName: String? = null) = PersonalizationState(
744748
supportsChangingDisplayName = canChangeDisplayName,
745-
supportsChangingProfilePicture = canChangeAvatar
749+
supportsChangingProfilePicture = canChangeAvatar,
750+
displayName = displayName,
746751
)

0 commit comments

Comments
 (0)