Don't re-create a removed contact when syncing its path or flags

The firmware's CMD_ADD_UPDATE_CONTACT adds the key when it isn't in the
contact table. Screens that stay open after a contact is removed (e.g. a
repeater admin screen after the repeater's keys were changed and the old
contact deleted) sync the path before every send, so the next command,
status or telemetry request silently added the old contact back. Skip
path and flag writes for contacts no longer in the contact list.
This commit is contained in:
zjs81 committed 2026-10-24 21:11:04 -07:00
1 parent f2a27f0f71
commit 21e727cf21
2 files changed
+36 -4

No files matched your search

+9 -2
View File
@@ -4366,7 +4366,7 @@ class MeshCoreConnector extends ChangeNotifier {
_pathOpLock = completer.future;
await prev;
try {
if (!isConnected) return;
if (!isConnected || !_isKnownContact(contact)) return;
final width =
pathHashWidth ??
@@ -4409,6 +4409,13 @@ class MeshCoreConnector extends ChangeNotifier {
}
}
/// Whether [contact] is still in the radio's contact list. The firmware's
/// CMD_ADD_UPDATE_CONTACT adds unknown keys, so path/flag writes for a
/// removed contact (e.g. a repeater screen still open after its old key was
/// deleted) would re-create it on the radio.
bool _isKnownContact(Contact contact) =>
_contacts.any((c) => c.publicKeyHex == contact.publicKeyHex);
/// The advert timestamp the firmware holds for [contact] (Contact.lastSeen
/// is parsed from that field); the stored copy is freshest.
DateTime _deviceLastAdvert(Contact contact) {
@@ -4425,7 +4432,7 @@ class MeshCoreConnector extends ChangeNotifier {
bool? teleLoc,
bool? teleEnv,
}) async {
if (!isConnected) return;
if (!isConnected || !_isKnownContact(contact)) return;
final latestContact =
await _fetchContactSnapshotFromDevice(contact.publicKey) ?? contact;
int updatedFlags = isFavorite != null
+27 -2
View File
@@ -1,3 +1,5 @@
import 'dart:typed_data';
import 'package:flutter_test/flutter_test.dart';
import 'package:meshcore_open/connector/meshcore_connector.dart';
import 'package:meshcore_open/connector/meshcore_protocol.dart';
@@ -17,6 +19,20 @@ Future<void> _waitFor(bool Function() condition, {int seconds = 8}) async {
}
}
/// Review radio that records every frame the app sends.
class _RecordingReviewRadio extends ReviewRadio {
final List<Uint8List> sent = [];
_RecordingReviewRadio()
: super(scheduledMessageInterval: const Duration(hours: 1));
@override
void handle(Uint8List frame) {
sent.add(frame);
super.handle(frame);
}
}
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
@@ -35,8 +51,8 @@ void main() {
retryService: retryService,
pathHistoryService: PathHistoryService(StorageService()),
);
connector.reviewRadioFactoryForTest = () =>
ReviewRadio(scheduledMessageInterval: const Duration(hours: 1));
final radio = _RecordingReviewRadio();
connector.reviewRadioFactoryForTest = () => radio;
await connector.connectReview();
await _waitFor(
@@ -66,6 +82,15 @@ void main() {
final saved = await store.loadContacts();
expect(saved.any((c) => c.publicKeyHex == contact.publicKeyHex), isFalse);
// An open chat/repeater screen still syncs the path before each send, and
// the favourite toggle writes flags. On firmware CMD_ADD_UPDATE_CONTACT
// adds unknown keys, so neither may be sent for the removed contact.
radio.sent.clear();
await connector.setContactPath(contact, Uint8List.fromList([0x42]), 1);
await connector.preparePathForContactSend(contact);
await connector.setContactFlags(contact, isFavorite: true);
expect(radio.sent.where((f) => f.first == cmdAddUpdateContact), isEmpty);
await connector.disconnect(manual: true);
});