Respond to CR.

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

@ -29,23 +29,15 @@ class ConversationSearchViewController: UITableViewController {
case messages
}
var contactsManager: OWSContactsManager {
return Environment.current().contactsManager
}
var blockedPhoneNumberSet = Set<String>()
// MARK: View Lifecyle
override public func loadView() {
super.loadView()
override func viewDidLoad() {
super.viewDidLoad()
let blockingManager = OWSBlockingManager.shared()
blockedPhoneNumberSet = Set(blockingManager.blockedPhoneNumbers())
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 60
@ -179,30 +171,29 @@ class ConversationSearchViewController: UITableViewController {
var overrideSnippet = NSAttributedString()
var overrideTimestamp: NSNumber?
self.uiDatabaseConnection.read { transaction in
guard let messageId = searchResult.messageId else {
owsFail("\(ConversationSearchViewController.logTag) message search result is missing message id")
return
}
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
if let messageId = searchResult.messageId {
if let messageTimestamp = searchResult.messageTimestamp {
overrideTimestamp = NSNumber(value: messageTimestamp)
} else {
owsFail("\(ConversationSearchViewController.logTag) message search result is missing message timestamp")
}
overrideTimestamp = NSNumber(value: message.timestamp)
guard let rawSnippet = searchResult.snippet else {
owsFail("\(ConversationSearchViewController.logTag) message search result is missing snippet")
return
// Note that we only use the snippet for message results,
// not conversation results. HomeViewCell will generate
// 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,

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

Loading…
Cancel
Save