search for name and nickname

pull/555/head
Ryan Zhao 4 years ago
parent 8be5768ad2
commit 42903d835d

@ -220,8 +220,8 @@ final class ConversationCell : UITableViewCell {
snippetLabel.attributedText = getHighlightedSnippet(snippet: snippet, searchText: normalizedSearchText, fontSize: Values.smallFontSize)
} else {
// Contact
displayNameLabel.attributedText = getHighlightedSnippet(snippet: getDisplayName(), searchText: normalizedSearchText, fontSize: Values.mediumFontSize)
if threadViewModel.isGroupThread, let thread = threadViewModel.threadRecord as? TSGroupThread {
displayNameLabel.attributedText = getHighlightedSnippet(snippet: getDisplayName(), searchText: normalizedSearchText, fontSize: Values.mediumFontSize)
bottomLabelStackView.isHidden = false
let context: Contact.Context = thread.isOpenGroup ? .openGroup : .regular
var rawSnippet: String = ""
@ -237,6 +237,7 @@ final class ConversationCell : UITableViewCell {
}
snippetLabel.attributedText = getHighlightedSnippet(snippet: rawSnippet, searchText: normalizedSearchText, fontSize: Values.smallFontSize)
} else {
displayNameLabel.attributedText = getHighlightedSnippet(snippet: getDisplayNameForSearch(threadViewModel.contactSessionID!), searchText: normalizedSearchText, fontSize: Values.mediumFontSize)
bottomLabelStackView.isHidden = true
}
timestampLabel.isHidden = true
@ -316,6 +317,15 @@ final class ConversationCell : UITableViewCell {
}
}
private func getDisplayNameForSearch(_ sessionID: String) -> String {
var result = sessionID
if let contact = Storage.shared.getContact(with: sessionID), let name = contact.name {
result = name
if let nickname = contact.nickname { result += "(\(nickname))"}
}
return result
}
private func getDisplayName() -> String {
if threadViewModel.isGroupThread {
if threadViewModel.name.isEmpty {

@ -178,8 +178,12 @@ public class FullTextSearchFinder: NSObject {
}
private static let recipientIndexer: SearchIndexer<String> = SearchIndexer { (recipientId: String, transaction: YapDatabaseReadTransaction) in
let displayName = Storage.shared.getContact(with: recipientId)?.displayName(for: Contact.Context.regular) ?? recipientId
return "\(recipientId) \(displayName)"
var result = "\(recipientId)"
if let contact = Storage.shared.getContact(with: recipientId) {
if let name = contact.name { result += " \(name)" }
if let nickname = contact.nickname { result += " \(nickname)" }
}
return result
}
private static let messageIndexer: SearchIndexer<TSMessage> = SearchIndexer { (message: TSMessage, transaction: YapDatabaseReadTransaction) in
@ -242,6 +246,6 @@ public class FullTextSearchFinder: NSObject {
options: nil,
handler: handler,
ftsVersion: YapDatabaseFullTextSearchFTS5Version,
versionTag: "1")
versionTag: "2")
}
}

Loading…
Cancel
Save