From f4c6cffea132a14710f4836e1ee15fa06fe39c2a Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 5 Aug 2020 15:25:57 +1000 Subject: [PATCH] Fix emoji handling --- Signal/src/Loki/Utilities/MentionUtilities.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Signal/src/Loki/Utilities/MentionUtilities.swift b/Signal/src/Loki/Utilities/MentionUtilities.swift index 388a07f10..08da7733e 100644 --- a/Signal/src/Loki/Utilities/MentionUtilities.swift +++ b/Signal/src/Loki/Utilities/MentionUtilities.swift @@ -17,8 +17,8 @@ public final class MentionUtilities : NSObject { var string = string let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: []) let knownPublicKeys = MentionsManager.userPublicKeyCache[threadID] ?? [] // Should always be populated at this point - var mentions: [(range: NSRange, hexEncodedPublicKey: String)] = [] - var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count)) + var mentions: [(range: NSRange, publicKey: String)] = [] + var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.utf16.count)) while let match = outerMatch { let publicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @ let matchEnd: Int @@ -35,15 +35,15 @@ public final class MentionUtilities : NSObject { } if let displayName = displayName { string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)") - mentions.append((range: NSRange(location: match.range.location, length: displayName.count + 1), hexEncodedPublicKey: publicKey)) // + 1 to include the @ - matchEnd = match.range.location + displayName.count + mentions.append((range: NSRange(location: match.range.location, length: displayName.utf16.count + 1), publicKey: publicKey)) // + 1 to include the @ + matchEnd = match.range.location + displayName.utf16.count } else { matchEnd = match.range.location + match.range.length } } else { matchEnd = match.range.location + match.range.length } - outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: matchEnd, length: string.count - matchEnd)) + outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: matchEnd, length: string.utf16.count - matchEnd)) } let result = NSMutableAttributedString(string: string, attributes: attributes) mentions.forEach { mention in