From e245b2fbdefdceb0009917557e0282b25d338ef6 Mon Sep 17 00:00:00 2001 From: Barry Deen Date: Wed, 22 Apr 2026 21:54:40 -0400 Subject: [PATCH] fix: preserve local relay and emoji frequency across account switches Two repos called clear() during resetForAccountSwitch() were doing `prefs.edit().clear().apply()` on their SharedPreferences files while those files were still pointing at the outgoing account: - CustomEmojiRepository wipes its own per-pubkey file, erasing the "most used" emoji frequency map. No relay mirror, so the data was lost for good. - BlossomRepository shares `wisp_prefs_{pubkey}` with KeyRepository, so its full-file wipe also took out local_relay, relays, dm_relays, etc. Most of those keys came back via replaceable-event refetches, but local_relay has no network source and stayed null. Drop the disk wipe from both clear() methods. The subsequent reload(newPubkey) already repoints prefs to the incoming account's file. --- app/src/main/kotlin/com/wisp/app/repo/BlossomRepository.kt | 5 ++++- .../main/kotlin/com/wisp/app/repo/CustomEmojiRepository.kt | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/com/wisp/app/repo/BlossomRepository.kt b/app/src/main/kotlin/com/wisp/app/repo/BlossomRepository.kt index 0be4e58a..8bff2fac 100644 --- a/app/src/main/kotlin/com/wisp/app/repo/BlossomRepository.kt +++ b/app/src/main/kotlin/com/wisp/app/repo/BlossomRepository.kt @@ -53,9 +53,12 @@ class BlossomRepository(private val context: Context, pubkeyHex: String? = null) _servers.value = list } + // In-memory reset only. `prefs` is shared with KeyRepository + // (`wisp_prefs_{pubkey}`), so `prefs.edit().clear()` would also wipe + // `local_relay`, `relays`, `dm_relays`, etc. `reload(newPubkey)` below + // repoints to the new account's file. fun clear() { _servers.value = listOf(Blossom.DEFAULT_SERVER) - prefs.edit().clear().apply() } fun reload(pubkeyHex: String?) { diff --git a/app/src/main/kotlin/com/wisp/app/repo/CustomEmojiRepository.kt b/app/src/main/kotlin/com/wisp/app/repo/CustomEmojiRepository.kt index 2b8c0b8e..4e51fa97 100644 --- a/app/src/main/kotlin/com/wisp/app/repo/CustomEmojiRepository.kt +++ b/app/src/main/kotlin/com/wisp/app/repo/CustomEmojiRepository.kt @@ -153,6 +153,9 @@ class CustomEmojiRepository(private val context: Context, pubkeyHex: String? = n _sortedUnicodeEmojis.value = all.sortedByDescending { freq[it] ?: 0 } } + // Resets in-memory state only; does NOT touch disk. On account switch the + // repo is called before the pubkey swap, so wiping `prefs` here would + // destroy the outgoing account's per-pubkey file. fun clear() { _userEmojiList.value = null _ownSets.value = emptyList() @@ -162,7 +165,6 @@ class CustomEmojiRepository(private val context: Context, pubkeyHex: String? = n _unicodeEmojis.value = emptyList() _emojiFrequency.value = emptyMap() _sortedUnicodeEmojis.value = emptyList() - prefs.edit().clear().apply() } fun reload(pubkeyHex: String?) {