Wait for the radio before removing a contact, and explain re-adds
removeContact now waits for the radio's reply and only drops the contact locally when the radio confirms (or reports it doesn't have it), so a lost command no longer leaves a contact that the next sync restores. Failures are shown to the user. The delete dialog warns when the radio auto-adds that contact type, since the contact returns on its next advert.
This commit is contained in:
1 parent
1e786b24ba
commit
f2a27f0f71
28 files changed
+352
-10
No files matched your search
@@ -667,6 +667,16 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
bool? get autoAddSensors => _autoAddSensors;
|
||||
bool? get autoAddOverwriteOldest => _overwriteOldest;
|
||||
|
||||
/// Whether the radio stores adverts of [type] by itself, so a removed
|
||||
/// contact of that type returns the next time it advertises.
|
||||
bool autoAddsContactType(int type) => switch (type) {
|
||||
advTypeChat => _autoAddUsers,
|
||||
advTypeRepeater => _autoAddRepeaters,
|
||||
advTypeRoom => _autoAddRoomServers,
|
||||
advTypeSensor => _autoAddSensors,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
/// autoadd_max_hops from GET_AUTOADD_CONFIG (0 = no limit), null when the
|
||||
/// firmware did not report it (pre-v1.13).
|
||||
int? get autoAddMaxHops => _autoAddMaxHops;
|
||||
@@ -5034,13 +5044,26 @@ class MeshCoreConnector extends ChangeNotifier {
|
||||
}) async {
|
||||
if (!isConnected) return;
|
||||
|
||||
// Only drop the contact locally once the radio confirms; otherwise the
|
||||
// next contact sync restores it. ERR means the radio does not have it.
|
||||
try {
|
||||
await sendFrame(
|
||||
buildRemoveContactFrame(contact.publicKey),
|
||||
waitForGenericAck: true,
|
||||
);
|
||||
} on FirmwareCommandException catch (e) {
|
||||
_appDebugLogService?.warn(
|
||||
'Radio has no contact ${contact.publicKeyHex.substring(0, 8)} '
|
||||
'(error ${e.errCode}); removing it locally',
|
||||
tag: 'Connector',
|
||||
);
|
||||
}
|
||||
|
||||
_handleDiscovery(
|
||||
contact,
|
||||
contact.rawPacket ?? Uint8List(0),
|
||||
noNotify: true,
|
||||
);
|
||||
|
||||
await sendFrame(buildRemoveContactFrame(contact.publicKey));
|
||||
_contactsStorageFull = false;
|
||||
_contacts.removeWhere((c) => c.publicKeyHex == contact.publicKeyHex);
|
||||
_knownContactKeys.remove(contact.publicKeyHex);
|
||||
|
||||
@@ -5,6 +5,16 @@ import 'package:flutter/foundation.dart';
|
||||
import '../services/image_chunk_transport.dart' show cmdSendChannelData;
|
||||
import 'meshcore_protocol.dart';
|
||||
|
||||
/// RESP_CODE_ERR received for a command that was waiting for its reply.
|
||||
class FirmwareCommandException implements Exception {
|
||||
final int errCode;
|
||||
|
||||
const FirmwareCommandException(this.errCode);
|
||||
|
||||
@override
|
||||
String toString() => 'Exception: Command failed with error code $errCode';
|
||||
}
|
||||
|
||||
/// A command waiting for its reply from the companion firmware.
|
||||
class PendingCommandReply {
|
||||
final int commandCode;
|
||||
@@ -203,9 +213,7 @@ class PendingCommandReplies {
|
||||
if (_queue.isEmpty) return null;
|
||||
final pending = _queue.removeAt(0);
|
||||
if (pending.isTombstone) return null;
|
||||
pending.completer?.completeError(
|
||||
Exception('Command failed with error code $errCode'),
|
||||
);
|
||||
pending.completer?.completeError(FirmwareCommandException(errCode));
|
||||
return pending;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user