Stamp legacy images inside the migration; hold early channel frames

- Image entries are stamped with their channel ID before the migration is
  marked done, so an interrupted run repeats it instead of leaving them
  unstamped (and invisible) forever.
- Channel message/data frames that arrive before this session's slot map
  is confirmed are held and replayed once it is. Current firmware only
  sends them in reply to SYNC_NEXT_MESSAGE, which already waits; this
  guards against a stale saved map filing them under the wrong channel.
This commit is contained in:
zjs81 committed 2026-10-11 18:04:53 -07:00
1 parent 679116ed03
commit 6a8df764bb
4 files changed
+87 -5

No files matched your search

+9 -1
View File
@@ -25,7 +25,14 @@ class ChannelStorageMigration {
/// Migrates [scope] (first 10 hex chars of the radio's public key) and
/// returns the slot -> channel ID mapping it used. Returns an empty map when
/// the scope was already migrated or must not adopt legacy data.
static Future<Map<int, String>> migrate(String scope) async {
///
/// [beforeDone] runs with that mapping before the migration is marked done,
/// so data kept elsewhere (images) is moved on the same one-shot terms: an
/// interrupted run repeats it on the next launch.
static Future<Map<int, String>> migrate(
String scope, {
Future<void> Function(Map<int, String> slotIds)? beforeDone,
}) async {
if (scope.isEmpty || !canMigrateLegacyKeys(scope)) return {};
final prefs = PrefsManager.instance;
final doneKey = '$_doneKeyPrefix$scope';
@@ -61,6 +68,7 @@ class ChannelStorageMigration {
);
}
await _migrateOrder(scope, slotIds);
if (slotIds.isNotEmpty) await beforeDone?.call(slotIds);
await prefs.setBool(doneKey, true);
await channelStore.saveSlotChannelIds(slotIds);