fix(#193): clear stale slot history on channel reassignment

Channel message history is keyed by the reusable slot index, not by the
channel's PSK. Adding a channel to a slot that previously held a different
channel surfaced the prior occupant's messages (e.g. #echo history appearing
in a newly QR-added channel).

setChannel now clears the slot's stored history unless the slot already holds
the same channel (same PSK, e.g. a rename). Only deleteChannel cleared before.

Build-B (bleed-stop) of epic #190. Build-A (PSK-keyed history + migration) to
follow. Accepted edge: re-adding the exact same channel that was orphaned
device-side loses its old history (messages carry no PSK to match on).
pull/202/head
Strycher 2 weeks ago
parent ed4dce94f3
commit 98841f1c2b

@ -3826,7 +3826,22 @@ class MeshCoreConnector extends ChangeNotifier {
Future<void> setChannel(int index, String name, Uint8List psk) async {
if (!isConnected) return;
// Channel history is stored keyed by the reusable slot [index], not by the
// channel's PSK. If this slot is being (re)assigned to a different channel
// than the one whose history is stored here, clear the stale history so a
// previous occupant's messages (e.g. #echo) don't surface under the newly
// added channel. Preserve only when the slot already holds the SAME channel
// (same PSK) e.g. a rename. (#193)
final existing = _findChannelByIndex(index);
final sameChannel = existing != null && listEquals(existing.psk, psk);
await sendFrame(buildSetChannelFrame(index, name, psk));
if (!sameChannel) {
await _channelMessageStore.clearChannelMessages(index);
_channelMessages.remove(index);
}
// Refresh channels after setting
await getChannels(force: true);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.