Always clear a deleted channel's storage when no other slot holds it
Keep refreshing channels before clearing so in-flight queue messages can't write the history back, but decide whether the channel is still held while ignoring the deleted slot, and clear even if the refresh fails or is incomplete.
This commit is contained in:
1 parent
3ed88a0fc0
commit
0620e8f27a
2 files changed
+48
-7
No files matched your search
@@ -5902,13 +5902,20 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
await sendFrame(buildSetChannelFrame(index, '', Uint8List(16)));
|
||||
_channelMessages.remove(index);
|
||||
_processedChannelReactions.remove(index);
|
||||
// Refresh before clearing history so messages from an in-flight queue sync
|
||||
// cannot recreate the channel's stored history after it has been deleted.
|
||||
await getChannels(force: true);
|
||||
// Another slot holding the same PSK keeps the shared history.
|
||||
final stillHeld = _slotChannelIds.containsValue(channelId);
|
||||
if (channelId != null && !stillHeld) {
|
||||
await _clearChannelStorage(channelId);
|
||||
try {
|
||||
// Refresh before clearing history so messages from an in-flight queue
|
||||
// sync cannot recreate the channel's stored history after it is deleted.
|
||||
await getChannels(force: true);
|
||||
} finally {
|
||||
// Another slot holding the same PSK keeps the shared history. The
|
||||
// deleted slot is skipped: a failed or partial refresh can leave it in
|
||||
// the map.
|
||||
final stillHeld = _slotChannelIds.entries.any(
|
||||
(entry) => entry.key != index && entry.value == channelId,
|
||||
);
|
||||
if (channelId != null && !stillHeld) {
|
||||
await _clearChannelStorage(channelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user