From e6953f4ef5be20ddac3d3835e0ebd3f6702111c5 Mon Sep 17 00:00:00 2001 From: Taksh Date: Mon, 5 Oct 2026 16:10:52 +0530 Subject: [PATCH] Resolve normalized composer mentions Split the existing PR change into a smaller reviewable piece. Original change: fix(composer): accept combining marks in @mention regex --- .../ViewModels/ChatComposerCoordinator.swift | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/bitchat/ViewModels/ChatComposerCoordinator.swift b/bitchat/ViewModels/ChatComposerCoordinator.swift index d0d347f2..0e52b3f3 100644 --- a/bitchat/ViewModels/ChatComposerCoordinator.swift +++ b/bitchat/ViewModels/ChatComposerCoordinator.swift @@ -116,6 +116,9 @@ final class ChatComposerCoordinator { } func parseMentions(from content: String) -> [String] { + // Canonicalize before matching so NFD typed text and NFC peer tokens + // share one codepoint sequence (regex also accepts combining marks). + let content = content.precomposedStringWithCanonicalMapping let regex = ChatViewModel.Patterns.mention let nsContent = content as NSString let matches = regex.matches( @@ -125,16 +128,22 @@ final class ChatComposerCoordinator { ) let peerNicknames = context.meshPeerNicknames() - var validTokens = Set(peerNicknames.values) - validTokens.insert(context.nickname) - validTokens.insert(context.nickname + "#" + String(context.myPeerID.id.prefix(4))) + // Key by NFC so a typed combining-accent form still resolves to the + // stored (precomposed) nickname token used on the wire. + var tokensByCanonical = [String: String]() + for token in peerNicknames.values { + tokensByCanonical[token.normalizedNickname] = token + } + tokensByCanonical[context.nickname.normalizedNickname] = context.nickname + let selfSuffix = context.nickname + "#" + String(context.myPeerID.id.prefix(4)) + tokensByCanonical[selfSuffix.normalizedNickname] = selfSuffix var mentions: [String] = [] for match in matches { guard let range = Range(match.range(at: 1), in: content) else { continue } let mentionedName = String(content[range]) - if validTokens.contains(mentionedName) { - mentions.append(mentionedName) + if let canonical = tokensByCanonical[mentionedName.normalizedNickname] { + mentions.append(canonical) } }