damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

commit f9982e992acbe40238b2c664db95133bccec9957
parent 0eaebb80f164c1a4b29ad3d69a716a516ff29a35
Author: Terry Yiu <963907+tyiu@users.noreply.github.com>
Date:   Thu, 11 May 2023 23:25:27 -0400

Migrate away from sticky deprecated non-pubkey-scoped settings

Changelog-Fixed: Migrate away from sticky deprecated non-pubkey-scoped settings
Closes: #1124

Diffstat:
Mdamus/Models/UserSettingsStore.swift | 10++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/damus/Models/UserSettingsStore.swift b/damus/Models/UserSettingsStore.swift @@ -19,8 +19,11 @@ let fallback_zap_amount = 1000 if let loaded = UserDefaults.standard.object(forKey: self.key) as? T { self.value = loaded } else if let loaded = UserDefaults.standard.object(forKey: key) as? T { - // try to load from deprecated non-pubkey-keyed setting + // If pubkey-scoped setting does not exist but the deprecated non-pubkey-scoped setting does, + // migrate the deprecated setting into the pubkey-scoped one and delete the deprecated one. self.value = loaded + UserDefaults.standard.set(loaded, forKey: self.key) + UserDefaults.standard.removeObject(forKey: key) } else { self.value = default_value } @@ -48,8 +51,11 @@ let fallback_zap_amount = 1000 if let loaded = UserDefaults.standard.string(forKey: self.key), let val = T.init(from: loaded) { self.value = val } else if let loaded = UserDefaults.standard.string(forKey: key), let val = T.init(from: loaded) { - // try to load from deprecated non-pubkey-keyed setting + // If pubkey-scoped setting does not exist but the deprecated non-pubkey-scoped setting does, + // migrate the deprecated setting into the pubkey-scoped one and delete the deprecated one. self.value = val + UserDefaults.standard.set(val.to_string(), forKey: self.key) + UserDefaults.standard.removeObject(forKey: key) } else { self.value = default_value }