snippet for group members

pull/555/head
Ryan Zhao 3 years ago
parent 037d70b185
commit 8be5768ad2

@ -305,7 +305,7 @@ final class HomeVC : BaseVC, UITableViewDataSource, UITableViewDelegate, NewConv
} }
@objc private func handleSeedViewedNotification(_ notification: Notification) { @objc private func handleSeedViewedNotification(_ notification: Notification) {
self.tableView.reloadSections(IndexSet(integer: 0), with: .none) // TODO: Just reload header self.tableView.reloadSections(IndexSet(integer: 0), with: .none) // TODO: Just reload header if possible
} }
@objc private func handleBlockedContactsUpdatedNotification(_ notification: Notification) { @objc private func handleBlockedContactsUpdatedNotification(_ notification: Notification) {

@ -82,7 +82,7 @@ class BaseVC : UIViewController {
headingImageView.image = UIImage(named: "SessionHeading")?.withRenderingMode(.alwaysTemplate) headingImageView.image = UIImage(named: "SessionHeading")?.withRenderingMode(.alwaysTemplate)
headingImageView.contentMode = .scaleAspectFit headingImageView.contentMode = .scaleAspectFit
headingImageView.set(.width, to: 150) headingImageView.set(.width, to: 150)
headingImageView.set(.height, to: 18) headingImageView.set(.height, to: Values.mediumFontSize)
navigationItem.titleView = headingImageView navigationItem.titleView = headingImageView
} }

@ -210,17 +210,35 @@ final class ConversationCell : UITableViewCell {
} }
public func configure(messageDate: Date?, snippet: String?, searchText: String) { public func configure(messageDate: Date?, snippet: String?, searchText: String) {
let normalizedSearchText = searchText.lowercased()
if let messageDate = messageDate, let snippet = snippet { if let messageDate = messageDate, let snippet = snippet {
// Message // Message
displayNameLabel.attributedText = NSMutableAttributedString(string: getDisplayName(), attributes: [.foregroundColor:Colors.text]) displayNameLabel.attributedText = NSMutableAttributedString(string: getDisplayName(), attributes: [.foregroundColor:Colors.text])
timestampLabel.isHidden = false timestampLabel.isHidden = false
timestampLabel.text = DateUtil.formatDate(forDisplay: messageDate) timestampLabel.text = DateUtil.formatDate(forDisplay: messageDate)
bottomLabelStackView.isHidden = false bottomLabelStackView.isHidden = false
snippetLabel.attributedText = getHighlightedSnippet(snippet: snippet, searchText: searchText, fontSize: Values.smallFontSize) snippetLabel.attributedText = getHighlightedSnippet(snippet: snippet, searchText: normalizedSearchText, fontSize: Values.smallFontSize)
} else { } else {
// Contact // Contact
displayNameLabel.attributedText = getHighlightedSnippet(snippet: getDisplayName(), searchText: searchText, fontSize: Values.mediumFontSize) displayNameLabel.attributedText = getHighlightedSnippet(snippet: getDisplayName(), searchText: normalizedSearchText, fontSize: Values.mediumFontSize)
bottomLabelStackView.isHidden = true if threadViewModel.isGroupThread, let thread = threadViewModel.threadRecord as? TSGroupThread {
bottomLabelStackView.isHidden = false
let context: Contact.Context = thread.isOpenGroup ? .openGroup : .regular
var rawSnippet: String = ""
thread.groupModel.groupMemberIds.forEach{ id in
if let displayName = Storage.shared.getContact(with: id)?.displayName(for: context) {
if !rawSnippet.isEmpty {
rawSnippet += ", \(displayName)"
}
if displayName.lowercased().contains(normalizedSearchText) {
rawSnippet = displayName
}
}
}
snippetLabel.attributedText = getHighlightedSnippet(snippet: rawSnippet, searchText: normalizedSearchText, fontSize: Values.smallFontSize)
} else {
bottomLabelStackView.isHidden = true
}
timestampLabel.isHidden = true timestampLabel.isHidden = true
} }
} }
@ -232,11 +250,10 @@ final class ConversationCell : UITableViewCell {
let result = NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:Colors.text.withAlphaComponent(Values.lowOpacity)]) let result = NSMutableAttributedString(string: snippet, attributes: [.foregroundColor:Colors.text.withAlphaComponent(Values.lowOpacity)])
let normalizedSnippet = snippet.lowercased() as NSString let normalizedSnippet = snippet.lowercased() as NSString
let normalizedSearchText = searchText.lowercased()
guard normalizedSnippet.contains(normalizedSearchText) else { return result } guard normalizedSnippet.contains(searchText) else { return result }
let range = normalizedSnippet.range(of: normalizedSearchText) let range = normalizedSnippet.range(of: searchText)
result.addAttribute(.foregroundColor, value: Colors.text, range: range) result.addAttribute(.foregroundColor, value: Colors.text, range: range)
result.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: fontSize), range: range) result.addAttribute(.font, value: UIFont.boldSystemFont(ofSize: fontSize), range: range)
return result return result

@ -97,6 +97,7 @@ public class FullTextSearchFinder: NSObject {
let snippetOptions = YapDatabaseFullTextSearchSnippetOptions() let snippetOptions = YapDatabaseFullTextSearchSnippetOptions()
snippetOptions.startMatchText = "" snippetOptions.startMatchText = ""
snippetOptions.endMatchText = "" snippetOptions.endMatchText = ""
snippetOptions.numberOfTokens = 5
ext.enumerateKeysAndObjects(matching: query, with: snippetOptions) { (snippet: String, _: String, _: String, object: Any, stop: UnsafeMutablePointer<ObjCBool>) in ext.enumerateKeysAndObjects(matching: query, with: snippetOptions) { (snippet: String, _: String, _: String, object: Any, stop: UnsafeMutablePointer<ObjCBool>) in
guard searchResultCount < maxSearchResults else { guard searchResultCount < maxSearchResults else {
stop.pointee = true stop.pointee = true

Loading…
Cancel
Save