Skip to content

Commit 2797e9f

Browse files
authored
Swiftify infoMessagePreviewText(…)
1 parent 743512e commit 2797e9f

10 files changed

+133
-145
lines changed

SignalServiceKit/Messages/Interactions/PinnedMessages/TSInfoMessage+PinnedMessage.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ extension TSInfoMessage {
8888
return message.uniqueId
8989
}
9090

91-
@objc
9291
func pinnedMessageDescription(transaction: DBReadTransaction) -> String? {
9392
guard let pinnedMessageItem: PersistablePinnedMessageItem = infoMessageValue(forKey: .pinnedMessage) else {
9493
return nil

SignalServiceKit/Messages/Interactions/Polls/TSInfoMessage+Polls.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ extension TSInfoMessage {
7272
}
7373
}
7474

75-
@objc
7675
func endPollDescription(transaction: DBReadTransaction) -> String? {
7776
guard let endPollItem: PersistableEndPollItem = infoMessageValue(forKey: .endPoll) else {
7877
return nil

SignalServiceKit/Messages/Interactions/TSInfoMessage+GroupUpdates.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ public extension TSInfoMessage {
9999

100100
// MARK: -
101101

102-
@objc
103-
func groupUpdateDescription(transaction tx: DBReadTransaction) -> NSAttributedString {
102+
func groupUpdateDescription(tx: DBReadTransaction) -> NSAttributedString {
104103
let fallback = DisplayableGroupUpdateItem.genericUpdateByUnknownUser.localizedText
105104

106105
guard

SignalServiceKit/Messages/Interactions/TSInfoMessage+LearnedProfileName.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public extension TSInfoMessage {
6565
return nil
6666
}
6767

68-
@objc
6968
func learnedProfileNameDescription(tx: DBReadTransaction) -> String {
7069
guard let displayNameBeforeLearningProfileName else {
7170
return ""

SignalServiceKit/Messages/Interactions/TSInfoMessage+Payments.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,7 @@ extension TSInfoMessage {
143143
}
144144
}
145145

146-
@objc
147-
func paymentsActivationRequestDescription(transaction: DBReadTransaction) -> String? {
146+
func paymentsActivationRequestDescription(tx transaction: DBReadTransaction) -> String? {
148147
let aci: Aci
149148
let formatString: String
150149
switch paymentsActivationRequestType(transaction: transaction) {
@@ -168,8 +167,7 @@ extension TSInfoMessage {
168167
return String(format: formatString, displayName.resolvedValue())
169168
}
170169

171-
@objc
172-
func paymentsActivatedDescription(transaction: DBReadTransaction) -> String? {
170+
func paymentsActivatedDescription(tx transaction: DBReadTransaction) -> String? {
173171
switch paymentsActivatedType(transaction: transaction) {
174172
case .none:
175173
return nil

SignalServiceKit/Messages/Interactions/TSInfoMessage+ProfileChanges.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ public extension TSInfoMessage {
7070
// MARK: -
7171

7272
public extension TSInfoMessage {
73-
@objc
74-
func profileChangeDescription(transaction tx: DBReadTransaction) -> String {
73+
func profileChangeDescription(tx: DBReadTransaction) -> String {
7574
guard
7675
let profileChanges,
7776
let updateDescription = profileChanges.descriptionForUpdate(tx: tx)

SignalServiceKit/Messages/Interactions/TSInfoMessage+SessionSwitchover.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public extension TSInfoMessage {
2929
return infoMessageValue(forKey: .sessionSwitchoverPhoneNumber)
3030
}
3131

32-
@objc
3332
func sessionSwitchoverDescription(tx: DBReadTransaction) -> String {
3433
if let phoneNumber = sessionSwitchoverPhoneNumber {
3534
let displayName = contactThreadDisplayName(tx: tx)

SignalServiceKit/Messages/Interactions/TSInfoMessage+ThreadMerge.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public extension TSInfoMessage {
3131
return infoMessageValue(forKey: .threadMergePhoneNumber)
3232
}
3333

34-
@objc
3534
func threadMergeDescription(tx: DBReadTransaction) -> String {
3635
let displayName = contactThreadDisplayName(tx: tx)
3736
if let phoneNumber = threadMergePhoneNumber {

SignalServiceKit/Messages/Interactions/TSInfoMessage.m

Lines changed: 1 addition & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -259,132 +259,7 @@ - (NSString *)conversationSystemMessageComponentTextWithTransaction:(DBReadTrans
259259

260260
- (NSString *)infoMessagePreviewTextWithTransaction:(DBReadTransaction *)transaction
261261
{
262-
switch (_messageType) {
263-
case TSInfoMessageTypeLocalUserEndedSession:
264-
case TSInfoMessageTypeRemoteUserEndedSession:
265-
return OWSLocalizedString(@"SECURE_SESSION_RESET", nil);
266-
case TSInfoMessageTypeUnsupportedMessage:
267-
return OWSLocalizedString(@"UNSUPPORTED_ATTACHMENT", nil);
268-
case TSInfoMessageUserNotRegistered:
269-
if (self.unregisteredAddress.isValid) {
270-
NSString *recipientName =
271-
[SSKEnvironment.shared.contactManagerObjcRef displayNameStringForAddress:self.unregisteredAddress
272-
transaction:transaction];
273-
return [NSString stringWithFormat:OWSLocalizedString(@"ERROR_UNREGISTERED_USER_FORMAT",
274-
@"Format string for 'unregistered user' error. Embeds {{the "
275-
@"unregistered user's name or signal id}}."),
276-
recipientName];
277-
} else {
278-
return OWSLocalizedString(@"CONTACT_DETAIL_COMM_TYPE_INSECURE", nil);
279-
}
280-
case TSInfoMessageTypeGroupQuit:
281-
return OWSLocalizedString(@"GROUP_YOU_LEFT", nil);
282-
case TSInfoMessageTypeGroupUpdate:
283-
return [self groupUpdateDescriptionWithTransaction:transaction].string;
284-
case TSInfoMessageAddToContactsOffer:
285-
return OWSLocalizedString(@"ADD_TO_CONTACTS_OFFER",
286-
@"Message shown in conversation view that offers to add an unknown user to your phone's contacts.");
287-
case TSInfoMessageVerificationStateChange:
288-
return OWSLocalizedString(@"VERIFICATION_STATE_CHANGE_GENERIC",
289-
@"Generic message indicating that verification state changed for a given user.");
290-
case TSInfoMessageAddUserToProfileWhitelistOffer:
291-
return OWSLocalizedString(@"ADD_USER_TO_PROFILE_WHITELIST_OFFER",
292-
@"Message shown in conversation view that offers to share your profile with a user.");
293-
case TSInfoMessageAddGroupToProfileWhitelistOffer:
294-
return OWSLocalizedString(@"ADD_GROUP_TO_PROFILE_WHITELIST_OFFER",
295-
@"Message shown in conversation view that offers to share your profile with a group.");
296-
case TSInfoMessageTypeDisappearingMessagesUpdate:
297-
break;
298-
case TSInfoMessageUnknownProtocolVersion:
299-
break;
300-
case TSInfoMessageUserJoinedSignal: {
301-
SignalServiceAddress *address = [TSContactThread contactAddressFromThreadId:self.uniqueThreadId
302-
transaction:transaction];
303-
NSString *recipientName =
304-
[SSKEnvironment.shared.contactManagerObjcRef displayNameStringForAddress:address
305-
transaction:transaction];
306-
NSString *format = OWSLocalizedString(@"INFO_MESSAGE_USER_JOINED_SIGNAL_BODY_FORMAT",
307-
@"Shown in inbox and conversation when a user joins Signal, embeds the new user's {{contact "
308-
@"name}}");
309-
#pragma clang diagnostic push
310-
#pragma clang diagnostic ignored "-Wformat-nonliteral"
311-
return [NSString stringWithFormat:format, recipientName];
312-
#pragma clang diagnostic pop
313-
}
314-
case TSInfoMessageSyncedThread:
315-
return @"";
316-
case TSInfoMessageProfileUpdate:
317-
return [self profileChangeDescriptionWithTransaction:transaction];
318-
case TSInfoMessagePhoneNumberChange: {
319-
AciObjC *_Nullable aci = [self phoneNumberChangeInfoAci];
320-
if (aci == nil) {
321-
OWSFailDebug(@"Invalid info message");
322-
return @"";
323-
}
324-
SignalServiceAddress *address = [[SignalServiceAddress alloc] initWithServiceIdObjC:aci];
325-
NSString *userName = [SSKEnvironment.shared.contactManagerObjcRef displayNameStringForAddress:address
326-
transaction:transaction];
327-
328-
NSString *format = OWSLocalizedString(@"INFO_MESSAGE_USER_CHANGED_PHONE_NUMBER_FORMAT",
329-
@"Indicates that another user has changed their phone number. Embeds: {{ the user's name}}".);
330-
#pragma clang diagnostic push
331-
#pragma clang diagnostic ignored "-Wformat-nonliteral"
332-
return [NSString stringWithFormat:format, userName];
333-
#pragma clang diagnostic pop
334-
}
335-
case TSInfoMessageRecipientHidden: {
336-
/// This does not control whether to show the info message in the chat
337-
/// preview. To control that, see ``TSInteraction.shouldAppearInInbox``.
338-
SignalServiceAddress *address = [TSContactThread contactAddressFromThreadId:self.uniqueThreadId
339-
transaction:transaction];
340-
if ([RecipientHidingManagerObjcBridge isHiddenAddress:address tx:transaction]) {
341-
return OWSLocalizedString(@"INFO_MESSAGE_CONTACT_REMOVED",
342-
@"Indicates that the recipient has been removed from the current user's contacts and that "
343-
@"messaging them will re-add them.");
344-
} else {
345-
return OWSLocalizedString(@"INFO_MESSAGE_CONTACT_REINSTATED",
346-
@"Indicates that a previously-removed recipient has been added back to the current user's "
347-
@"contacts.");
348-
}
349-
}
350-
case TSInfoMessagePaymentsActivationRequest:
351-
return [self paymentsActivationRequestDescriptionWithTransaction:transaction];
352-
case TSInfoMessagePaymentsActivated:
353-
return [self paymentsActivatedDescriptionWithTransaction:transaction];
354-
case TSInfoMessageThreadMerge:
355-
return [self threadMergeDescriptionWithTx:transaction];
356-
case TSInfoMessageSessionSwitchover:
357-
return [self sessionSwitchoverDescriptionWithTx:transaction];
358-
case TSInfoMessageReportedSpam:
359-
return OWSLocalizedString(
360-
@"INFO_MESSAGE_REPORTED_SPAM", @"Shown when a user reports a conversation as spam.");
361-
case TSInfoMessageLearnedProfileName:
362-
return [self learnedProfileNameDescriptionWithTx:transaction];
363-
case TSInfoMessageBlockedOtherUser:
364-
return OWSLocalizedString(@"INFO_MESSAGE_BLOCKED_OTHER_USER",
365-
@"An info message inserted into a 1:1 chat when you block another user.");
366-
case TSInfoMessageBlockedGroup:
367-
return OWSLocalizedString(
368-
@"INFO_MESSAGE_BLOCKED_GROUP", @"An info message inserted into a group chat when you block the group.");
369-
case TSInfoMessageUnblockedOtherUser:
370-
return OWSLocalizedString(@"INFO_MESSAGE_UNBLOCKED_OTHER_USER",
371-
@"An info message inserted into a 1:1 chat when you unblock another user.");
372-
case TSInfoMessageUnblockedGroup:
373-
return OWSLocalizedString(@"INFO_MESSAGE_UNBLOCKED_GROUP",
374-
@"An info message inserted into a group chat when you unblock the group.");
375-
case TSInfoMessageAcceptedMessageRequest:
376-
return OWSLocalizedString(@"INFO_MESSAGE_ACCEPTED_MESSAGE_REQUEST",
377-
@"An info message inserted into the chat when you accept a message request, in a 1:1 or group "
378-
@"chat.");
379-
case TSInfoMessageTypeEndPoll: {
380-
return [self endPollDescriptionWithTransaction:transaction];
381-
}
382-
case TSInfoMessageTypePinnedMessage:
383-
return [self pinnedMessageDescriptionWithTransaction:transaction];
384-
}
385-
386-
OWSFailDebug(@"Unknown info message type");
387-
return @"";
262+
return [self _infoMessagePreviewTextWithTx:transaction];
388263
}
389264

390265
#pragma mark - OWSReadTracking

SignalServiceKit/Messages/Interactions/TSInfoMessage.swift

Lines changed: 128 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
import Foundation
77
import LibSignalClient
88

9-
// MARK: - Convenience initializers
9+
extension TSInfoMessage {
10+
// MARK: - Convenience initializers
1011

11-
public extension TSInfoMessage {
12-
convenience init(
12+
public convenience init(
1313
thread: TSThread,
1414
messageType: TSInfoMessageType,
1515
timestamp: UInt64 = MessageTimestampGenerator.sharedInstance.generateTimestamp(),
@@ -27,11 +27,133 @@ public extension TSInfoMessage {
2727
infoMessageUserInfo: infoMessageUserInfo,
2828
)
2929
}
30-
}
3130

32-
// MARK: - InfoMessageUserInfo
31+
@objc
32+
func _infoMessagePreviewText(tx: DBReadTransaction) -> String {
33+
switch messageType {
34+
case .typeLocalUserEndedSession:
35+
fallthrough
36+
case .typeRemoteUserEndedSession:
37+
return OWSLocalizedString("SECURE_SESSION_RESET", comment: "")
38+
case .typeUnsupportedMessage:
39+
return OWSLocalizedString("UNSUPPORTED_ATTACHMENT", comment: "")
40+
case .userNotRegistered:
41+
if let unregisteredAddress, unregisteredAddress.isValid {
42+
let recipientName = SSKEnvironment.shared.contactManagerRef.displayNameString(for: unregisteredAddress, transaction: tx)
43+
return String(
44+
format: OWSLocalizedString(
45+
"ERROR_UNREGISTERED_USER_FORMAT",
46+
comment: "Format string for 'unregistered user' error. Embeds {{the unregistered user's name or signal id}}.",
47+
),
48+
recipientName,
49+
)
50+
} else {
51+
return OWSLocalizedString("CONTACT_DETAIL_COMM_TYPE_INSECURE", comment: "")
52+
}
53+
case .typeGroupQuit:
54+
return OWSLocalizedString("GROUP_YOU_LEFT", comment: "")
55+
case .typeGroupUpdate:
56+
return self.groupUpdateDescription(tx: tx).string
57+
case .addToContactsOffer:
58+
return OWSLocalizedString("ADD_TO_CONTACTS_OFFER", comment: "Message shown in conversation view that offers to add an unknown user to your phone's contacts.")
59+
case .verificationStateChange:
60+
return OWSLocalizedString("VERIFICATION_STATE_CHANGE_GENERIC", comment: "Generic message indicating that verification state changed for a given user.")
61+
case .addUserToProfileWhitelistOffer:
62+
return OWSLocalizedString("ADD_USER_TO_PROFILE_WHITELIST_OFFER", comment: "Message shown in conversation view that offers to share your profile with a user.")
63+
case .addGroupToProfileWhitelistOffer:
64+
return OWSLocalizedString("ADD_GROUP_TO_PROFILE_WHITELIST_OFFER", comment: "Message shown in conversation view that offers to share your profile with a group.")
65+
case .typeDisappearingMessagesUpdate:
66+
break
67+
case .unknownProtocolVersion:
68+
break
69+
case .userJoinedSignal:
70+
let address = TSContactThread.contactAddress(fromThreadId: self.uniqueThreadId, transaction: tx)
71+
let recipientName = SSKEnvironment.shared.contactManagerRef.displayNameString(for: address!, transaction: tx)
72+
let format = OWSLocalizedString("INFO_MESSAGE_USER_JOINED_SIGNAL_BODY_FORMAT", comment: "Shown in inbox and conversation when a user joins Signal, embeds the new user's {{contact name}}")
73+
return String(format: format, recipientName)
74+
case .syncedThread:
75+
return ""
76+
case .profileUpdate:
77+
return self.profileChangeDescription(tx: tx)
78+
case .phoneNumberChange:
79+
guard let aci = self.phoneNumberChangeInfoAci() else {
80+
owsFailDebug("Invalid info message")
81+
return ""
82+
}
83+
let address = SignalServiceAddress(aci.wrappedAciValue)
84+
let userName = SSKEnvironment.shared.contactManagerRef.displayNameString(for: address, transaction: tx)
85+
let format = OWSLocalizedString(
86+
"INFO_MESSAGE_USER_CHANGED_PHONE_NUMBER_FORMAT",
87+
comment: "Indicates that another user has changed their phone number. Embeds: {{ the user's name}}",
88+
)
89+
return String(format: format, userName)
90+
case .recipientHidden:
91+
/// This does not control whether to show the info message in the chat
92+
/// preview. To control that, see ``TSInteraction.shouldAppearInInbox``.
93+
let address = TSContactThread.contactAddress(fromThreadId: self.uniqueThreadId, transaction: tx)
94+
if DependenciesBridge.shared.recipientHidingManager.isHiddenAddress(address!, tx: tx) {
95+
return OWSLocalizedString(
96+
"INFO_MESSAGE_CONTACT_REMOVED",
97+
comment: "Indicates that the recipient has been removed from the current user's contacts and that messaging them will re-add them.",
98+
)
99+
} else {
100+
return OWSLocalizedString(
101+
"INFO_MESSAGE_CONTACT_REINSTATED",
102+
comment: "Indicates that a previously-removed recipient has been added back to the current user's contacts.",
103+
)
104+
}
105+
case .paymentsActivationRequest:
106+
return self.paymentsActivationRequestDescription(tx: tx) ?? ""
107+
case .paymentsActivated:
108+
return self.paymentsActivatedDescription(tx: tx) ?? ""
109+
case .threadMerge:
110+
return self.threadMergeDescription(tx: tx)
111+
case .sessionSwitchover:
112+
return self.sessionSwitchoverDescription(tx: tx)
113+
case .reportedSpam:
114+
return OWSLocalizedString(
115+
"INFO_MESSAGE_REPORTED_SPAM",
116+
comment: "Shown when a user reports a conversation as spam.",
117+
)
118+
case .learnedProfileName:
119+
return self.learnedProfileNameDescription(tx: tx)
120+
case .blockedOtherUser:
121+
return OWSLocalizedString(
122+
"INFO_MESSAGE_BLOCKED_OTHER_USER",
123+
comment: "An info message inserted into a 1:1 chat when you block another user.",
124+
)
125+
case .blockedGroup:
126+
return OWSLocalizedString(
127+
"INFO_MESSAGE_BLOCKED_GROUP",
128+
comment: "An info message inserted into a group chat when you block the group.",
129+
)
130+
case .unblockedOtherUser:
131+
return OWSLocalizedString(
132+
"INFO_MESSAGE_UNBLOCKED_OTHER_USER",
133+
comment: "An info message inserted into a 1:1 chat when you unblock another user.",
134+
)
135+
case .unblockedGroup:
136+
return OWSLocalizedString(
137+
"INFO_MESSAGE_UNBLOCKED_GROUP",
138+
comment: "An info message inserted into a group chat when you unblock the group.",
139+
)
140+
case .acceptedMessageRequest:
141+
return OWSLocalizedString(
142+
"INFO_MESSAGE_ACCEPTED_MESSAGE_REQUEST",
143+
comment: "An info message inserted into the chat when you accept a message request, in a 1:1 or group chat.",
144+
)
145+
case .typeEndPoll:
146+
return self.endPollDescription(transaction: tx) ?? ""
147+
case .typePinnedMessage:
148+
return self.pinnedMessageDescription(transaction: tx) ?? ""
149+
}
150+
151+
owsFailDebug("Unknown info message type")
152+
return ""
153+
}
154+
155+
// MARK: - InfoMessageUserInfo
33156

34-
extension TSInfoMessage {
35157
func infoMessageValue<T>(forKey key: InfoMessageUserInfoKey) -> T? {
36158
guard let value = infoMessageUserInfo?[key] as? T else {
37159
return nil

0 commit comments

Comments
 (0)