From 926a5dc8b82a4e79a23dda0aa4a63f4edc528ec3 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 13 Aug 2020 17:28:38 +1000 Subject: [PATCH] Fix emoji handling --- .../NotificationServiceExtension.swift | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LokiPushNotificationService/NotificationServiceExtension.swift b/LokiPushNotificationService/NotificationServiceExtension.swift index 3222febed..91ea74b55 100644 --- a/LokiPushNotificationService/NotificationServiceExtension.swift +++ b/LokiPushNotificationService/NotificationServiceExtension.swift @@ -121,18 +121,18 @@ final class NotificationServiceExtension : UNNotificationServiceExtension { func handleMentionIfNecessary(rawMessageBody: String, threadID: String, transaction: YapDatabaseReadWriteTransaction) -> String { var string = rawMessageBody let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]*", options: []) - var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.count)) + var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.utf16.count)) while let match = outerMatch { - let hexEncodedPublicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @ + let publicKey = String((string as NSString).substring(with: match.range).dropFirst()) // Drop the @ let matchEnd: Int - let displayName: String? = OWSProfileManager.shared().profileNameForRecipient(withID: hexEncodedPublicKey, transaction: transaction) + let displayName: String? = OWSProfileManager.shared().profileNameForRecipient(withID: publicKey, transaction: transaction) if let displayName = displayName { string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)") - matchEnd = match.range.location + displayName.count + matchEnd = match.range.location + displayName.utf16.count } 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)) } return string }