Merge remote-tracking branch 'zjs81/dev' into ez_disable_discoveredContact_eviction_PR

This commit is contained in:
ericz committed 2026-09-08 18:09:32 +02:00
commit 4480c0d356
56 files changed
+1500 -229

No files matched your search

+82 -17
View File
@@ -375,12 +375,14 @@ class MeshCoreConnector extends ChangeNotifier {
List<Channel> _cachedChannels = [];
final Map<int, bool> _channelSmazEnabled = {};
final Map<int, bool> _channelCyr2LatEnabled = {};
final Map<int, bool> _channelUrlImagesEnabled = {};
final Map<int, String?> _channelCyr2LatProfileId = {};
final Map<int, Region> _channelRegions = {};
bool _lastSentWasCliCommand =
false; // Track if last sent message was a CLI command
final Map<String, bool> _contactSmazEnabled = {};
final Map<String, bool> _contactCyr2LatEnabled = {};
final Map<String, bool> _contactUrlImagesEnabled = {};
final Map<String, String?> _contactCyr2LatProfileId = {};
final Set<String> _knownContactKeys = {};
final Map<String, int> _contactUnreadCount = {};
@@ -454,6 +456,13 @@ class MeshCoreConnector extends ChangeNotifier {
);
}
Contact? getContactByPubKeyHex(String contactPubKeyHex) {
return _contacts.cast<Contact?>().firstWhere(
(c) => c?.publicKeyHex == contactPubKeyHex,
orElse: () => null,
);
}
List<Contact> get allContacts => List.unmodifiable([
..._contacts,
..._discoveredContacts.where(
@@ -782,6 +791,15 @@ class MeshCoreConnector extends ChangeNotifier {
return _contactSmazEnabled[contactKeyHex] ?? false;
}
bool isChannelUrlImagesEnabled(int channelIndex) {
return _channelUrlImagesEnabled[channelIndex] ?? false;
}
bool isContactUrlImagesEnabled(String contactKeyHex) {
_ensureContactUrlImagesSettingLoaded(contactKeyHex);
return _contactUrlImagesEnabled[contactKeyHex] ?? false;
}
bool hasChannelRegion(int channelIndex) {
return (_channelRegions[channelIndex] ?? '').isNotEmpty;
}
@@ -924,6 +942,24 @@ class MeshCoreConnector extends ChangeNotifier {
notifyListeners();
}
Future<void> setChannelUrlImagesEnabled(
int channelIndex,
bool enabled,
) async {
_channelUrlImagesEnabled[channelIndex] = enabled;
await _channelSettingsStore.saveUrlImagesEnabled(channelIndex, enabled);
notifyListeners();
}
Future<void> setContactUrlImagesEnabled(
String contactKeyHex,
bool enabled,
) async {
_contactUrlImagesEnabled[contactKeyHex] = enabled;
await _contactSettingsStore.saveUrlImagesEnabled(contactKeyHex, enabled);
notifyListeners();
}
Future<void> setChannelCyr2LatEnabled(int channelIndex, bool enabled) async {
_channelCyr2LatEnabled[channelIndex] = enabled;
if (enabled) {
@@ -1094,6 +1130,7 @@ class MeshCoreConnector extends ChangeNotifier {
}
Future<void> loadContactCache() async {
_contactUrlImagesEnabled.clear();
final cached = await _contactStore.loadContacts();
_knownContactKeys
..clear()
@@ -1104,6 +1141,7 @@ class MeshCoreConnector extends ChangeNotifier {
for (final contact in cached) {
_ensureContactSmazSettingLoaded(contact.publicKeyHex);
_ensureContactCyr2LatSettingLoaded(contact.publicKeyHex);
_ensureContactUrlImagesSettingLoaded(contact.publicKeyHex);
}
}
@@ -1136,12 +1174,15 @@ class MeshCoreConnector extends ChangeNotifier {
Future<void> loadChannelSettings({int? maxChannels}) async {
_channelSmazEnabled.clear();
_channelCyr2LatEnabled.clear();
_channelUrlImagesEnabled.clear();
_channelRegions.clear();
final channelCount = maxChannels ?? _maxChannels;
for (int i = 0; i < channelCount; i++) {
_channelSmazEnabled[i] = await _channelSettingsStore.loadSmazEnabled(i);
_channelCyr2LatEnabled[i] = await _channelSettingsStore
.loadCyr2LatEnabled(i);
_channelUrlImagesEnabled[i] = await _channelSettingsStore
.loadUrlImagesEnabled(i);
_channelRegions[i] = await _channelRegionStore.loadRegion(i);
}
}
@@ -3162,9 +3203,15 @@ class MeshCoreConnector extends ChangeNotifier {
// Check if this is a reaction - apply locally with pending status and route through retry service
final reactionInfo = ReactionHelper.parseReaction(text);
if (reactionInfo != null) {
appLogger.info('Sending reaction: ${reactionInfo.identifier()}');
_conversations.putIfAbsent(contact.publicKeyHex, () => []);
final messages = _conversations[contact.publicKeyHex]!;
// No check for duplicates. If you want to do it again to resend, you can.
final String reactionID = reactionInfo.identifier();
_processedContactReactions.putIfAbsent(contact.publicKeyHex, () => {});
_processedContactReactions[contact.publicKeyHex]!.add(reactionID);
// Apply reaction locally with pending status
_processOutgoingContactReaction(messages, reactionInfo, contact);
_setReactionStatus(
@@ -3206,7 +3253,7 @@ class MeshCoreConnector extends ChangeNotifier {
translatedLanguageCode: translatedLanguageCode,
translationModelId: translationModelId,
);
_addMessage(contact.publicKeyHex, message);
_addMessage(contact.publicKeyHex, message); // recipient as "sender"
notifyListeners();
final outboundText = prepareContactOutboundText(contact, text);
await sendFrame(buildSendTextMsgFrame(contact.publicKey, outboundText));
@@ -3543,11 +3590,12 @@ class MeshCoreConnector extends ChangeNotifier {
// Check if this is a reaction - if so, process it immediately instead of adding as a message
final reactionInfo = ReactionHelper.parseReaction(text);
if (reactionInfo != null) {
reactionInfo.senderName = selfName;
// Check if we've already processed this reaction
_processedChannelReactions.putIfAbsent(channel.index, () => {});
final reactionIdentifier =
'${reactionInfo.targetHash}_${reactionInfo.emoji}';
final reactionIdentifier = reactionInfo.identifier();
// Maybe we should allow resending. Recipients can drop duplicates.
if (_processedChannelReactions[channel.index]!.contains(
reactionIdentifier,
)) {
@@ -3560,6 +3608,7 @@ class MeshCoreConnector extends ChangeNotifier {
final messages = _channelMessages[channel.index]!;
// Process reaction locally to update the UI immediately
appLogger.info('Adding sent channel reaction, id: $reactionIdentifier');
_processReaction(messages, reactionInfo);
await _channelMessageStore.saveChannelMessages(channel.index, messages);
@@ -5326,6 +5375,8 @@ class MeshCoreConnector extends ChangeNotifier {
await _notificationService.showMessageNotification(
contactName: c?.name ?? 'Unknown',
message: resolvedText,
urlImagesEnabled:
c != null && isContactUrlImagesEnabled(c.publicKeyHex),
contactId: msg.senderKeyHex,
badgeCount: getTotalUnreadCount(),
);
@@ -5340,6 +5391,8 @@ class MeshCoreConnector extends ChangeNotifier {
await _notificationService.showMessageNotification(
contactName: c?.name ?? 'Unknown Room',
message: resolvedText,
urlImagesEnabled:
c != null && isContactUrlImagesEnabled(c.publicKeyHex),
contactId: msg.senderKeyHex,
badgeCount: getTotalUnreadCount(),
);
@@ -5490,6 +5543,15 @@ class MeshCoreConnector extends ChangeNotifier {
});
}
void _ensureContactUrlImagesSettingLoaded(String contactKeyHex) {
if (_contactUrlImagesEnabled.containsKey(contactKeyHex)) return;
_contactSettingsStore.loadUrlImagesEnabled(contactKeyHex).then((enabled) {
if (_contactUrlImagesEnabled[contactKeyHex] == enabled) return;
_contactUrlImagesEnabled[contactKeyHex] = enabled;
notifyListeners();
});
}
void _ensureContactCyr2LatProfileLoaded(String contactKeyHex) {
if (_contactCyr2LatProfileId.containsKey(contactKeyHex)) return;
_contactSettingsStore.loadCyr2LatProfileId(contactKeyHex).then((profileId) {
@@ -5644,6 +5706,7 @@ class MeshCoreConnector extends ChangeNotifier {
channelName: label,
senderName: message.senderName,
message: resolvedText,
urlImagesEnabled: isChannelUrlImagesEnabled(channelIndex),
channelIndex: message.channelIndex,
badgeCount: getTotalUnreadCount(),
);
@@ -6219,15 +6282,23 @@ class MeshCoreConnector extends ChangeNotifier {
if (reactionInfo != null) {
// Check if we've already processed this exact reaction
_processedContactReactions.putIfAbsent(pubKeyHex, () => {});
final reactionIdentifier =
'${reactionInfo.targetHash}_${reactionInfo.emoji}';
reactionInfo.senderName = _resolveContactSenderName(message, null, false);
final reactionIdentifier = reactionInfo.identifier();
final isDuplicate = _processedContactReactions[pubKeyHex]!.contains(
reactionIdentifier,
);
if (!isDuplicate) {
// New reaction - process it
appLogger.info('Adding reaction, id: $reactionIdentifier');
// For hashing and dup checking, we use null for sender names in
// normal 1:1 chats. This way if we and they have different ideas
// about what their name is, reactions still work. But for reaction
// reports, we want to know who sent what, rather than infer it later,
// so we'll add it to the reactionInfo before storing it.
reactionInfo.senderName ??= message.isOutgoing
? selfName
: getContactByPubKeyHex(pubKeyHex)?.name ?? '???';
_processContactReaction(messages, reactionInfo, pubKeyHex);
_messageStore.saveMessages(pubKeyHex, messages);
@@ -6252,10 +6323,7 @@ class MeshCoreConnector extends ChangeNotifier {
ReactionInfo reactionInfo,
String contactPubKeyHex,
) {
final contact = _contacts.cast<Contact?>().firstWhere(
(c) => c?.publicKeyHex == contactPubKeyHex,
orElse: () => null,
);
final contact = getContactByPubKeyHex(contactPubKeyHex);
final isRoomServer = contact?.type == advTypeRoom;
ReactionHelper.applyReaction<Message>(
@@ -6304,10 +6372,7 @@ class MeshCoreConnector extends ChangeNotifier {
) {
final messages = _conversations[pubKeyHex];
if (messages == null) return;
final contact = _contacts.cast<Contact?>().firstWhere(
(c) => c?.publicKeyHex == pubKeyHex,
orElse: () => null,
);
final contact = getContactByPubKeyHex(pubKeyHex);
final isRoomServer = contact?.type == advTypeRoom;
for (int i = messages.length - 1; i >= 0; i--) {
final msg = messages[i];
@@ -6466,12 +6531,11 @@ class MeshCoreConnector extends ChangeNotifier {
final messages = _channelMessages[channelIndex]!;
// Parse reaction info
final reactionInfo = ChannelMessage.parseReaction(message.text);
final reactionInfo = message.parseReaction();
if (reactionInfo != null) {
// Check if we've already processed this exact reaction
_processedChannelReactions.putIfAbsent(channelIndex, () => {});
final reactionIdentifier =
'${reactionInfo.targetHash}_${reactionInfo.emoji}';
final reactionIdentifier = reactionInfo.identifier();
final isDuplicate = _processedChannelReactions[channelIndex]!.contains(
reactionIdentifier,
@@ -6479,6 +6543,7 @@ class MeshCoreConnector extends ChangeNotifier {
if (!isDuplicate) {
// New reaction - process it
appLogger.info('Adding channel reaction, id: $reactionIdentifier');
_processReaction(messages, reactionInfo);
// Save updated messages
_channelMessageStore.saveChannelMessages(channelIndex, messages);