mirror of
https://github.com/zjs81/meshcore-open.git
synced 2026-04-20 22:13:48 +00:00
Unify contact retrieval by introducing allContacts getter
This commit is contained in:
parent
8b280b37be
commit
79a45c527b
9 changed files with 25 additions and 29 deletions
|
|
@ -289,6 +289,10 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
);
|
||||
}
|
||||
|
||||
List<Contact> get allContacts => List.unmodifiable([
|
||||
..._contacts,
|
||||
..._discoveredContacts.where((c) => !c.isActive),
|
||||
]);
|
||||
List<Contact> get discoveredContacts {
|
||||
return List.unmodifiable(_discoveredContacts);
|
||||
}
|
||||
|
|
@ -2909,6 +2913,8 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
void _handleContact(Uint8List frame, {bool isContact = true}) {
|
||||
final contact = Contact.fromFrame(frame);
|
||||
if (contact != null) {
|
||||
_handleDiscovery(contact, frame, noNotify: true, addActive: true);
|
||||
|
||||
if (contact.type == advTypeRepeater) {
|
||||
_contactUnreadCount.remove(contact.publicKeyHex);
|
||||
_unreadStore.saveContactUnreadCount(
|
||||
|
|
@ -4717,6 +4723,12 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
(_autoAddRoomServers && type == advTypeRoom) ||
|
||||
(_autoAddSensors && type == advTypeSensor)) {
|
||||
_handleContactAdvert(newContact);
|
||||
_handleDiscovery(
|
||||
newContact,
|
||||
rawPacket,
|
||||
noNotify: true,
|
||||
addActive: true,
|
||||
);
|
||||
} else {
|
||||
_handleDiscovery(newContact, rawPacket);
|
||||
}
|
||||
|
|
@ -4827,6 +4839,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
Contact contact,
|
||||
Uint8List rawPacket, {
|
||||
bool noNotify = false,
|
||||
bool addActive = false,
|
||||
}) {
|
||||
appLogger.info('Discovered new contact: ${contact.name}', tag: 'Connector');
|
||||
|
||||
|
|
@ -4847,7 +4860,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
longitude: contact.longitude,
|
||||
lastSeen: contact.lastSeen,
|
||||
flags: 0,
|
||||
isActive: false,
|
||||
isActive: addActive,
|
||||
);
|
||||
notifyListeners();
|
||||
unawaited(_persistDiscoveredContacts());
|
||||
|
|
@ -4865,7 +4878,7 @@ class MeshCoreConnector extends ChangeNotifier {
|
|||
longitude: contact.longitude,
|
||||
lastSeen: contact.lastSeen,
|
||||
lastMessageAt: contact.lastMessageAt,
|
||||
isActive: false,
|
||||
isActive: addActive,
|
||||
flags: 0,
|
||||
);
|
||||
_discoveredContacts.add(disContact);
|
||||
|
|
|
|||
|
|
@ -40,10 +40,7 @@ class ChannelMessagePathScreen extends StatelessWidget {
|
|||
final primaryPath = !channelMessage && !message.isOutgoing
|
||||
? Uint8List.fromList(primaryPathTmp.reversed.toList())
|
||||
: primaryPathTmp;
|
||||
final contacts = <Contact>[
|
||||
...connector.contacts,
|
||||
...connector.discoveredContacts,
|
||||
];
|
||||
final contacts = connector.allContacts;
|
||||
final hops = _buildPathHops(primaryPath, contacts, l10n);
|
||||
final hasHopDetails = primaryPath.isNotEmpty;
|
||||
final observedLabel = _formatObservedHops(
|
||||
|
|
@ -367,10 +364,7 @@ class _ChannelMessagePathMapScreenState
|
|||
: selectedPathTmp;
|
||||
|
||||
final selectedIndex = _indexForPath(selectedPath, observedPaths);
|
||||
final contacts = <Contact>[
|
||||
...connector.contacts,
|
||||
...connector.discoveredContacts,
|
||||
];
|
||||
final contacts = connector.allContacts;
|
||||
final hops = _buildPathHops(selectedPath, contacts, context.l10n);
|
||||
|
||||
final points = <LatLng>[];
|
||||
|
|
|
|||
|
|
@ -1027,7 +1027,7 @@ class _ChatScreenState extends State<ChatScreen> {
|
|||
final currentPathLabel = _currentPathLabel(currentContact);
|
||||
|
||||
// Filter out the current contact from available contacts
|
||||
final availableContacts = connector.contacts
|
||||
final availableContacts = connector.allContacts
|
||||
.where((c) => c != widget.contact)
|
||||
.toList();
|
||||
|
||||
|
|
|
|||
|
|
@ -137,10 +137,7 @@ class _MapScreenState extends State<MapScreen> {
|
|||
builder: (context, connector, settingsService, pathHistory, child) {
|
||||
final tileCache = context.read<MapTileCacheService>();
|
||||
final settings = settingsService.settings;
|
||||
final allContacts = <Contact>[
|
||||
...connector.contacts,
|
||||
...connector.discoveredContacts.where((c) => !c.isActive),
|
||||
];
|
||||
final allContacts = connector.allContacts;
|
||||
|
||||
final contacts = settings.mapShowDiscoveryContacts
|
||||
? allContacts
|
||||
|
|
|
|||
|
|
@ -124,10 +124,7 @@ class _NeighborsScreenState extends State<NeighborsScreen> {
|
|||
|
||||
void _handleNeighborsResponse(MeshCoreConnector connector, Uint8List frame) {
|
||||
final buffer = BufferReader(frame);
|
||||
final contacts = <Contact>[
|
||||
...connector.contacts,
|
||||
...connector.discoveredContacts,
|
||||
];
|
||||
final contacts = connector.allContacts;
|
||||
try {
|
||||
final neighborCount = buffer.readUInt16LE();
|
||||
final parsedNeighbors = parseNeighborsData(buffer, buffer.readUInt16LE());
|
||||
|
|
|
|||
|
|
@ -263,10 +263,7 @@ class _PathTraceMapScreenState extends State<PathTraceMapScreen> {
|
|||
.toList();
|
||||
|
||||
Map<int, Contact> pathContacts = {};
|
||||
final contacts = <Contact>[
|
||||
...connector.contacts,
|
||||
...connector.discoveredContacts,
|
||||
];
|
||||
final contacts = connector.allContacts;
|
||||
contacts.where((c) => c.type != advTypeChat).forEach((repeater) {
|
||||
for (var repeaterData in pathData) {
|
||||
if (listEquals(
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class _PathManagementDialogState extends State<_PathManagementDialog> {
|
|||
}
|
||||
|
||||
final pathForInput = currentContact.pathIdList;
|
||||
final availableContacts = connector.contacts
|
||||
final availableContacts = connector.allContacts
|
||||
.where((c) => c.publicKeyHex != currentContact.publicKeyHex)
|
||||
.toList();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:meshcore_open/connector/meshcore_protocol.dart';
|
||||
import '../l10n/l10n.dart';
|
||||
import '../models/contact.dart';
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ class _PathSelectionDialogState extends State<PathSelectionDialog> {
|
|||
|
||||
void _filterValidContacts() {
|
||||
_validContacts = widget.availableContacts
|
||||
.where((c) => c.type == 2 || c.type == 3)
|
||||
.where((c) => c.type == advTypeRepeater || c.type == advTypeRoom)
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,10 +157,7 @@ class _SNRIndicatorState extends State<SNRIndicator> {
|
|||
repeater.snr,
|
||||
widget.connector.currentSf,
|
||||
);
|
||||
final allContacts = [
|
||||
...widget.connector.contacts,
|
||||
...widget.connector.discoveredContacts,
|
||||
];
|
||||
final allContacts = widget.connector.allContacts;
|
||||
final name = allContacts
|
||||
.where((c) => c.publicKey.first == repeater.pubkeyFirstByte)
|
||||
.map((c) => c.name)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue