|
|
|
@ -34,36 +34,49 @@ class ConversationSearchViewController: UITableViewController {
|
|
|
|
|
|
|
|
|
|
tableView.register(ConversationSearchResultCell.self, forCellReuseIdentifier: ConversationSearchResultCell.reuseIdentifier)
|
|
|
|
|
tableView.register(MessageSearchResultCell.self, forCellReuseIdentifier: MessageSearchResultCell.reuseIdentifier)
|
|
|
|
|
tableView.register(ContactSearchResultCell.self, forCellReuseIdentifier: ContactSearchResultCell.reuseIdentifier)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: UITableViewDelegate
|
|
|
|
|
|
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
|
tableView.deselectRow(at: indexPath, animated: false)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let searchSection = SearchSection(rawValue: indexPath.section) else {
|
|
|
|
|
owsFail("\(logTag) unknown section selected.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var sectionResults: [SearchResult]
|
|
|
|
|
|
|
|
|
|
switch searchSection {
|
|
|
|
|
case .conversations:
|
|
|
|
|
sectionResults = searchResultSet.conversations
|
|
|
|
|
let sectionResults = searchResultSet.conversations
|
|
|
|
|
guard let searchResult = sectionResults[safe: indexPath.row] else {
|
|
|
|
|
owsFail("\(logTag) unknown row selected.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let thread = searchResult.thread
|
|
|
|
|
SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose)
|
|
|
|
|
|
|
|
|
|
case .contacts:
|
|
|
|
|
sectionResults = searchResultSet.contacts
|
|
|
|
|
let sectionResults = searchResultSet.contacts
|
|
|
|
|
guard let searchResult = sectionResults[safe: indexPath.row] else {
|
|
|
|
|
owsFail("\(logTag) unknown row selected.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SignalApp.shared().presentConversation(forRecipientId: searchResult.recipientId, action: .compose)
|
|
|
|
|
|
|
|
|
|
case .messages:
|
|
|
|
|
sectionResults = searchResultSet.messages
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard indexPath.row < sectionResults.count else {
|
|
|
|
|
owsFail("\(logTag) unknown row selected.")
|
|
|
|
|
return
|
|
|
|
|
let sectionResults = searchResultSet.messages
|
|
|
|
|
guard let searchResult = sectionResults[safe: indexPath.row] else {
|
|
|
|
|
owsFail("\(logTag) unknown row selected.")
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let thread = searchResult.thread
|
|
|
|
|
SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let searchResult = sectionResults[indexPath.row]
|
|
|
|
|
let thread = searchResult.thread
|
|
|
|
|
SignalApp.shared().presentConversation(for: thread.threadRecord, action: .compose)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: UITableViewDataSource
|
|
|
|
@ -102,8 +115,16 @@ class ConversationSearchViewController: UITableViewController {
|
|
|
|
|
cell.configure(searchResult: searchResult)
|
|
|
|
|
return cell
|
|
|
|
|
case .contacts:
|
|
|
|
|
// TODO
|
|
|
|
|
return UITableViewCell()
|
|
|
|
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: ContactSearchResultCell.reuseIdentifier) as? ContactSearchResultCell else {
|
|
|
|
|
return UITableViewCell()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
guard let searchResult = self.searchResultSet.contacts[safe: indexPath.row] else {
|
|
|
|
|
return UITableViewCell()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cell.configure(searchResult: searchResult)
|
|
|
|
|
return cell
|
|
|
|
|
case .messages:
|
|
|
|
|
guard let cell = tableView.dequeueReusableCell(withIdentifier: MessageSearchResultCell.reuseIdentifier) as? MessageSearchResultCell else {
|
|
|
|
|
return UITableViewCell()
|
|
|
|
@ -209,7 +230,7 @@ class ConversationSearchResultCell: UITableViewCell {
|
|
|
|
|
return Environment.current().contactsManager
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func configure(searchResult: SearchResult) {
|
|
|
|
|
func configure(searchResult: ConversationSearchResult) {
|
|
|
|
|
self.avatarView.image = OWSAvatarBuilder.buildImage(thread: searchResult.thread.threadRecord, diameter: avatarWidth, contactsManager: self.contactsManager)
|
|
|
|
|
self.nameLabel.text = searchResult.thread.name
|
|
|
|
|
self.snippetLabel.text = searchResult.snippet
|
|
|
|
@ -242,7 +263,7 @@ class MessageSearchResultCell: UITableViewCell {
|
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func configure(searchResult: SearchResult) {
|
|
|
|
|
func configure(searchResult: ConversationSearchResult) {
|
|
|
|
|
self.nameLabel.text = searchResult.thread.name
|
|
|
|
|
|
|
|
|
|
guard let snippet = searchResult.snippet else {
|
|
|
|
@ -272,3 +293,49 @@ class MessageSearchResultCell: UITableViewCell {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class ContactSearchResultCell: UITableViewCell {
|
|
|
|
|
static let reuseIdentifier = "ContactSearchResultCell"
|
|
|
|
|
|
|
|
|
|
let nameLabel: UILabel
|
|
|
|
|
let snippetLabel: UILabel
|
|
|
|
|
let avatarView: AvatarImageView
|
|
|
|
|
let avatarWidth: UInt = 40
|
|
|
|
|
|
|
|
|
|
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
|
|
|
|
|
self.nameLabel = UILabel()
|
|
|
|
|
self.snippetLabel = UILabel()
|
|
|
|
|
self.avatarView = AvatarImageView()
|
|
|
|
|
avatarView.autoSetDimensions(to: CGSize(width: CGFloat(avatarWidth), height: CGFloat(avatarWidth)))
|
|
|
|
|
|
|
|
|
|
super.init(style: style, reuseIdentifier: reuseIdentifier)
|
|
|
|
|
|
|
|
|
|
nameLabel.font = UIFont.ows_dynamicTypeBody.ows_mediumWeight()
|
|
|
|
|
snippetLabel.font = UIFont.ows_dynamicTypeFootnote
|
|
|
|
|
|
|
|
|
|
let textRows = UIStackView(arrangedSubviews: [nameLabel, snippetLabel])
|
|
|
|
|
textRows.axis = .vertical
|
|
|
|
|
|
|
|
|
|
let columns = UIStackView(arrangedSubviews: [avatarView, textRows])
|
|
|
|
|
columns.axis = .horizontal
|
|
|
|
|
columns.spacing = 8
|
|
|
|
|
|
|
|
|
|
contentView.addSubview(columns)
|
|
|
|
|
columns.autoPinEdgesToSuperviewMargins()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
required init?(coder aDecoder: NSCoder) {
|
|
|
|
|
fatalError("init(coder:) has not been implemented")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var contactsManager: OWSContactsManager {
|
|
|
|
|
return Environment.current().contactsManager
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func configure(searchResult: ContactSearchResult) {
|
|
|
|
|
let avatarBuilder = OWSContactAvatarBuilder.init(signalId: searchResult.recipientId, diameter: avatarWidth, contactsManager: contactsManager)
|
|
|
|
|
self.avatarView.image = avatarBuilder.build()
|
|
|
|
|
self.nameLabel.text = self.contactsManager.displayName(forPhoneIdentifier: searchResult.recipientId)
|
|
|
|
|
self.snippetLabel.text = searchResult.recipientId
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|