Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent f0c1805de9
commit 99677899b1

@ -29,23 +29,15 @@ class ConversationSearchViewController: UITableViewController {
case messages case messages
} }
var contactsManager: OWSContactsManager {
return Environment.current().contactsManager
}
var blockedPhoneNumberSet = Set<String>() var blockedPhoneNumberSet = Set<String>()
// MARK: View Lifecyle // MARK: View Lifecyle
override public func loadView() { override func viewDidLoad() {
super.loadView() super.viewDidLoad()
let blockingManager = OWSBlockingManager.shared() let blockingManager = OWSBlockingManager.shared()
blockedPhoneNumberSet = Set(blockingManager.blockedPhoneNumbers()) blockedPhoneNumberSet = Set(blockingManager.blockedPhoneNumbers())
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 60 tableView.estimatedRowHeight = 60
@ -179,30 +171,29 @@ class ConversationSearchViewController: UITableViewController {
var overrideSnippet = NSAttributedString() var overrideSnippet = NSAttributedString()
var overrideTimestamp: NSNumber? var overrideTimestamp: NSNumber?
self.uiDatabaseConnection.read { transaction in if let messageId = searchResult.messageId {
guard let messageId = searchResult.messageId else { if let messageTimestamp = searchResult.messageTimestamp {
owsFail("\(ConversationSearchViewController.logTag) message search result is missing message id") overrideTimestamp = NSNumber(value: messageTimestamp)
return } else {
} owsFail("\(ConversationSearchViewController.logTag) message search result is missing message timestamp")
guard let message = TSInteraction.fetch(uniqueId: messageId, transaction: transaction) else {
// This could happen if the message has disappeared, etc.
Logger.error("\(ConversationSearchViewController.logTag) could not load message")
return
} }
overrideTimestamp = NSNumber(value: message.timestamp)
guard let rawSnippet = searchResult.snippet else { // Note that we only use the snippet for message results,
owsFail("\(ConversationSearchViewController.logTag) message search result is missing snippet") // not conversation results. HomeViewCell will generate
return // a snippet for conversations that reflects the latest
// contents.
if let messageSnippet = searchResult.snippet {
// YDB uses bold tags to highlight matches within the snippet.
let filteredSnippet = messageSnippet
.replacingOccurrences(of: "<b>", with: "")
.replacingOccurrences(of: "</b>", with: "")
.replacingOccurrences(of: "<B>", with: "")
.replacingOccurrences(of: "</B>", with: "")
overrideSnippet = NSAttributedString(string: filteredSnippet)
} else {
owsFail("\(ConversationSearchViewController.logTag) message search result is missing 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, cell.configure(withThread: searchResult.thread,

@ -9,16 +9,18 @@ public class ConversationSearchResult: Comparable {
public let thread: ThreadViewModel public let thread: ThreadViewModel
public let messageId: String? public let messageId: String?
public let messageTimestamp: UInt64?
public let snippet: String? public let snippet: String?
private let sortKey: UInt64 private let sortKey: UInt64
init(thread: ThreadViewModel, messageId: String?, snippet: String?, sortKey: UInt64) { init(thread: ThreadViewModel, sortKey: UInt64, messageId: String? = nil, messageTimestamp: UInt64? = nil, snippet: String? = nil) {
self.thread = thread self.thread = thread
self.sortKey = sortKey
self.messageId = messageId self.messageId = messageId
self.messageTimestamp = messageTimestamp
self.snippet = snippet self.snippet = snippet
self.sortKey = sortKey
} }
// Mark: Comparable // Mark: Comparable
@ -109,9 +111,8 @@ public class ConversationSearcher: NSObject {
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 sortKey = NSDate.ows_millisecondsSince1970(for: threadViewModel.lastMessageDate) let sortKey = NSDate.ows_millisecondsSince1970(for: threadViewModel.lastMessageDate)
let searchResult = ConversationSearchResult(thread: threadViewModel, messageId: nil, snippet: snippet, sortKey: sortKey) let searchResult = ConversationSearchResult(thread: threadViewModel, sortKey: sortKey)
if let contactThread = thread as? TSContactThread { if let contactThread = thread as? TSContactThread {
let recipientId = contactThread.contactIdentifier() let recipientId = contactThread.contactIdentifier()
@ -124,7 +125,12 @@ public class ConversationSearcher: NSObject {
let threadViewModel = ThreadViewModel(thread: thread, transaction: transaction) let threadViewModel = ThreadViewModel(thread: thread, transaction: transaction)
let sortKey = message.timestamp let sortKey = message.timestamp
let searchResult = ConversationSearchResult(thread: threadViewModel, messageId: message.uniqueId, snippet: snippet, sortKey: sortKey) let searchResult = ConversationSearchResult(thread: threadViewModel,
sortKey: sortKey,
messageId: message.uniqueId,
messageTimestamp: message.timestamp,
snippet: snippet)
messages.append(searchResult) messages.append(searchResult)
} else if let signalAccount = match as? SignalAccount { } else if let signalAccount = match as? SignalAccount {
let searchResult = ContactSearchResult(signalAccount: signalAccount, contactsManager: contactsManager) let searchResult = ContactSearchResult(signalAccount: signalAccount, contactsManager: contactsManager)

Loading…
Cancel
Save