Strip snippet formatting.

This commit is contained in:
Matthew Chen 2018-06-12 17:18:24 -04:00
parent 31443b5687
commit f0c1805de9
2 changed files with 10 additions and 13 deletions

View file

@ -191,22 +191,18 @@ class ConversationSearchViewController: UITableViewController {
}
overrideTimestamp = NSNumber(value: message.timestamp)
guard let snippet = searchResult.snippet else {
guard let rawSnippet = searchResult.snippet else {
owsFail("\(ConversationSearchViewController.logTag) message search result is missing snippet")
return
}
guard let snippetData = snippet.data(using: String.Encoding.utf8) else {
owsFail("\(ConversationSearchViewController.logTag) message search result has invalid snippet")
return
}
do {
let snippetOptions = [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html]
overrideSnippet = try NSAttributedString(data: snippetData,
options: snippetOptions,
documentAttributes: nil)
} catch {
owsFail("\(ConversationSearchViewController.logTag) could not parse message snippet")
}
// YDB uses bold tags to highlight matches within the snippet.
let filteredSnippet = rawSnippet
.replacingOccurrences(of: "<b>", with: "")
.replacingOccurrences(of: "</b>", with: "")
.replacingOccurrences(of: "<B>", with: "")
.replacingOccurrences(of: "</B>", with: "")
overrideSnippet = NSAttributedString(string: filteredSnippet)
}
cell.configure(withThread: searchResult.thread,

View file

@ -106,6 +106,7 @@ public class ConversationSearcher: NSObject {
var existingConversationRecipientIds: Set<String> = Set()
self.finder.enumerateObjects(searchText: searchText, transaction: transaction) { (match: Any, snippet: String?) in
if let thread = match as? TSThread {
let threadViewModel = ThreadViewModel(thread: thread, transaction: transaction)
let snippet: String? = thread.lastMessageText(transaction: transaction)