Strip snippet formatting.

pull/1/head
Matthew Chen 7 years ago
parent 31443b5687
commit f0c1805de9

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

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

Loading…
Cancel
Save