diff --git a/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt b/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt index 43b5ca2..620f1a1 100644 --- a/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt +++ b/app/src/main/kotlin/io/flamenet/messenger/app/MessengerViewModel.kt @@ -506,10 +506,26 @@ class MessengerViewModel(app: Application) : AndroidViewModel(app) { } val vault = vault ?: error("the vault is not open") - val device = identity ?: DeviceIdentity.create().also { - vault.saveIdentity(it) - identity = it - } + // 🔴 **The stored identity FIRST, and this line is why signing out and + // back in used to cost every contact a prompt.** Sign-in only ever + // consulted the in-memory field, and sign-out clears it — so it minted + // a fresh identity and overwrote the vault's, making this phone a brand + // new device on every sign-in. Contacts saw a safety-number change, + // sends were refused until they accepted it, and the relay's public key + // log had not yet caught up with the key being offered, so even after + // accepting, the next send failed on "the keys offered by this contact + // are not in the public log". + // + // ⚠️ It was harmless right up until it wasn't: sign-out used to destroy + // the vault, so there was never a stored identity to find and minting + // one was correct. Keeping the device across a plain sign-out is what + // turned this into the bug it always looked like. + val device = identity + ?: vault.loadIdentity()?.also { identity = it } + ?: DeviceIdentity.create().also { + vault.saveIdentity(it) + identity = it + } val relay = RelayClient(config.baseUrl, username = account.username, appPassword = credential) relay.useRelayAuth(device)