mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-07-24 01:29:03 +10:00
feat: Refactor repeater resolution logic across multiple screens
This commit is contained in:
@@ -44,6 +44,24 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
|||||||
PathSelection? _pendingStatusSelection;
|
PathSelection? _pendingStatusSelection;
|
||||||
List<Map<String, dynamic>>? _parsedNeighbors;
|
List<Map<String, dynamic>>? _parsedNeighbors;
|
||||||
|
|
||||||
|
int _resolveRepeaterIndex = -1;
|
||||||
|
|
||||||
|
Contact _resolveRepeater(MeshCoreConnector connector) {
|
||||||
|
if (_resolveRepeaterIndex >= 0 &&
|
||||||
|
_resolveRepeaterIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveRepeaterIndex].publicKeyHex ==
|
||||||
|
widget.repeater.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
_resolveRepeaterIndex = connector.contacts.indexWhere(
|
||||||
|
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
||||||
|
);
|
||||||
|
if (_resolveRepeaterIndex == -1) {
|
||||||
|
return widget.repeater;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -163,13 +181,6 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Contact _resolveRepeater(MeshCoreConnector connector) {
|
|
||||||
return connector.contacts.firstWhere(
|
|
||||||
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
|
||||||
orElse: () => widget.repeater,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> _loadNeighbors() async {
|
Future<void> _loadNeighbors() async {
|
||||||
if (_commandService == null) return;
|
if (_commandService == null) return;
|
||||||
|
|
||||||
|
|||||||
@@ -77,11 +77,22 @@ class _RepeaterCliScreenState extends State<RepeaterCliScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _resolveRepeaterIndex = -1;
|
||||||
|
|
||||||
Contact _resolveRepeater(MeshCoreConnector connector) {
|
Contact _resolveRepeater(MeshCoreConnector connector) {
|
||||||
return connector.contacts.firstWhere(
|
if (_resolveRepeaterIndex >= 0 &&
|
||||||
|
_resolveRepeaterIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveRepeaterIndex].publicKeyHex ==
|
||||||
|
widget.repeater.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
_resolveRepeaterIndex = connector.contacts.indexWhere(
|
||||||
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
||||||
orElse: () => widget.repeater,
|
|
||||||
);
|
);
|
||||||
|
if (_resolveRepeaterIndex == -1) {
|
||||||
|
return widget.repeater;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTextMessageResponse(Uint8List frame) {
|
void _handleTextMessageResponse(Uint8List frame) {
|
||||||
|
|||||||
@@ -129,11 +129,22 @@ class _RepeaterSettingsScreenState extends State<RepeaterSettingsScreen> {
|
|||||||
_commandService?.handleResponse(widget.repeater, parsed.text);
|
_commandService?.handleResponse(widget.repeater, parsed.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _resolveRepeaterIndex = -1;
|
||||||
|
|
||||||
Contact _resolveRepeater(MeshCoreConnector connector) {
|
Contact _resolveRepeater(MeshCoreConnector connector) {
|
||||||
return connector.contacts.firstWhere(
|
if (_resolveRepeaterIndex >= 0 &&
|
||||||
|
_resolveRepeaterIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveRepeaterIndex].publicKeyHex ==
|
||||||
|
widget.repeater.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
_resolveRepeaterIndex = connector.contacts.indexWhere(
|
||||||
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
||||||
orElse: () => widget.repeater,
|
|
||||||
);
|
);
|
||||||
|
if (_resolveRepeaterIndex == -1) {
|
||||||
|
return widget.repeater;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool _matchesRepeaterPrefix(Uint8List prefix) {
|
bool _matchesRepeaterPrefix(Uint8List prefix) {
|
||||||
|
|||||||
@@ -91,11 +91,22 @@ class _RepeaterStatusScreenState extends State<RepeaterStatusScreen> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _resolveRepeaterIndex = -1;
|
||||||
|
|
||||||
Contact _resolveRepeater(MeshCoreConnector connector) {
|
Contact _resolveRepeater(MeshCoreConnector connector) {
|
||||||
return connector.contacts.firstWhere(
|
if (_resolveRepeaterIndex >= 0 &&
|
||||||
|
_resolveRepeaterIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveRepeaterIndex].publicKeyHex ==
|
||||||
|
widget.repeater.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
_resolveRepeaterIndex = connector.contacts.indexWhere(
|
||||||
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
||||||
orElse: () => widget.repeater,
|
|
||||||
);
|
);
|
||||||
|
if (_resolveRepeaterIndex == -1) {
|
||||||
|
return widget.repeater;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleTextMessageResponse(Uint8List frame) {
|
void _handleTextMessageResponse(Uint8List frame) {
|
||||||
|
|||||||
@@ -38,6 +38,24 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
|||||||
|
|
||||||
int _tripTime = 0;
|
int _tripTime = 0;
|
||||||
|
|
||||||
|
int _resolveContactIndex = -1;
|
||||||
|
|
||||||
|
Contact _resolveContact(MeshCoreConnector connector) {
|
||||||
|
if (_resolveContactIndex >= 0 &&
|
||||||
|
_resolveContactIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveContactIndex].publicKeyHex ==
|
||||||
|
widget.contact.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveContactIndex];
|
||||||
|
}
|
||||||
|
_resolveContactIndex = connector.contacts.indexWhere(
|
||||||
|
(c) => c.publicKeyHex == widget.contact.publicKeyHex,
|
||||||
|
);
|
||||||
|
if (_resolveContactIndex == -1) {
|
||||||
|
return widget.contact;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveContactIndex];
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
@@ -144,7 +162,7 @@ class _TelemetryScreenState extends State<TelemetryScreen> {
|
|||||||
try {
|
try {
|
||||||
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
final connector = Provider.of<MeshCoreConnector>(context, listen: false);
|
||||||
final selection = await connector.preparePathForContactSend(
|
final selection = await connector.preparePathForContactSend(
|
||||||
widget.contact,
|
_resolveContact(connector),
|
||||||
);
|
);
|
||||||
_pendingStatusSelection = selection;
|
_pendingStatusSelection = selection;
|
||||||
Uint8List frame;
|
Uint8List frame;
|
||||||
|
|||||||
@@ -69,11 +69,21 @@ class _RepeaterLoginDialogState extends State<RepeaterLoginDialog> {
|
|||||||
|
|
||||||
bool _isLoggingIn = false;
|
bool _isLoggingIn = false;
|
||||||
|
|
||||||
|
int _resolveRepeaterIndex = -1;
|
||||||
Contact _resolveRepeater(MeshCoreConnector connector) {
|
Contact _resolveRepeater(MeshCoreConnector connector) {
|
||||||
return connector.contacts.firstWhere(
|
if (_resolveRepeaterIndex >= 0 &&
|
||||||
|
_resolveRepeaterIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveRepeaterIndex].publicKeyHex ==
|
||||||
|
widget.repeater.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
_resolveRepeaterIndex = connector.contacts.indexWhere(
|
||||||
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
(c) => c.publicKeyHex == widget.repeater.publicKeyHex,
|
||||||
orElse: () => widget.repeater,
|
|
||||||
);
|
);
|
||||||
|
if (_resolveRepeaterIndex == -1) {
|
||||||
|
return widget.repeater;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleLogin() async {
|
Future<void> _handleLogin() async {
|
||||||
|
|||||||
@@ -64,11 +64,22 @@ class _RoomLoginDialogState extends State<RoomLoginDialog> {
|
|||||||
|
|
||||||
bool _isLoggingIn = false;
|
bool _isLoggingIn = false;
|
||||||
|
|
||||||
|
int _resolveRepeaterIndex = -1;
|
||||||
|
|
||||||
Contact _resolveRepeater(MeshCoreConnector connector) {
|
Contact _resolveRepeater(MeshCoreConnector connector) {
|
||||||
return connector.contacts.firstWhere(
|
if (_resolveRepeaterIndex >= 0 &&
|
||||||
|
_resolveRepeaterIndex < connector.contacts.length &&
|
||||||
|
connector.contacts[_resolveRepeaterIndex].publicKeyHex ==
|
||||||
|
widget.room.publicKeyHex) {
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
|
}
|
||||||
|
_resolveRepeaterIndex = connector.contacts.indexWhere(
|
||||||
(c) => c.publicKeyHex == widget.room.publicKeyHex,
|
(c) => c.publicKeyHex == widget.room.publicKeyHex,
|
||||||
orElse: () => widget.room,
|
|
||||||
);
|
);
|
||||||
|
if (_resolveRepeaterIndex == -1) {
|
||||||
|
return widget.room;
|
||||||
|
}
|
||||||
|
return connector.contacts[_resolveRepeaterIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleLogin() async {
|
Future<void> _handleLogin() async {
|
||||||
|
|||||||
Reference in New Issue
Block a user