Skip to content

Commit

Permalink
Display conversation content for recent chats
Browse files Browse the repository at this point in the history
  • Loading branch information
fanyu committed Oct 8, 2022
1 parent af46a64 commit 773246f
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 149 deletions.
18 changes: 11 additions & 7 deletions Mixin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@
7C695D56285B25AB0042177C /* SpotlightManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C695D55285B25AB0042177C /* SpotlightManager.swift */; };
7C6AD1F526A6794F00E6C41D /* StickersStoreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C6AD1F426A6794F00E6C41D /* StickersStoreViewController.swift */; };
7C7635B826A13461006101DB /* HomeAppsConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C7635B726A13461006101DB /* HomeAppsConstants.swift */; };
7C7A865428E6E81600D6A4FA /* ConversationItem+DisplayContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C7A865328E6E81600D6A4FA /* ConversationItem+DisplayContent.swift */; };
7C8CC5A4280D347A00F7CBDF /* PreviewWallpaperViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8CC5A2280D347A00F7CBDF /* PreviewWallpaperViewController.swift */; };
7C8CC5A7280D40E900F7CBDF /* PreviewWallpaperCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8CC5A6280D40E900F7CBDF /* PreviewWallpaperCell.swift */; };
7C8FA78D27687D1500855AFD /* DeleteAccountSettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FA78C27687D1500855AFD /* DeleteAccountSettingViewController.swift */; };
Expand Down Expand Up @@ -1600,6 +1601,7 @@
7C695D55285B25AB0042177C /* SpotlightManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotlightManager.swift; sourceTree = "<group>"; };
7C6AD1F426A6794F00E6C41D /* StickersStoreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickersStoreViewController.swift; sourceTree = "<group>"; };
7C7635B726A13461006101DB /* HomeAppsConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeAppsConstants.swift; sourceTree = "<group>"; };
7C7A865328E6E81600D6A4FA /* ConversationItem+DisplayContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ConversationItem+DisplayContent.swift"; sourceTree = "<group>"; };
7C8CC5A2280D347A00F7CBDF /* PreviewWallpaperViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewWallpaperViewController.swift; sourceTree = "<group>"; };
7C8CC5A6280D40E900F7CBDF /* PreviewWallpaperCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewWallpaperCell.swift; sourceTree = "<group>"; };
7C8FA78C27687D1500855AFD /* DeleteAccountSettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountSettingViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2114,15 +2116,16 @@
isa = PBXGroup;
children = (
7B04FAB722684242004F8F04 /* AssetSearchResult.swift */,
7B04FAB922684F51004F8F04 /* SearchResult.swift */,
7B35AF73228A948A00E8101D /* UserSearchResult.swift */,
7C4733A028533EB800ECD293 /* PhoneContactSearchResult.swift */,
7BB0F9502434DDD400BEDA97 /* CircleMemberSearchResult.swift */,
7B35AF75228A98EF00E8101D /* ConversationSearchResult.swift */,
7BAB76AB228AAE00009ECB8C /* MessageReceiverSearchResult.swift */,
7BAB76A9228AABEA009ECB8C /* MessageSearchResult.swift */,
7B35AF79228AA61400E8101D /* MessagesWithGroupSearchResult.swift */,
7B35AF7B228AA6CD00E8101D /* MessagesWithinConversationSearchResult.swift */,
7B35AF77228AA3BD00E8101D /* MessagesWithUserSearchResult.swift */,
7B35AF79228AA61400E8101D /* MessagesWithGroupSearchResult.swift */,
7BAB76A9228AABEA009ECB8C /* MessageSearchResult.swift */,
7BB0F9502434DDD400BEDA97 /* CircleMemberSearchResult.swift */,
7C4733A028533EB800ECD293 /* PhoneContactSearchResult.swift */,
7B04FAB922684F51004F8F04 /* SearchResult.swift */,
7B35AF73228A948A00E8101D /* UserSearchResult.swift */,
);
path = "Search Result";
sourceTree = "<group>";
Expand Down Expand Up @@ -2169,7 +2172,6 @@
7BF196AE24115F9100CC8325 /* LocationMessageViewModel.swift */,
7BEB97172366CF42002DB190 /* MessageFontSet.swift */,
7BFE47E622845DE100FC4379 /* MessageReceiver.swift */,
7BAB76AB228AAE00009ECB8C /* MessageReceiverSearchResult.swift */,
7B09E5591FD157EB002E45D3 /* MessageViewModel.swift */,
7B9D825722F1BFEA0099381E /* NetworkOperationIconSet.swift */,
7B9D825522F1BFE90099381E /* NormalNetworkOperationIconSet.swift */,
Expand Down Expand Up @@ -2204,6 +2206,7 @@
94D63DD52646C29100FD7EE8 /* MessageViewModelFactory.swift */,
7CC7304F2745F95D002780F5 /* StickerStore.swift */,
7CF7416D27DAD93000DA0004 /* SnapCenterFlowLayout.swift */,
7C7A865328E6E81600D6A4FA /* ConversationItem+DisplayContent.swift */,
);
path = Model;
sourceTree = "<group>";
Expand Down Expand Up @@ -4779,6 +4782,7 @@
945278982626BCD600023A6C /* HighlightableButton.swift in Sources */,
7BEB5D9F22B79F5500B8B10E /* EmergencyContactLoginVerificationCodeViewController.swift in Sources */,
7B59535122672D3500D59DB4 /* TopResultCell.swift in Sources */,
7C7A865428E6E81600D6A4FA /* ConversationItem+DisplayContent.swift in Sources */,
94046B91272DC265007C1D4A /* GroupCallMembersDataSource.swift in Sources */,
7BEE5353222E21D7008D3911 /* KeyboardHeight.swift in Sources */,
7B95534322438ECD00CE95E6 /* TopRoundedView.swift in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Mixin/Service/Storage/CircleMember+Convenience.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ extension CircleMember {
iconUrl: isGroup ? conversation.iconUrl : conversation.ownerAvatarUrl,
identityNumber: conversation.ownerIdentityNumber,
phoneNumber: nil,
badgeImage: nil)
badgeImage: nil,
conversationContent: conversation.displayContent)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ class CircleMemberSearchResult: SearchResult {
textAttributes: SearchResult.titleAttributes,
keyword: keyword,
keywordAttributes: SearchResult.highlightedTitleAttributes)
description = SearchResult.description(identityNumber: member.identityNumber,
phoneNumber: member.phoneNumber,
keyword: keyword)
if let content = member.conversationContent {
description = SearchResult.description(conversationContent: content)
} else {
description = SearchResult.description(identityNumber: member.identityNumber,
phoneNumber: member.phoneNumber,
keyword: keyword)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ConversationSearchResult: SearchResult {
textAttributes: SearchResult.titleAttributes,
keyword: keyword,
keywordAttributes: SearchResult.highlightedTitleAttributes)
description = SearchResult.description(conversationContent: conversation.displayContent)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ class MessageReceiverSearchResult: SearchResult {
textAttributes: SearchResult.titleAttributes,
keyword: keyword,
keywordAttributes: SearchResult.highlightedTitleAttributes)
switch receiver.item {
case .group(_):
description = nil
case let .user(user):
description = SearchResult.description(user: user, keyword: keyword)
if let content = receiver.conversationContent {
description = SearchResult.description(conversationContent: content)
} else if case let .user(user) = receiver.item {
description = SearchResult.description(identityNumber: user.identityNumber, phoneNumber: user.phone, keyword: keyword)
}
}

Expand Down
24 changes: 22 additions & 2 deletions Mixin/Service/Storage/Search Result/SearchResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,33 @@ extension SearchResult {
textAttributes: SearchResult.normalDescriptionAttributes,
keyword: keyword,
keywordAttributes: SearchResult.highlightedNormalDescriptionAttributes)
} else if let identityNumber {
return NSAttributedString(string: identityNumber, attributes: normalDescriptionAttributes)
} else {
return nil
}
}

static func description(user: UserItem, keyword: String) -> NSAttributedString? {
description(identityNumber: user.identityNumber, phoneNumber: user.phone, keyword: keyword)
static func description(conversationContent: String?) -> NSAttributedString? {
guard let conversationContent, !conversationContent.isEmpty else {
return nil
}
return NSAttributedString(string: conversationContent, attributes: normalDescriptionAttributes)
}

static func description(conversationContent: String? = nil, user: UserItem, keyword: String) -> NSAttributedString? {
if let conversationContent, !conversationContent.isEmpty {
if conversationContent.contains(keyword) {
return SearchResult.attributedText(text: conversationContent,
textAttributes: SearchResult.normalDescriptionAttributes,
keyword: keyword,
keywordAttributes: SearchResult.highlightedNormalDescriptionAttributes)
} else {
return NSAttributedString(string: conversationContent, attributes: normalDescriptionAttributes)
}
} else {
return SearchResult.description(identityNumber: user.identityNumber, phoneNumber: user.phone, keyword: keyword)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import Foundation
import MixinServices

extension ConversationItem {

var displayContent: String {
if messageStatus == MessageStatus.FAILED.rawValue {
return R.string.localizable.chat_decryption_failed_hint(senderFullName)
} else if messageStatus == MessageStatus.UNKNOWN.rawValue {
return R.string.localizable.message_not_support()
} else {
let senderIsMe = senderId == myUserId
let senderName = senderIsMe ? R.string.localizable.you() : senderFullName
let category = contentType
if category.hasSuffix("_TEXT") {
if isGroup() {
return "\(senderName): \(mentionedFullnameReplacedContent)"
} else {
return mentionedFullnameReplacedContent
}
} else if category.hasSuffix("_IMAGE") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_photo())"
} else {
return R.string.localizable.content_photo()
}
} else if category.hasSuffix("_STICKER") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_sticker())"
} else {
return R.string.localizable.content_sticker()
}
} else if category.hasSuffix("_CONTACT") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_contact())"
} else {
return R.string.localizable.content_contact()
}
} else if category.hasSuffix("_DATA") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_file())"
} else {
return R.string.localizable.content_file()
}
} else if category.hasSuffix("_VIDEO") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_video())"
} else {
return R.string.localizable.content_video()
}
} else if category.hasSuffix("_LIVE") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_live())"
} else {
return R.string.localizable.content_live()
}
} else if category.hasSuffix("_AUDIO") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_audio())"
} else {
return R.string.localizable.content_audio()
}
} else if category.hasSuffix("_POST") {
if isGroup() {
return "\(senderName): \(markdownControlCodeRemovedContent)"
} else {
return markdownControlCodeRemovedContent
}
} else if category.hasSuffix("_LOCATION") {
if isGroup() {
return "\(senderName): \(R.string.localizable.content_location())"
} else {
return R.string.localizable.content_location()
}
} else if category.hasPrefix("WEBRTC_") {
return R.string.localizable.content_voice()
} else if category == MessageCategory.SYSTEM_ACCOUNT_SNAPSHOT.rawValue {
return R.string.localizable.content_transfer()
} else if category == MessageCategory.APP_BUTTON_GROUP.rawValue {
return (appButtons?.map({ (appButton) -> String in
return "[\(appButton.label)]"
}) ?? []).joined()
} else if category == MessageCategory.APP_CARD.rawValue, let appCard = appCard {
return "[\(appCard.title)]"
} else if category == MessageCategory.MESSAGE_RECALL.rawValue {
if senderIsMe {
return R.string.localizable.you_deleted_this_message()
} else {
return R.string.localizable.this_message_was_deleted()
}
} else if category == MessageCategory.MESSAGE_PIN.rawValue {
return TransferPinAction.pinMessage(item: self)
} else if category == MessageCategory.KRAKEN_PUBLISH.rawValue {
return R.string.localizable.started_group_call(senderName)
} else if category == MessageCategory.KRAKEN_CANCEL.rawValue {
return R.string.localizable.chat_group_call_cancel(senderName)
} else if category == MessageCategory.KRAKEN_DECLINE.rawValue {
return R.string.localizable.chat_group_call_decline(senderName)
} else if category == MessageCategory.KRAKEN_INVITE.rawValue {
return R.string.localizable.chat_group_call_invite(senderName)
} else if category == MessageCategory.KRAKEN_END.rawValue {
return R.string.localizable.content_group_call_ended()
} else if category.hasSuffix("_TRANSCRIPT") {
return R.string.localizable.content_transcript()
} else {
if contentType.hasPrefix("SYSTEM_") {
return SystemConversationAction.getSystemMessage(actionName: actionName,
userId: senderId,
userFullName: senderFullName,
participantId: participantUserId,
participantFullName: participantFullName,
content: content)
} else if messageId.isEmpty {
return ""
} else {
return R.string.localizable.message_not_support()
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class MessageReceiver {
let name: String
let badgeImage: UIImage?
let item: Item
let conversationContent: String?

init?(conversation: ConversationItem) {
if conversation.category == ConversationCategory.CONTACT.rawValue {
Expand All @@ -30,13 +31,15 @@ class MessageReceiver {
return nil
}
conversationId = conversation.conversationId
conversationContent = conversation.displayContent
}

init(user: UserItem) {
name = user.fullName
badgeImage = SearchResult.userBadgeImage(isVerified: user.isVerified, appId: user.appId)
item = .user(user)
conversationId = ConversationDAO.shared.makeConversationId(userId: user.userId, ownerUserId: myUserId)
conversationContent = nil
}

func matches(lowercasedKeyword keyword: String) -> Bool {
Expand Down
Loading

0 comments on commit 773246f

Please sign in to comment.