add author for group messages

pull/555/head
Ryan Zhao 3 years ago
parent 18fea4ab73
commit 124d908686

@ -363,7 +363,9 @@ extension GlobalSearchViewController {
cell.isShowingGlobalSearchResult = true cell.isShowingGlobalSearchResult = true
let searchResult = sectionResults[safe: indexPath.row] let searchResult = sectionResults[safe: indexPath.row]
cell.threadViewModel = searchResult?.thread cell.threadViewModel = searchResult?.thread
cell.configure(messageDate: searchResult?.messageDate, snippet: searchResult?.snippet, searchText: searchResultSet.searchText) var message: TSMessage? = nil
if let messageId = searchResult?.messageId { message = TSMessage.fetch(uniqueId: messageId) }
cell.configure(messageDate: searchResult?.messageDate, snippet: searchResult?.snippet, searchText: searchResultSet.searchText, message: message)
return cell return cell
case .recent: case .recent:
let cell = tableView.dequeueReusableCell(withIdentifier: ConversationCell.reuseIdentifier) as! ConversationCell let cell = tableView.dequeueReusableCell(withIdentifier: ConversationCell.reuseIdentifier) as! ConversationCell

@ -217,7 +217,7 @@ final class ConversationCell : UITableViewCell {
timestampLabel.isHidden = true timestampLabel.isHidden = true
} }
public func configure(messageDate: Date?, snippet: String?, searchText: String) { public func configure(messageDate: Date?, snippet: String?, searchText: String, message: TSMessage? = nil) {
let normalizedSearchText = searchText.lowercased() let normalizedSearchText = searchText.lowercased()
if let messageDate = messageDate, let snippet = snippet { if let messageDate = messageDate, let snippet = snippet {
// Message // Message
@ -225,7 +225,11 @@ final class ConversationCell : UITableViewCell {
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: normalizedSearchText, fontSize: Values.smallFontSize) var rawSnippet = snippet
if let message = message, let name = getMessageAuthorName(message: message) {
rawSnippet = "\(name): \(snippet)"
}
snippetLabel.attributedText = getHighlightedSnippet(snippet: rawSnippet, searchText: normalizedSearchText, fontSize: Values.smallFontSize)
} else { } else {
// Contact // Contact
if threadViewModel.isGroupThread, let thread = threadViewModel.threadRecord as? TSGroupThread { if threadViewModel.isGroupThread, let thread = threadViewModel.threadRecord as? TSGroupThread {
@ -325,6 +329,14 @@ final class ConversationCell : UITableViewCell {
} }
} }
private func getMessageAuthorName(message: TSMessage) -> String? {
guard threadViewModel.isGroupThread else { return nil }
if let incomingMessage = message as? TSIncomingMessage {
return Storage.shared.getContact(with: incomingMessage.authorId)?.displayName(for: .regular) ?? "Anonymous"
}
return nil
}
private func getDisplayNameForSearch(_ sessionID: String) -> String { private func getDisplayNameForSearch(_ sessionID: String) -> String {
if threadViewModel.threadRecord.isNoteToSelf() { if threadViewModel.threadRecord.isNoteToSelf() {
return NSLocalizedString("NOTE_TO_SELF", comment: "") return NSLocalizedString("NOTE_TO_SELF", comment: "")
@ -367,9 +379,12 @@ final class ConversationCell : UITableViewCell {
result.append(imageString) result.append(imageString)
result.append(NSAttributedString(string: " ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ])) result.append(NSAttributedString(string: " ", attributes: [ .font : UIFont.ows_elegantIconsFont(10), .foregroundColor : Colors.unimportant ]))
} }
let font = threadViewModel.hasUnreadMessages ? UIFont.boldSystemFont(ofSize: Values.smallFontSize) : UIFont.systemFont(ofSize: Values.smallFontSize)
if threadViewModel.isGroupThread, let message = threadViewModel.lastMessageForInbox as? TSMessage, let name = getMessageAuthorName(message: message) {
result.append(NSAttributedString(string: "\(name): ", attributes: [ .font : font, .foregroundColor : Colors.text ]))
}
if let rawSnippet = threadViewModel.lastMessageText { if let rawSnippet = threadViewModel.lastMessageText {
let snippet = MentionUtilities.highlightMentions(in: rawSnippet, threadID: threadViewModel.threadRecord.uniqueId!) let snippet = MentionUtilities.highlightMentions(in: rawSnippet, threadID: threadViewModel.threadRecord.uniqueId!)
let font = threadViewModel.hasUnreadMessages ? UIFont.boldSystemFont(ofSize: Values.smallFontSize) : UIFont.systemFont(ofSize: Values.smallFontSize)
result.append(NSAttributedString(string: snippet, attributes: [ .font : font, .foregroundColor : Colors.text ])) result.append(NSAttributedString(string: snippet, attributes: [ .font : font, .foregroundColor : Colors.text ]))
} }
return result return result

Loading…
Cancel
Save