Add dedicated Add Contact page with manual public key entry
Replace the Contacts add-contact modal sheet and separate menu shortcuts with a unified Add Contact screen supporting manual type/name/public-key entry, clipboard import (meshcore:// URIs, share tokens, and bare 64-hex keys), discovered contacts, and QR scanning.
This commit is contained in:
1 parent
3a93481bdf
commit
f45b511bcb
35 files changed
+2315
-188
No files matched your search
@@ -84,6 +84,7 @@ class ReviewFrames {
|
||||
required Uint8List publicKey,
|
||||
required int type,
|
||||
required Uint8List path,
|
||||
int? pathLen,
|
||||
required String name,
|
||||
required int lastAdvertSecs,
|
||||
required int latitudeE6,
|
||||
@@ -96,7 +97,9 @@ class ReviewFrames {
|
||||
writer.writeBytes(publicKey);
|
||||
writer.writeByte(type);
|
||||
writer.writeByte(flags);
|
||||
writer.writeByte(path.length); // one-byte hashes: hop count == byte count
|
||||
writer.writeByte(
|
||||
pathLen ?? path.length,
|
||||
); // one-byte hashes: hop count == byte count
|
||||
writer.writeBytesPadded(path, maxPathSize);
|
||||
writer.writeCString(name, maxNameSize);
|
||||
writer.writeUInt32LE(lastAdvertSecs);
|
||||
|
||||
@@ -318,6 +318,9 @@ class ReviewRadio {
|
||||
}
|
||||
_emit([ReviewFrames.ok()]);
|
||||
break;
|
||||
case cmdAddUpdateContact:
|
||||
_handleAddUpdateContact(frame);
|
||||
break;
|
||||
case cmdSendLogin:
|
||||
_handleLogin(frame);
|
||||
break;
|
||||
@@ -365,13 +368,68 @@ class ReviewRadio {
|
||||
publicKey: c.publicKey,
|
||||
type: c.type,
|
||||
path: c.path,
|
||||
pathLen: c.pathLen,
|
||||
name: c.name,
|
||||
lastAdvertSecs: c.lastAdvertSecs,
|
||||
latitudeE6: c.latitudeE6,
|
||||
longitudeE6: c.longitudeE6,
|
||||
lastModSecs: c.lastModSecs,
|
||||
flags: c.flags,
|
||||
);
|
||||
|
||||
void _handleAddUpdateContact(Uint8List frame) {
|
||||
// [cmd][pub_key x32][type][flags][path_len][path x64][name x32][last_advert? x4][lat? x4][lon? x4]
|
||||
const minLen = 1 + pubKeySize + 3 + maxPathSize + maxNameSize;
|
||||
if (frame.length < minLen) {
|
||||
_emit([ReviewFrames.err()]);
|
||||
return;
|
||||
}
|
||||
final publicKey = Uint8List.fromList(frame.sublist(1, 1 + pubKeySize));
|
||||
final type = frame[33];
|
||||
final flags = frame[34];
|
||||
final pathLen = frame[35];
|
||||
final Uint8List path;
|
||||
if (pathLen == 0xFF) {
|
||||
path = Uint8List(0);
|
||||
} else {
|
||||
final width = ((pathLen & 0xC0) >> 6) + 1;
|
||||
final hops = pathLen & 0x3F;
|
||||
final byteLen = (hops * width).clamp(0, maxPathSize);
|
||||
path = Uint8List.fromList(frame.sublist(36, 36 + byteLen));
|
||||
}
|
||||
final name = _readCString(frame, 36 + maxPathSize, maxNameSize);
|
||||
final lastAdvertSecs = frame.length >= minLen + 4
|
||||
? readUint32LE(frame, minLen)
|
||||
: 0;
|
||||
final latE6 = frame.length >= minLen + 12
|
||||
? readInt32LE(frame, minLen + 4)
|
||||
: 0;
|
||||
final lonE6 = frame.length >= minLen + 12
|
||||
? readInt32LE(frame, minLen + 8)
|
||||
: 0;
|
||||
final contact = _Contact(
|
||||
publicKey: publicKey,
|
||||
type: type,
|
||||
flags: flags,
|
||||
path: path,
|
||||
pathLen: pathLen,
|
||||
name: name,
|
||||
lastAdvertSecs: lastAdvertSecs,
|
||||
latitudeE6: latE6,
|
||||
longitudeE6: lonE6,
|
||||
lastModSecs: _nowSecs,
|
||||
);
|
||||
final index = _contacts.indexWhere(
|
||||
(c) => listEquals(c.publicKey, publicKey),
|
||||
);
|
||||
if (index >= 0) {
|
||||
_contacts[index] = contact;
|
||||
} else {
|
||||
_contacts.add(contact);
|
||||
}
|
||||
_emit([ReviewFrames.ok()]);
|
||||
}
|
||||
|
||||
void _handleGetContacts(Uint8List frame) {
|
||||
final since = frame.length >= 5 ? readUint32LE(frame, 1) : 0;
|
||||
final matching = _contacts.where((c) => c.lastModSecs > since).toList();
|
||||
@@ -659,7 +717,9 @@ class ReviewRadio {
|
||||
class _Contact {
|
||||
final Uint8List publicKey;
|
||||
final int type;
|
||||
final int flags;
|
||||
final Uint8List path;
|
||||
final int? pathLen;
|
||||
final String name;
|
||||
final int lastAdvertSecs;
|
||||
final int latitudeE6;
|
||||
@@ -669,7 +729,9 @@ class _Contact {
|
||||
_Contact({
|
||||
required this.publicKey,
|
||||
required this.type,
|
||||
this.flags = 0,
|
||||
required this.path,
|
||||
this.pathLen,
|
||||
required this.name,
|
||||
required this.lastAdvertSecs,
|
||||
required this.latitudeE6,
|
||||
|
||||
Reference in new issue
Block a user