diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModel.kt b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModel.kt index 9fca5b0351..86c1a808a3 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModel.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModel.kt @@ -21,19 +21,19 @@ import org.signal.appsettings.totpsetup.TotpSetupState import org.signal.appsettings.totpsetup.TotpSetupState.Dialog import org.signal.core.ui.compose.EventDrivenViewModel import org.signal.core.util.logging.Log -import org.thoughtcrime.securesms.keyvalue.SignalStore -import java.util.UUID +import java.time.LocalDateTime +import java.time.format.DateTimeFormatter class TotpSetupViewModel( private val repository: TotpRepository = TotpRepository(), - private val accountName: String = accountNameFor(SignalStore.account.aci?.rawUuid) + private val accountName: String = accountNameFor(LocalDateTime.now()) ) : EventDrivenViewModel(TAG) { companion object { private val TAG = Log.tag(TotpSetupViewModel::class) @VisibleForTesting - fun accountNameFor(aci: UUID?): String = aci?.toString()?.substringBefore('-')?.uppercase().orEmpty() + fun accountNameFor(time: LocalDateTime): String = time.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) } private val _state = MutableStateFlow(TotpSetupState()) diff --git a/app/src/test/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModelTest.kt b/app/src/test/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModelTest.kt index 16363cacb6..b41fdb9fd5 100644 --- a/app/src/test/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModelTest.kt +++ b/app/src/test/java/org/thoughtcrime/securesms/components/settings/app/account/authenticator/TotpSetupViewModelTest.kt @@ -30,13 +30,13 @@ import org.signal.appsettings.totpsetup.TotpSetupAction import org.signal.appsettings.totpsetup.TotpSetupEvent import org.signal.appsettings.totpsetup.TotpSetupState.Dialog import org.thoughtcrime.securesms.testing.CoroutineDispatcherRule -import java.util.UUID +import java.time.LocalDateTime @OptIn(ExperimentalCoroutinesApi::class) class TotpSetupViewModelTest { companion object { - private const val ACCOUNT_NAME = "8B4A1F0C" + private const val ACCOUNT_NAME = "2026-09-15" private const val SETUP_URI = "otpauth://totp/Signal:%2B15551234567?secret=MZXW6YTBOI" private const val DISPLAY_KEY = "MZXW 6YTB OI" private const val CLIPBOARD_KEY = "MZXW6YTBOI" @@ -161,15 +161,17 @@ class TotpSetupViewModelTest { } @Test - fun `accountNameFor - takes the first hunk of the ACI, uppercased`() { - val aci = UUID.fromString("8b4a1f0c-2d3e-4a5b-9c7d-1e2f3a4b5c6d") + fun `accountNameFor - names the app after the day it was set up, without the time of day`() { + val time = LocalDateTime.of(2026, 9, 15, 13, 45, 30) - assertThat(TotpSetupViewModel.accountNameFor(aci)).isEqualTo("8B4A1F0C") + assertThat(TotpSetupViewModel.accountNameFor(time)).isEqualTo("2026-09-15") } @Test - fun `accountNameFor - has nothing to say without an ACI, which leaves the issuer as the whole label`() { - assertThat(TotpSetupViewModel.accountNameFor(null)).isEqualTo("") + fun `accountNameFor - pads single-digit months and days so the names sort`() { + val time = LocalDateTime.of(2026, 1, 2, 0, 0) + + assertThat(TotpSetupViewModel.accountNameFor(time)).isEqualTo("2026-01-02") } private fun createViewModel() = TotpSetupViewModel(repository = repository, accountName = ACCOUNT_NAME)