From c81791cf1eea320af55fc4ffa3e443161b8d542d Mon Sep 17 00:00:00 2001 From: Winston Lowe Date: Thu, 12 Mar 2026 08:39:17 -0700 Subject: [PATCH] Migrate legacy storage keys to scoped keys in various store classes (#289) --- lib/storage/channel_message_store.dart | 13 ++++++++----- lib/storage/channel_settings_store.dart | 2 +- lib/storage/channel_store.dart | 4 ++++ lib/storage/community_store.dart | 3 +++ lib/storage/contact_group_store.dart | 3 +++ lib/storage/contact_store.dart | 3 +++ lib/storage/message_store.dart | 3 +++ lib/storage/unread_store.dart | 3 +++ 8 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/storage/channel_message_store.dart b/lib/storage/channel_message_store.dart index 9c9f7e8..50d13f7 100644 --- a/lib/storage/channel_message_store.dart +++ b/lib/storage/channel_message_store.dart @@ -46,24 +46,27 @@ class ChannelMessageStore { } final prefs = PrefsManager.instance; final key = '$keyFor$channelIndex'; + final oldKey = '$_keyPrefix$channelIndex'; - String? jsonString = prefs.getString(_keyPrefix); + String? jsonString = prefs.getString(oldKey); if (jsonString == null || jsonString.isEmpty) { // Attempt migration from legacy unscoped key on first load - final legacyJsonString = prefs.getString(_keyPrefix); - prefs.remove(_keyPrefix); + final legacyJsonString = prefs.getString(oldKey); + prefs.remove(oldKey); if (legacyJsonString != null && legacyJsonString.isNotEmpty) { appLogger.info( - 'Migrating channel messages from legacy key $_keyPrefix to scoped key $key', + 'Migrating channel messages from legacy key $oldKey to scoped key $key', ); await prefs.setString(key, legacyJsonString); jsonString = legacyJsonString; } } + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return []; } - try { final jsonList = jsonDecode(jsonString) as List; return jsonList.map((json) => _messageFromJson(json)).toList(); diff --git a/lib/storage/channel_settings_store.dart b/lib/storage/channel_settings_store.dart index 3b639cd..3fb00eb 100644 --- a/lib/storage/channel_settings_store.dart +++ b/lib/storage/channel_settings_store.dart @@ -20,7 +20,7 @@ class ChannelSettingsStore { final prefs = PrefsManager.instance; final key = '$keyFor$channelIndex'; final oldKey = '$_keyPrefix$channelIndex'; - bool? enabled = prefs.getBool(key); + bool? enabled = prefs.getBool(oldKey); if (enabled == null) { // Attempt migration from legacy unscoped key on first load enabled = prefs.getBool(oldKey); diff --git a/lib/storage/channel_store.dart b/lib/storage/channel_store.dart index 1bad7e3..775398e 100644 --- a/lib/storage/channel_store.dart +++ b/lib/storage/channel_store.dart @@ -32,6 +32,10 @@ class ChannelStore { jsonString = legacyJsonString; } } + + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return []; } diff --git a/lib/storage/community_store.dart b/lib/storage/community_store.dart index c7198e7..6df859a 100644 --- a/lib/storage/community_store.dart +++ b/lib/storage/community_store.dart @@ -38,6 +38,9 @@ class CommunityStore { jsonString = legacyJsonString; } } + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return []; } diff --git a/lib/storage/contact_group_store.dart b/lib/storage/contact_group_store.dart index c1a7702..986bfdd 100644 --- a/lib/storage/contact_group_store.dart +++ b/lib/storage/contact_group_store.dart @@ -31,6 +31,9 @@ class ContactGroupStore { jsonString = legacyJsonString; } } + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return []; } diff --git a/lib/storage/contact_store.dart b/lib/storage/contact_store.dart index 8f9e84d..a4e2f0d 100644 --- a/lib/storage/contact_store.dart +++ b/lib/storage/contact_store.dart @@ -33,6 +33,9 @@ class ContactStore { jsonString = legacyJsonString; } } + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return []; } diff --git a/lib/storage/message_store.dart b/lib/storage/message_store.dart index 82caa78..9a39e3f 100644 --- a/lib/storage/message_store.dart +++ b/lib/storage/message_store.dart @@ -49,6 +49,9 @@ class MessageStore { jsonString = legacyJsonString; } } + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return []; } diff --git a/lib/storage/unread_store.dart b/lib/storage/unread_store.dart index c0cecee..d46fb41 100644 --- a/lib/storage/unread_store.dart +++ b/lib/storage/unread_store.dart @@ -45,6 +45,9 @@ class UnreadStore { jsonString = legacyJsonString; } } + if (jsonString == null || jsonString.isEmpty) { + jsonString = prefs.getString(keyFor); + } if (jsonString == null || jsonString.isEmpty) { return {}; }