Fix QR contact import replay guard, type fallback and rescan loops
- Pass the existing contact's advert timestamp (0 for new contacts) so the firmware replay guard does not drop the node's real adverts. - Leave a missing/invalid QR type unset and fall back to the existing contact's type instead of rewriting repeaters/rooms as Companion. - Show a failed state with Retry instead of reopening the camera, which rescanned the same QR and resent the frame in a loop. - Keep the processing flag set after a successful import so the closing route cannot restart the camera, import again and pop twice.
This commit is contained in:
1 parent
fba97b9628
commit
3c971705bd
5 files changed
+111
-19
No files matched your search
@@ -56,6 +56,61 @@ void main() {
|
||||
expect(name, 'Alice');
|
||||
});
|
||||
|
||||
test('defaults a new contact without a type to Companion', () {
|
||||
final frame = buildContactQrFrame(ScannedContact(publicKey: publicKey));
|
||||
|
||||
expect(frame[33], advTypeChat);
|
||||
});
|
||||
|
||||
test('keeps the type of an existing contact when the card has none', () {
|
||||
final existing = Contact(
|
||||
publicKey: publicKey,
|
||||
name: 'Hilltop',
|
||||
type: advTypeRepeater,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(0),
|
||||
);
|
||||
final frame = buildContactQrFrame(
|
||||
ScannedContact(publicKey: publicKey),
|
||||
existing: existing,
|
||||
);
|
||||
|
||||
expect(frame[33], advTypeRepeater);
|
||||
});
|
||||
|
||||
test('writes a zero advert timestamp for a new contact', () {
|
||||
final frame = buildContactQrFrame(
|
||||
ScannedContact(publicKey: publicKey, name: 'Alice'),
|
||||
);
|
||||
|
||||
final tsStart = 36 + maxPathSize + maxNameSize;
|
||||
expect(frame.sublist(tsStart, tsStart + 4), [0, 0, 0, 0]);
|
||||
});
|
||||
|
||||
test('keeps the advert timestamp of an existing contact', () {
|
||||
final existing = Contact(
|
||||
publicKey: publicKey,
|
||||
name: 'Alice',
|
||||
type: advTypeChat,
|
||||
pathLength: -1,
|
||||
path: Uint8List(0),
|
||||
lastSeen: DateTime.fromMillisecondsSinceEpoch(1700000000 * 1000),
|
||||
);
|
||||
final frame = buildContactQrFrame(
|
||||
ScannedContact(publicKey: publicKey, name: 'Alice'),
|
||||
existing: existing,
|
||||
);
|
||||
|
||||
final tsStart = 36 + maxPathSize + maxNameSize;
|
||||
final ts = ByteData.sublistView(
|
||||
frame,
|
||||
tsStart,
|
||||
tsStart + 4,
|
||||
).getUint32(0, Endian.little);
|
||||
expect(ts, 1700000000);
|
||||
});
|
||||
|
||||
test('preserves the flags of an existing contact', () {
|
||||
final frame = buildContactQrFrame(
|
||||
ScannedContact(publicKey: publicKey, name: 'Alice'),
|
||||
|
||||
@@ -21,24 +21,24 @@ void main() {
|
||||
expect(result.type, 2);
|
||||
});
|
||||
|
||||
test('missing type defaults to 1', () {
|
||||
test('missing type is left unset', () {
|
||||
final key = 'ab' * 32;
|
||||
final result = parseContactQr(
|
||||
'meshcore://contact/add?name=Bob&public_key=$key',
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.type, 1);
|
||||
expect(result!.type, isNull);
|
||||
});
|
||||
|
||||
test('garbage type falls back to 1', () {
|
||||
test('garbage type is left unset', () {
|
||||
final key = 'ab' * 32;
|
||||
final result = parseContactQr(
|
||||
'meshcore://contact/add?name=Bob&public_key=$key&type=nope',
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.type, 1);
|
||||
expect(result!.type, isNull);
|
||||
});
|
||||
|
||||
test('uppercase hex public key is accepted', () {
|
||||
|
||||
Reference in new issue
Block a user