Skip to content

Commit 773246f

Browse files
committed
Display conversation content for recent chats
1 parent af46a64 commit 773246f

File tree

11 files changed

+200
-149
lines changed

11 files changed

+200
-149
lines changed

Mixin.xcodeproj/project.pbxproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@
596596
7C695D56285B25AB0042177C /* SpotlightManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C695D55285B25AB0042177C /* SpotlightManager.swift */; };
597597
7C6AD1F526A6794F00E6C41D /* StickersStoreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C6AD1F426A6794F00E6C41D /* StickersStoreViewController.swift */; };
598598
7C7635B826A13461006101DB /* HomeAppsConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C7635B726A13461006101DB /* HomeAppsConstants.swift */; };
599+
7C7A865428E6E81600D6A4FA /* ConversationItem+DisplayContent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C7A865328E6E81600D6A4FA /* ConversationItem+DisplayContent.swift */; };
599600
7C8CC5A4280D347A00F7CBDF /* PreviewWallpaperViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8CC5A2280D347A00F7CBDF /* PreviewWallpaperViewController.swift */; };
600601
7C8CC5A7280D40E900F7CBDF /* PreviewWallpaperCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8CC5A6280D40E900F7CBDF /* PreviewWallpaperCell.swift */; };
601602
7C8FA78D27687D1500855AFD /* DeleteAccountSettingViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7C8FA78C27687D1500855AFD /* DeleteAccountSettingViewController.swift */; };
@@ -1600,6 +1601,7 @@
16001601
7C695D55285B25AB0042177C /* SpotlightManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SpotlightManager.swift; sourceTree = "<group>"; };
16011602
7C6AD1F426A6794F00E6C41D /* StickersStoreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StickersStoreViewController.swift; sourceTree = "<group>"; };
16021603
7C7635B726A13461006101DB /* HomeAppsConstants.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeAppsConstants.swift; sourceTree = "<group>"; };
1604+
7C7A865328E6E81600D6A4FA /* ConversationItem+DisplayContent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ConversationItem+DisplayContent.swift"; sourceTree = "<group>"; };
16031605
7C8CC5A2280D347A00F7CBDF /* PreviewWallpaperViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewWallpaperViewController.swift; sourceTree = "<group>"; };
16041606
7C8CC5A6280D40E900F7CBDF /* PreviewWallpaperCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreviewWallpaperCell.swift; sourceTree = "<group>"; };
16051607
7C8FA78C27687D1500855AFD /* DeleteAccountSettingViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteAccountSettingViewController.swift; sourceTree = "<group>"; };
@@ -2114,15 +2116,16 @@
21142116
isa = PBXGroup;
21152117
children = (
21162118
7B04FAB722684242004F8F04 /* AssetSearchResult.swift */,
2117-
7B04FAB922684F51004F8F04 /* SearchResult.swift */,
2118-
7B35AF73228A948A00E8101D /* UserSearchResult.swift */,
2119-
7C4733A028533EB800ECD293 /* PhoneContactSearchResult.swift */,
2119+
7BB0F9502434DDD400BEDA97 /* CircleMemberSearchResult.swift */,
21202120
7B35AF75228A98EF00E8101D /* ConversationSearchResult.swift */,
2121+
7BAB76AB228AAE00009ECB8C /* MessageReceiverSearchResult.swift */,
2122+
7BAB76A9228AABEA009ECB8C /* MessageSearchResult.swift */,
2123+
7B35AF79228AA61400E8101D /* MessagesWithGroupSearchResult.swift */,
21212124
7B35AF7B228AA6CD00E8101D /* MessagesWithinConversationSearchResult.swift */,
21222125
7B35AF77228AA3BD00E8101D /* MessagesWithUserSearchResult.swift */,
2123-
7B35AF79228AA61400E8101D /* MessagesWithGroupSearchResult.swift */,
2124-
7BAB76A9228AABEA009ECB8C /* MessageSearchResult.swift */,
2125-
7BB0F9502434DDD400BEDA97 /* CircleMemberSearchResult.swift */,
2126+
7C4733A028533EB800ECD293 /* PhoneContactSearchResult.swift */,
2127+
7B04FAB922684F51004F8F04 /* SearchResult.swift */,
2128+
7B35AF73228A948A00E8101D /* UserSearchResult.swift */,
21262129
);
21272130
path = "Search Result";
21282131
sourceTree = "<group>";
@@ -2169,7 +2172,6 @@
21692172
7BF196AE24115F9100CC8325 /* LocationMessageViewModel.swift */,
21702173
7BEB97172366CF42002DB190 /* MessageFontSet.swift */,
21712174
7BFE47E622845DE100FC4379 /* MessageReceiver.swift */,
2172-
7BAB76AB228AAE00009ECB8C /* MessageReceiverSearchResult.swift */,
21732175
7B09E5591FD157EB002E45D3 /* MessageViewModel.swift */,
21742176
7B9D825722F1BFEA0099381E /* NetworkOperationIconSet.swift */,
21752177
7B9D825522F1BFE90099381E /* NormalNetworkOperationIconSet.swift */,
@@ -2204,6 +2206,7 @@
22042206
94D63DD52646C29100FD7EE8 /* MessageViewModelFactory.swift */,
22052207
7CC7304F2745F95D002780F5 /* StickerStore.swift */,
22062208
7CF7416D27DAD93000DA0004 /* SnapCenterFlowLayout.swift */,
2209+
7C7A865328E6E81600D6A4FA /* ConversationItem+DisplayContent.swift */,
22072210
);
22082211
path = Model;
22092212
sourceTree = "<group>";
@@ -4779,6 +4782,7 @@
47794782
945278982626BCD600023A6C /* HighlightableButton.swift in Sources */,
47804783
7BEB5D9F22B79F5500B8B10E /* EmergencyContactLoginVerificationCodeViewController.swift in Sources */,
47814784
7B59535122672D3500D59DB4 /* TopResultCell.swift in Sources */,
4785+
7C7A865428E6E81600D6A4FA /* ConversationItem+DisplayContent.swift in Sources */,
47824786
94046B91272DC265007C1D4A /* GroupCallMembersDataSource.swift in Sources */,
47834787
7BEE5353222E21D7008D3911 /* KeyboardHeight.swift in Sources */,
47844788
7B95534322438ECD00CE95E6 /* TopRoundedView.swift in Sources */,

Mixin/Service/Storage/CircleMember+Convenience.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ extension CircleMember {
2525
iconUrl: isGroup ? conversation.iconUrl : conversation.ownerAvatarUrl,
2626
identityNumber: conversation.ownerIdentityNumber,
2727
phoneNumber: nil,
28-
badgeImage: nil)
28+
badgeImage: nil,
29+
conversationContent: conversation.displayContent)
2930
}
3031

3132
}

Mixin/Service/Storage/Search Result/CircleMemberSearchResult.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ class CircleMemberSearchResult: SearchResult {
2020
textAttributes: SearchResult.titleAttributes,
2121
keyword: keyword,
2222
keywordAttributes: SearchResult.highlightedTitleAttributes)
23-
description = SearchResult.description(identityNumber: member.identityNumber,
24-
phoneNumber: member.phoneNumber,
25-
keyword: keyword)
23+
if let content = member.conversationContent {
24+
description = SearchResult.description(conversationContent: content)
25+
} else {
26+
description = SearchResult.description(identityNumber: member.identityNumber,
27+
phoneNumber: member.phoneNumber,
28+
keyword: keyword)
29+
}
2630
}
2731

2832
}

Mixin/Service/Storage/Search Result/ConversationSearchResult.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ConversationSearchResult: SearchResult {
2020
textAttributes: SearchResult.titleAttributes,
2121
keyword: keyword,
2222
keywordAttributes: SearchResult.highlightedTitleAttributes)
23+
description = SearchResult.description(conversationContent: conversation.displayContent)
2324
}
2425

2526
}

Mixin/UserInterface/Controllers/Chat/Model/MessageReceiverSearchResult.swift renamed to Mixin/Service/Storage/Search Result/MessageReceiverSearchResult.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@ class MessageReceiverSearchResult: SearchResult {
2727
textAttributes: SearchResult.titleAttributes,
2828
keyword: keyword,
2929
keywordAttributes: SearchResult.highlightedTitleAttributes)
30-
switch receiver.item {
31-
case .group(_):
32-
description = nil
33-
case let .user(user):
34-
description = SearchResult.description(user: user, keyword: keyword)
30+
if let content = receiver.conversationContent {
31+
description = SearchResult.description(conversationContent: content)
32+
} else if case let .user(user) = receiver.item {
33+
description = SearchResult.description(identityNumber: user.identityNumber, phoneNumber: user.phone, keyword: keyword)
3534
}
3635
}
3736

Mixin/Service/Storage/Search Result/SearchResult.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,33 @@ extension SearchResult {
9595
textAttributes: SearchResult.normalDescriptionAttributes,
9696
keyword: keyword,
9797
keywordAttributes: SearchResult.highlightedNormalDescriptionAttributes)
98+
} else if let identityNumber {
99+
return NSAttributedString(string: identityNumber, attributes: normalDescriptionAttributes)
98100
} else {
99101
return nil
100102
}
101103
}
102104

103-
static func description(user: UserItem, keyword: String) -> NSAttributedString? {
104-
description(identityNumber: user.identityNumber, phoneNumber: user.phone, keyword: keyword)
105+
static func description(conversationContent: String?) -> NSAttributedString? {
106+
guard let conversationContent, !conversationContent.isEmpty else {
107+
return nil
108+
}
109+
return NSAttributedString(string: conversationContent, attributes: normalDescriptionAttributes)
105110
}
106111

112+
static func description(conversationContent: String? = nil, user: UserItem, keyword: String) -> NSAttributedString? {
113+
if let conversationContent, !conversationContent.isEmpty {
114+
if conversationContent.contains(keyword) {
115+
return SearchResult.attributedText(text: conversationContent,
116+
textAttributes: SearchResult.normalDescriptionAttributes,
117+
keyword: keyword,
118+
keywordAttributes: SearchResult.highlightedNormalDescriptionAttributes)
119+
} else {
120+
return NSAttributedString(string: conversationContent, attributes: normalDescriptionAttributes)
121+
}
122+
} else {
123+
return SearchResult.description(identityNumber: user.identityNumber, phoneNumber: user.phone, keyword: keyword)
124+
}
125+
}
126+
107127
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import Foundation
2+
import MixinServices
3+
4+
extension ConversationItem {
5+
6+
var displayContent: String {
7+
if messageStatus == MessageStatus.FAILED.rawValue {
8+
return R.string.localizable.chat_decryption_failed_hint(senderFullName)
9+
} else if messageStatus == MessageStatus.UNKNOWN.rawValue {
10+
return R.string.localizable.message_not_support()
11+
} else {
12+
let senderIsMe = senderId == myUserId
13+
let senderName = senderIsMe ? R.string.localizable.you() : senderFullName
14+
let category = contentType
15+
if category.hasSuffix("_TEXT") {
16+
if isGroup() {
17+
return "\(senderName): \(mentionedFullnameReplacedContent)"
18+
} else {
19+
return mentionedFullnameReplacedContent
20+
}
21+
} else if category.hasSuffix("_IMAGE") {
22+
if isGroup() {
23+
return "\(senderName): \(R.string.localizable.content_photo())"
24+
} else {
25+
return R.string.localizable.content_photo()
26+
}
27+
} else if category.hasSuffix("_STICKER") {
28+
if isGroup() {
29+
return "\(senderName): \(R.string.localizable.content_sticker())"
30+
} else {
31+
return R.string.localizable.content_sticker()
32+
}
33+
} else if category.hasSuffix("_CONTACT") {
34+
if isGroup() {
35+
return "\(senderName): \(R.string.localizable.content_contact())"
36+
} else {
37+
return R.string.localizable.content_contact()
38+
}
39+
} else if category.hasSuffix("_DATA") {
40+
if isGroup() {
41+
return "\(senderName): \(R.string.localizable.content_file())"
42+
} else {
43+
return R.string.localizable.content_file()
44+
}
45+
} else if category.hasSuffix("_VIDEO") {
46+
if isGroup() {
47+
return "\(senderName): \(R.string.localizable.content_video())"
48+
} else {
49+
return R.string.localizable.content_video()
50+
}
51+
} else if category.hasSuffix("_LIVE") {
52+
if isGroup() {
53+
return "\(senderName): \(R.string.localizable.content_live())"
54+
} else {
55+
return R.string.localizable.content_live()
56+
}
57+
} else if category.hasSuffix("_AUDIO") {
58+
if isGroup() {
59+
return "\(senderName): \(R.string.localizable.content_audio())"
60+
} else {
61+
return R.string.localizable.content_audio()
62+
}
63+
} else if category.hasSuffix("_POST") {
64+
if isGroup() {
65+
return "\(senderName): \(markdownControlCodeRemovedContent)"
66+
} else {
67+
return markdownControlCodeRemovedContent
68+
}
69+
} else if category.hasSuffix("_LOCATION") {
70+
if isGroup() {
71+
return "\(senderName): \(R.string.localizable.content_location())"
72+
} else {
73+
return R.string.localizable.content_location()
74+
}
75+
} else if category.hasPrefix("WEBRTC_") {
76+
return R.string.localizable.content_voice()
77+
} else if category == MessageCategory.SYSTEM_ACCOUNT_SNAPSHOT.rawValue {
78+
return R.string.localizable.content_transfer()
79+
} else if category == MessageCategory.APP_BUTTON_GROUP.rawValue {
80+
return (appButtons?.map({ (appButton) -> String in
81+
return "[\(appButton.label)]"
82+
}) ?? []).joined()
83+
} else if category == MessageCategory.APP_CARD.rawValue, let appCard = appCard {
84+
return "[\(appCard.title)]"
85+
} else if category == MessageCategory.MESSAGE_RECALL.rawValue {
86+
if senderIsMe {
87+
return R.string.localizable.you_deleted_this_message()
88+
} else {
89+
return R.string.localizable.this_message_was_deleted()
90+
}
91+
} else if category == MessageCategory.MESSAGE_PIN.rawValue {
92+
return TransferPinAction.pinMessage(item: self)
93+
} else if category == MessageCategory.KRAKEN_PUBLISH.rawValue {
94+
return R.string.localizable.started_group_call(senderName)
95+
} else if category == MessageCategory.KRAKEN_CANCEL.rawValue {
96+
return R.string.localizable.chat_group_call_cancel(senderName)
97+
} else if category == MessageCategory.KRAKEN_DECLINE.rawValue {
98+
return R.string.localizable.chat_group_call_decline(senderName)
99+
} else if category == MessageCategory.KRAKEN_INVITE.rawValue {
100+
return R.string.localizable.chat_group_call_invite(senderName)
101+
} else if category == MessageCategory.KRAKEN_END.rawValue {
102+
return R.string.localizable.content_group_call_ended()
103+
} else if category.hasSuffix("_TRANSCRIPT") {
104+
return R.string.localizable.content_transcript()
105+
} else {
106+
if contentType.hasPrefix("SYSTEM_") {
107+
return SystemConversationAction.getSystemMessage(actionName: actionName,
108+
userId: senderId,
109+
userFullName: senderFullName,
110+
participantId: participantUserId,
111+
participantFullName: participantFullName,
112+
content: content)
113+
} else if messageId.isEmpty {
114+
return ""
115+
} else {
116+
return R.string.localizable.message_not_support()
117+
}
118+
}
119+
}
120+
}
121+
122+
}

Mixin/UserInterface/Controllers/Chat/Model/MessageReceiver.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class MessageReceiver {
1212
let name: String
1313
let badgeImage: UIImage?
1414
let item: Item
15+
let conversationContent: String?
1516

1617
init?(conversation: ConversationItem) {
1718
if conversation.category == ConversationCategory.CONTACT.rawValue {
@@ -30,13 +31,15 @@ class MessageReceiver {
3031
return nil
3132
}
3233
conversationId = conversation.conversationId
34+
conversationContent = conversation.displayContent
3335
}
3436

3537
init(user: UserItem) {
3638
name = user.fullName
3739
badgeImage = SearchResult.userBadgeImage(isVerified: user.isVerified, appId: user.appId)
3840
item = .user(user)
3941
conversationId = ConversationDAO.shared.makeConversationId(userId: user.userId, ownerUserId: myUserId)
42+
conversationContent = nil
4043
}
4144

4245
func matches(lowercasedKeyword keyword: String) -> Bool {

0 commit comments

Comments
 (0)