remove populate cache on loading home page

pull/541/head
Ryan Zhao 3 years ago
parent 69352efa32
commit ec9adfee7f

@ -10,18 +10,13 @@ public final class MentionUtilities : NSObject {
@objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, threadID: String, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString { @objc public static func highlightMentions(in string: String, isOutgoingMessage: Bool, threadID: String, attributes: [NSAttributedString.Key:Any]) -> NSAttributedString {
let openGroupV2 = Storage.shared.getV2OpenGroup(for: threadID) let openGroupV2 = Storage.shared.getV2OpenGroup(for: threadID)
OWSPrimaryStorage.shared().dbReadConnection.read { transaction in
MentionsManager.populateUserPublicKeyCacheIfNeeded(for: threadID, in: transaction)
}
var string = string var string = string
let regex = try! NSRegularExpression(pattern: "@[0-9a-fA-F]{66}", options: []) 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 mentions: [(range: NSRange, publicKey: String)] = []
var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.utf16.count)) var outerMatch = regex.firstMatch(in: string, options: .withoutAnchoringBounds, range: NSRange(location: 0, length: string.utf16.count))
while let match = outerMatch { while let match = outerMatch {
let publicKey = 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 matchEnd: Int
if knownPublicKeys.contains(publicKey) {
let context: Contact.Context = (openGroupV2 != nil) ? .openGroup : .regular let context: Contact.Context = (openGroupV2 != nil) ? .openGroup : .regular
let displayName = Storage.shared.getContact(with: publicKey)?.displayName(for: context) let displayName = Storage.shared.getContact(with: publicKey)?.displayName(for: context)
if let displayName = displayName { if let displayName = displayName {
@ -31,9 +26,6 @@ public final class MentionUtilities : NSObject {
} else { } else {
matchEnd = match.range.location + match.range.length 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.utf16.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) let result = NSMutableAttributedString(string: string, attributes: attributes)

Loading…
Cancel
Save