From 91608ff09e248fd96398cd040e90893ecb80c91c Mon Sep 17 00:00:00 2001 From: zjs81 Date: Sat, 14 Mar 2026 09:44:37 -0700 Subject: [PATCH] feat: improve message matching logic and update notification IDs for advertisements --- .swift-version | 1 + lib/services/message_retry_service.dart | 16 ++-------------- lib/services/notification_service.dart | 6 ++++-- 3 files changed, 7 insertions(+), 16 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..31b44b0 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +6.2.4 \ No newline at end of file diff --git a/lib/services/message_retry_service.dart b/lib/services/message_retry_service.dart index df81d16..56d7b82 100644 --- a/lib/services/message_retry_service.dart +++ b/lib/services/message_retry_service.dart @@ -355,24 +355,12 @@ class MessageRetryService extends ChangeNotifier { 'Hash-based match failed for $ackHashHex, falling back to queue-based matching', ); - // Try to identify the correct contact from _activeMessages first. - String? targetContactKey; - for (final activeId in _activeMessages) { - final activeContact = _pendingContacts[activeId]; - if (activeContact != null) { - targetContactKey = activeContact.publicKeyHex; - break; - } - } - - final queuesToSearch = targetContactKey != null - ? {targetContactKey: _pendingMessageQueuePerContact[targetContactKey]} - : _pendingMessageQueuePerContact; + // Search all contact queues so concurrent chats don't miss matches. + final queuesToSearch = _pendingMessageQueuePerContact; for (var entry in queuesToSearch.entries) { final contactKey = entry.key; final queue = entry.value; - if (queue == null) continue; // Drain stale entries until we find a valid one or exhaust the queue. while (queue.isNotEmpty) { diff --git a/lib/services/notification_service.dart b/lib/services/notification_service.dart index 4ed59d0..62d3796 100644 --- a/lib/services/notification_service.dart +++ b/lib/services/notification_service.dart @@ -232,7 +232,9 @@ class NotificationService { try { await _notifications.show( - id: contactId?.hashCode ?? DateTime.now().millisecondsSinceEpoch, + id: contactId != null + ? 'advert:$contactId'.hashCode + : DateTime.now().millisecondsSinceEpoch, title: _l10n.notification_newTypeDiscovered(contactType), body: contactName, notificationDetails: notificationDetails, @@ -355,7 +357,7 @@ class NotificationService { Future clearAdvertNotifications(List contactIds) async { if (!await _ensureInitialized()) return; for (final id in contactIds) { - await _notifications.cancel(id: id.hashCode); + await _notifications.cancel(id: 'advert:$id'.hashCode); } }