From ec9adfee7fad8766e257f044e337075b7ad1bbc4 Mon Sep 17 00:00:00 2001 From: Ryan Zhao Date: Wed, 15 Dec 2021 16:35:47 +1100 Subject: [PATCH] remove populate cache on loading home page --- Session/Utilities/MentionUtilities.swift | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Session/Utilities/MentionUtilities.swift b/Session/Utilities/MentionUtilities.swift index f0f5be6c8..fb0fb0d82 100644 --- a/Session/Utilities/MentionUtilities.swift +++ b/Session/Utilities/MentionUtilities.swift @@ -10,27 +10,19 @@ public final class MentionUtilities : NSObject { @objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, threadID: String, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString { let openGroupV2 = Storage.shared.getV2OpenGroup(for: threadID) - OWSPrimaryStorage.shared().dbReadConnection.read { transaction in - MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction) - } var string = string let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]{66}", options: []) - let knownPublicKeys = MentionsManager.userPublicKeyCache[threadID] ?? [] // Should always be populated at this point 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 - if knownPublicKeys.contains(publicKey) { - let context: Contact.Context = (openGroupV2 != nil) ? .openGroup : .regular - let displayName = Storage.shared.getContact(with: publicKey)?.displayName(for: context) - if let displayName = displayName { - string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)") - 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 - } + let context: Contact.Context = (openGroupV2 != nil) ? .openGroup : .regular + let displayName = Storage.shared.getContact(with: publicKey)?.displayName(for: context) + if let displayName = displayName { + string = (string as NSString).replacingCharacters(in: match.range, with: "@\(displayName)") + 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 }