Merge remote-tracking branch 'origin/dev' into cursor/routing-send-settings-ef15

# Conflicts:
#	documentation/design.md
#	lib/screens/channels_screen.dart
#	lib/screens/chat_screen.dart
This commit is contained in:
zjs81 committed 2026-11-20 22:53:08 -07:00
commit 84c0b97710
67 files changed
+5449 -880

No files matched your search

+123 -67
View File
@@ -12,6 +12,7 @@ import 'package:flutter_blue_plus_platform_interface/flutter_blue_plus_platform_
import '../utils/advert_signature.dart';
import '../models/channel.dart';
import '../models/channel_message.dart';
import '../models/chat_compression_mode.dart';
import '../models/bookmarked_message.dart';
import '../models/companion_radio_stats.dart';
import '../models/contact.dart';
@@ -62,6 +63,7 @@ import '../storage/channel_settings_store.dart';
import '../storage/channel_region_store.dart';
import '../storage/channel_storage_migration.dart';
import '../storage/channel_store.dart';
import '../storage/contact_added_at_store.dart';
import '../storage/contact_discovery_store.dart';
import '../storage/contact_settings_store.dart';
import '../storage/contact_store.dart';
@@ -526,6 +528,8 @@ class MeshCoreConnector extends ChangeNotifier {
final ChannelRegionStore _channelRegionStore = ChannelRegionStore();
final ContactSettingsStore _contactSettingsStore = ContactSettingsStore();
final ContactStore _contactStore = ContactStore();
final ContactAddedAtStore _contactAddedAtStore = ContactAddedAtStore();
final Map<String, DateTime> _contactAddedAt = {};
final ContactDiscoveryStore _discoveryContactStore = ContactDiscoveryStore();
final ChannelStore _channelStore = ChannelStore();
final UnreadStore _unreadStore = UnreadStore();
@@ -649,6 +653,11 @@ class MeshCoreConnector extends ChangeNotifier {
return radio.bleDisplayName;
}
/// Phone time a contact was first added from a card; the list orders by it
/// while the radio has no advert time for the contact.
DateTime? contactAddedAt(String contactPubKeyHex) =>
_contactAddedAt[contactPubKeyHex];
Contact? getContactByPubKeyHex(String contactPubKeyHex) {
return _contacts.cast<Contact?>().firstWhere(
(c) => c?.publicKeyHex == contactPubKeyHex,
@@ -1817,10 +1826,6 @@ class MeshCoreConnector extends ChangeNotifier {
await _channelRegionStore.saveDefaultRegion(region);
}
void ensureContactSmazSettingLoaded(String contactKeyHex) {
_ensureContactSmazSettingLoaded(contactKeyHex);
}
bool isChannelCyr2LatEnabled(int channelIndex) {
_ensureChannelCyr2LatSettingLoaded(channelIndex);
return _channelCyr2LatEnabled[channelIndex] ?? false;
@@ -1831,10 +1836,6 @@ class MeshCoreConnector extends ChangeNotifier {
return _contactCyr2LatEnabled[contactKeyHex] ?? false;
}
void ensureContactCyr2LatSettingLoaded(String contactKeyHex) {
_ensureContactCyr2LatSettingLoaded(contactKeyHex);
}
Future<void> loadUnreadState() async {
_contactUnreadCount
..clear()
@@ -2103,30 +2104,97 @@ class MeshCoreConnector extends ChangeNotifier {
];
}
Future<void> setChannelSmazEnabled(int channelIndex, bool enabled) async {
final slots = _slotsSharingChannel(channelIndex);
for (final slot in slots) {
_channelSmazEnabled[slot] = enabled;
ChatCompressionMode channelCompressionMode(int channelIndex) {
if (isChannelSmazEnabled(channelIndex)) return ChatCompressionMode.smaz;
if (isChannelCyr2LatEnabled(channelIndex)) {
return ChatCompressionMode.cyr2lat;
}
final channelId = _channelIdForSlot(channelIndex);
if (enabled) {
for (final slot in slots) {
_channelCyr2LatEnabled[slot] = false;
}
if (channelId != null) {
await _channelSettingsStore.saveCyr2LatEnabled(channelId, false);
}
}
if (channelId != null) {
await _channelSettingsStore.saveSmazEnabled(channelId, enabled);
}
notifyListeners();
return ChatCompressionMode.off;
}
Future<void> setContactSmazEnabled(String contactKeyHex, bool enabled) async {
_contactSmazEnabled[contactKeyHex] = enabled;
await _contactSettingsStore.saveSmazEnabled(contactKeyHex, enabled);
notifyListeners();
ChatCompressionMode contactCompressionMode(String contactKeyHex) {
_ensureContactSmazSettingLoaded(contactKeyHex);
if (isContactSmazEnabled(contactKeyHex)) return ChatCompressionMode.smaz;
if (isContactCyr2LatEnabled(contactKeyHex)) {
return ChatCompressionMode.cyr2lat;
}
return ChatCompressionMode.off;
}
/// Serializes compression writes so overlapping choices can't interleave
/// their flag writes and leave SMAZ and Cyr2Lat both on.
Future<void> _compressionWrites = Future<void>.value();
Future<void> _queueCompressionWrite(Future<void> Function() write) {
final next = _compressionWrites.then((_) => write());
_compressionWrites = next.catchError((_) {});
return next;
}
/// Saves [mode] for the channel in [channelIndex] and every slot holding
/// the same channel. Flags are switched off before the new one is switched
/// on, and memory follows each completed write, so a failure never leaves
/// both on. Throws [StateError] when the slot has no storage ID.
Future<void> setChannelCompressionMode(
int channelIndex,
ChatCompressionMode mode,
) {
return _queueCompressionWrite(() async {
final channelId = _channelIdForSlot(channelIndex);
if (channelId == null) {
throw StateError('Channel slot $channelIndex has no storage ID');
}
final slots = _slotsSharingChannel(channelIndex);
Future<void> writeSmaz(bool on) async {
await _channelSettingsStore.saveSmazEnabled(channelId, on);
for (final slot in slots) {
_channelSmazEnabled[slot] = on;
}
}
Future<void> writeCyr2Lat(bool on) async {
await _channelSettingsStore.saveCyr2LatEnabled(channelId, on);
for (final slot in slots) {
_channelCyr2LatEnabled[slot] = on;
}
}
try {
if (mode != ChatCompressionMode.smaz) await writeSmaz(false);
if (mode != ChatCompressionMode.cyr2lat) await writeCyr2Lat(false);
if (mode == ChatCompressionMode.smaz) await writeSmaz(true);
if (mode == ChatCompressionMode.cyr2lat) await writeCyr2Lat(true);
} finally {
notifyListeners();
}
});
}
/// Contact counterpart of [setChannelCompressionMode].
Future<void> setContactCompressionMode(
String contactKeyHex,
ChatCompressionMode mode,
) {
return _queueCompressionWrite(() async {
Future<void> writeSmaz(bool on) async {
await _contactSettingsStore.saveSmazEnabled(contactKeyHex, on);
_contactSmazEnabled[contactKeyHex] = on;
}
Future<void> writeCyr2Lat(bool on) async {
await _contactSettingsStore.saveCyr2LatEnabled(contactKeyHex, on);
_contactCyr2LatEnabled[contactKeyHex] = on;
}
try {
if (mode != ChatCompressionMode.smaz) await writeSmaz(false);
if (mode != ChatCompressionMode.cyr2lat) await writeCyr2Lat(false);
if (mode == ChatCompressionMode.smaz) await writeSmaz(true);
if (mode == ChatCompressionMode.cyr2lat) await writeCyr2Lat(true);
} finally {
notifyListeners();
}
});
}
Future<void> setChannelUrlImagesEnabled(
@@ -2152,35 +2220,6 @@ class MeshCoreConnector extends ChangeNotifier {
notifyListeners();
}
Future<void> setChannelCyr2LatEnabled(int channelIndex, bool enabled) async {
final slots = _slotsSharingChannel(channelIndex);
for (final slot in slots) {
_channelCyr2LatEnabled[slot] = enabled;
}
final channelId = _channelIdForSlot(channelIndex);
if (enabled) {
for (final slot in slots) {
_channelSmazEnabled[slot] = false;
}
if (channelId != null) {
await _channelSettingsStore.saveSmazEnabled(channelId, false);
}
}
if (channelId != null) {
await _channelSettingsStore.saveCyr2LatEnabled(channelId, enabled);
}
notifyListeners();
}
Future<void> setContactCyr2LatEnabled(
String contactKeyHex,
bool enabled,
) async {
_contactCyr2LatEnabled[contactKeyHex] = enabled;
await _contactSettingsStore.saveCyr2LatEnabled(contactKeyHex, enabled);
notifyListeners();
}
Future<void> setChannelRegion(int channelIndex, String region) async {
// Update in-memory state and notify synchronously so the UI reflects the
// change immediately; persistence happens in the background.
@@ -2434,6 +2473,9 @@ class MeshCoreConnector extends ChangeNotifier {
_contacts
..clear()
..addAll(cached);
_contactAddedAt
..clear()
..addAll(_contactAddedAtStore.load());
for (final contact in cached) {
_ensureContactSmazSettingLoaded(contact.publicKeyHex);
_ensureContactCyr2LatSettingLoaded(contact.publicKeyHex);
@@ -5124,6 +5166,13 @@ class MeshCoreConnector extends ChangeNotifier {
pathHashByteWidth: pathHashByteWidth,
);
await sendFrame(frame, waitForGenericAck: true);
if (publicKey != null) {
final keyHex = pubKeyToHex(publicKey);
if (!_contactAddedAt.containsKey(keyHex)) {
_contactAddedAt[keyHex] = DateTime.now();
await _contactAddedAtStore.save(_contactAddedAt);
}
}
await refreshContacts();
}
@@ -6126,6 +6175,9 @@ class MeshCoreConnector extends ChangeNotifier {
_contactsStorageFull = false;
_contacts.removeWhere((c) => c.publicKeyHex == contact.publicKeyHex);
_knownContactKeys.remove(contact.publicKeyHex);
if (_contactAddedAt.remove(contact.publicKeyHex) != null) {
unawaited(_contactAddedAtStore.save(_contactAddedAt));
}
unawaited(updateKnownDiscovered());
unawaited(_persistContacts());
_conversations.remove(contact.publicKeyHex);
@@ -7814,6 +7866,9 @@ class MeshCoreConnector extends ChangeNotifier {
);
_contacts.removeWhere((c) => c.publicKeyHex == keyHex);
_knownContactKeys.remove(keyHex);
if (_contactAddedAt.remove(keyHex) != null) {
unawaited(_contactAddedAtStore.save(_contactAddedAt));
}
_contactsStorageFull = false;
unawaited(updateKnownDiscovered());
unawaited(_persistContacts());
@@ -8371,7 +8426,7 @@ class MeshCoreConnector extends ChangeNotifier {
void _ensureContactSmazSettingLoaded(String contactKeyHex) {
if (_contactSmazEnabled.containsKey(contactKeyHex)) return;
_contactSettingsStore.loadSmazEnabled(contactKeyHex).then((enabled) {
if (_contactSmazEnabled[contactKeyHex] == enabled) return;
if (_contactSmazEnabled.containsKey(contactKeyHex)) return;
_contactSmazEnabled[contactKeyHex] = enabled;
notifyListeners();
});
@@ -8380,7 +8435,7 @@ class MeshCoreConnector extends ChangeNotifier {
void _ensureContactCyr2LatSettingLoaded(String contactKeyHex) {
if (_contactCyr2LatEnabled.containsKey(contactKeyHex)) return;
_contactSettingsStore.loadCyr2LatEnabled(contactKeyHex).then((enabled) {
if (_contactCyr2LatEnabled[contactKeyHex] == enabled) return;
if (_contactCyr2LatEnabled.containsKey(contactKeyHex)) return;
_contactCyr2LatEnabled[contactKeyHex] = enabled;
notifyListeners();
});
@@ -8398,7 +8453,7 @@ class MeshCoreConnector extends ChangeNotifier {
void _ensureContactCyr2LatProfileLoaded(String contactKeyHex) {
if (_contactCyr2LatProfileId.containsKey(contactKeyHex)) return;
_contactSettingsStore.loadCyr2LatProfileId(contactKeyHex).then((profileId) {
if (_contactCyr2LatProfileId[contactKeyHex] == profileId) return;
if (_contactCyr2LatProfileId.containsKey(contactKeyHex)) return;
_contactCyr2LatProfileId[contactKeyHex] = profileId;
notifyListeners();
});
@@ -8409,7 +8464,7 @@ class MeshCoreConnector extends ChangeNotifier {
final channelId = _slotChannelIds[channelIndex];
if (channelId == null) return;
_channelSettingsStore.loadCyr2LatEnabled(channelId).then((enabled) {
if (_channelCyr2LatEnabled[channelIndex] == enabled) return;
if (_channelCyr2LatEnabled.containsKey(channelIndex)) return;
_channelCyr2LatEnabled[channelIndex] = enabled;
notifyListeners();
});
@@ -8420,7 +8475,7 @@ class MeshCoreConnector extends ChangeNotifier {
final channelId = _slotChannelIds[channelIndex];
if (channelId == null) return;
_channelSettingsStore.loadCyr2LatProfileId(channelId).then((profileId) {
if (_channelCyr2LatProfileId[channelIndex] == profileId) return;
if (_channelCyr2LatProfileId.containsKey(channelIndex)) return;
_channelCyr2LatProfileId[channelIndex] = profileId;
notifyListeners();
});
@@ -8436,13 +8491,13 @@ class MeshCoreConnector extends ChangeNotifier {
String? profileId,
) async {
if (_channelCyr2LatProfileId[channelIndex] == profileId) return;
for (final slot in _slotsSharingChannel(channelIndex)) {
_channelCyr2LatProfileId[slot] = profileId;
}
final channelId = _channelIdForSlot(channelIndex);
if (channelId != null) {
await _channelSettingsStore.saveCyr2LatProfileId(channelId, profileId);
}
for (final slot in _slotsSharingChannel(channelIndex)) {
_channelCyr2LatProfileId[slot] = profileId;
}
notifyListeners();
}
@@ -8456,8 +8511,8 @@ class MeshCoreConnector extends ChangeNotifier {
String? profileId,
) async {
if (_contactCyr2LatProfileId[contactKeyHex] == profileId) return;
_contactCyr2LatProfileId[contactKeyHex] = profileId;
await _contactSettingsStore.saveCyr2LatProfileId(contactKeyHex, profileId);
_contactCyr2LatProfileId[contactKeyHex] = profileId;
notifyListeners();
}
@@ -9898,6 +9953,7 @@ class MeshCoreConnector extends ChangeNotifier {
_channelRegionStore.setPublicKeyHex = keyHex;
_contactSettingsStore.setPublicKeyHex = keyHex;
_contactStore.setPublicKeyHex = keyHex;
_contactAddedAtStore.setPublicKeyHex = keyHex;
_channelStore.setPublicKeyHex = keyHex;
_unreadStore.setPublicKeyHex = keyHex;
_discoveryContactStore.setPublicKeyHex = keyHex;