Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Messages/Interactions/TSErrorMessage.m
1 views
1
//
2
// Copyright 2017 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
#import "TSErrorMessage.h"
7
#import <SignalServiceKit/SignalServiceKit-Swift.h>
8
9
NS_ASSUME_NONNULL_BEGIN
10
11
#pragma mark -
12
13
@interface TSErrorMessage ()
14
15
@property (nonatomic, getter=wasRead) BOOL read;
16
17
@end
18
19
#pragma mark -
20
21
@implementation TSErrorMessage
22
23
- (NSUInteger)hash
24
{
25
NSUInteger result = [super hash];
26
result ^= (NSUInteger)self.errorType;
27
result ^= self.read;
28
result ^= self.recipientAddress.hash;
29
result ^= self.sender.hash;
30
result ^= self.wasIdentityVerified;
31
return result;
32
}
33
34
- (BOOL)isEqual:(id)other
35
{
36
if (![super isEqual:other]) {
37
return NO;
38
}
39
TSErrorMessage *typedOther = (TSErrorMessage *)other;
40
if (self.errorType != typedOther.errorType) {
41
return NO;
42
}
43
if (self.read != typedOther.read) {
44
return NO;
45
}
46
if (![NSObject isObject:self.recipientAddress equalToObject:typedOther.recipientAddress]) {
47
return NO;
48
}
49
if (![NSObject isObject:self.sender equalToObject:typedOther.sender]) {
50
return NO;
51
}
52
if (self.wasIdentityVerified != typedOther.wasIdentityVerified) {
53
return NO;
54
}
55
return YES;
56
}
57
58
- (instancetype)initErrorMessageWithBuilder:(TSErrorMessageBuilder *)errorMessageBuilder
59
{
60
self = [super initMessageWithBuilder:errorMessageBuilder];
61
62
if (!self) {
63
return self;
64
}
65
66
_errorType = errorMessageBuilder.errorType;
67
_sender = errorMessageBuilder.senderAddress;
68
_recipientAddress = errorMessageBuilder.recipientAddress;
69
_wasIdentityVerified = errorMessageBuilder.wasIdentityVerified;
70
71
if (self.isDynamicInteraction) {
72
self.read = YES;
73
}
74
75
return self;
76
}
77
78
// --- CODE GENERATION MARKER
79
80
// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run
81
// `sds_codegen.sh`.
82
83
// clang-format off
84
85
- (instancetype)initWithGrdbId:(int64_t)grdbId
86
uniqueId:(NSString *)uniqueId
87
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
88
sortId:(uint64_t)sortId
89
timestamp:(uint64_t)timestamp
90
uniqueThreadId:(NSString *)uniqueThreadId
91
body:(nullable NSString *)body
92
bodyRanges:(nullable MessageBodyRanges *)bodyRanges
93
contactShare:(nullable OWSContact *)contactShare
94
deprecated_attachmentIds:(nullable NSArray<NSString *> *)deprecated_attachmentIds
95
editState:(TSEditState)editState
96
expireStartedAt:(uint64_t)expireStartedAt
97
expireTimerVersion:(nullable NSNumber *)expireTimerVersion
98
expiresAt:(uint64_t)expiresAt
99
expiresInSeconds:(unsigned int)expiresInSeconds
100
giftBadge:(nullable OWSGiftBadge *)giftBadge
101
isGroupStoryReply:(BOOL)isGroupStoryReply
102
isPoll:(BOOL)isPoll
103
isSmsMessageRestoredFromBackup:(BOOL)isSmsMessageRestoredFromBackup
104
isViewOnceComplete:(BOOL)isViewOnceComplete
105
isViewOnceMessage:(BOOL)isViewOnceMessage
106
linkPreview:(nullable OWSLinkPreview *)linkPreview
107
messageSticker:(nullable MessageSticker *)messageSticker
108
quotedMessage:(nullable TSQuotedMessage *)quotedMessage
109
storedShouldStartExpireTimer:(BOOL)storedShouldStartExpireTimer
110
storyAuthorUuidString:(nullable NSString *)storyAuthorUuidString
111
storyReactionEmoji:(nullable NSString *)storyReactionEmoji
112
storyTimestamp:(nullable NSNumber *)storyTimestamp
113
wasRemotelyDeleted:(BOOL)wasRemotelyDeleted
114
errorType:(TSErrorMessageType)errorType
115
read:(BOOL)read
116
recipientAddress:(nullable SignalServiceAddress *)recipientAddress
117
sender:(nullable SignalServiceAddress *)sender
118
wasIdentityVerified:(BOOL)wasIdentityVerified
119
{
120
self = [super initWithGrdbId:grdbId
121
uniqueId:uniqueId
122
receivedAtTimestamp:receivedAtTimestamp
123
sortId:sortId
124
timestamp:timestamp
125
uniqueThreadId:uniqueThreadId
126
body:body
127
bodyRanges:bodyRanges
128
contactShare:contactShare
129
deprecated_attachmentIds:deprecated_attachmentIds
130
editState:editState
131
expireStartedAt:expireStartedAt
132
expireTimerVersion:expireTimerVersion
133
expiresAt:expiresAt
134
expiresInSeconds:expiresInSeconds
135
giftBadge:giftBadge
136
isGroupStoryReply:isGroupStoryReply
137
isPoll:isPoll
138
isSmsMessageRestoredFromBackup:isSmsMessageRestoredFromBackup
139
isViewOnceComplete:isViewOnceComplete
140
isViewOnceMessage:isViewOnceMessage
141
linkPreview:linkPreview
142
messageSticker:messageSticker
143
quotedMessage:quotedMessage
144
storedShouldStartExpireTimer:storedShouldStartExpireTimer
145
storyAuthorUuidString:storyAuthorUuidString
146
storyReactionEmoji:storyReactionEmoji
147
storyTimestamp:storyTimestamp
148
wasRemotelyDeleted:wasRemotelyDeleted];
149
150
if (!self) {
151
return self;
152
}
153
154
_errorType = errorType;
155
_read = read;
156
_recipientAddress = recipientAddress;
157
_sender = sender;
158
_wasIdentityVerified = wasIdentityVerified;
159
160
return self;
161
}
162
163
// clang-format on
164
165
// --- CODE GENERATION MARKER
166
167
- (OWSInteractionType)interactionType
168
{
169
return OWSInteractionType_Error;
170
}
171
172
- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction
173
{
174
switch (_errorType) {
175
case TSErrorMessageNoSession:
176
return OWSLocalizedString(@"ERROR_MESSAGE_NO_SESSION", @"");
177
case TSErrorMessageInvalidMessage:
178
return OWSLocalizedString(@"ERROR_MESSAGE_INVALID_MESSAGE", @"");
179
case TSErrorMessageInvalidVersion:
180
return OWSLocalizedString(@"ERROR_MESSAGE_INVALID_VERSION", @"");
181
case TSErrorMessageDuplicateMessage:
182
return OWSLocalizedString(@"ERROR_MESSAGE_DUPLICATE_MESSAGE", @"");
183
case TSErrorMessageInvalidKeyException:
184
return OWSLocalizedString(@"ERROR_MESSAGE_INVALID_KEY_EXCEPTION", @"");
185
case TSErrorMessageWrongTrustedIdentityKey:
186
return OWSLocalizedString(@"ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY", @"");
187
case TSErrorMessageNonBlockingIdentityChange:
188
return [TSErrorMessage safetyNumberChangeDescriptionFor:self.recipientAddress tx:transaction];
189
case TSErrorMessageUnknownContactBlockOffer:
190
return OWSLocalizedString(@"UNKNOWN_CONTACT_BLOCK_OFFER",
191
@"Message shown in conversation view that offers to block an unknown user.");
192
case TSErrorMessageGroupCreationFailed:
193
return OWSLocalizedString(@"GROUP_CREATION_FAILED",
194
@"Message shown in conversation view that indicates there were issues with group creation.");
195
case TSErrorMessageSessionRefresh:
196
return OWSLocalizedString(
197
@"ERROR_MESSAGE_SESSION_REFRESH", @"Text notifying the user that their secure session has been reset");
198
case TSErrorMessageDecryptionFailure: {
199
if (self.sender) {
200
NSString *formatString = OWSLocalizedString(@"ERROR_MESSAGE_DECRYPTION_FAILURE",
201
@"Error message for a decryption failure. Embeds {{sender short name}}.");
202
NSString *senderName =
203
[SSKEnvironment.shared.contactManagerObjcRef shortDisplayNameStringForAddress:self.sender
204
transaction:transaction];
205
#pragma clang diagnostic push
206
#pragma clang diagnostic ignored "-Wformat-nonliteral"
207
return [[NSString alloc] initWithFormat:formatString, senderName];
208
#pragma clang diagnostic pop
209
} else {
210
return OWSLocalizedString(
211
@"ERROR_MESSAGE_DECRYPTION_FAILURE_UNKNOWN_SENDER", @"Error message for a decryption failure.");
212
}
213
}
214
default:
215
OWSFailDebug(@"failure: unknown error type");
216
break;
217
}
218
return OWSLocalizedString(@"ERROR_MESSAGE_UNKNOWN_ERROR", @"");
219
}
220
221
#pragma mark - OWSReadTracking
222
223
- (uint64_t)expireStartedAt
224
{
225
return 0;
226
}
227
228
- (void)markAsReadAtTimestamp:(uint64_t)readTimestamp
229
thread:(TSThread *)thread
230
circumstance:(OWSReceiptCircumstance)circumstance
231
shouldClearNotifications:(BOOL)shouldClearNotifications
232
transaction:(DBWriteTransaction *)transaction
233
{
234
OWSAssertDebug(transaction);
235
236
if (self.read) {
237
return;
238
}
239
240
[self anyUpdateErrorMessageWithTransaction:transaction block:^(TSErrorMessage *message) { message.read = YES; }];
241
242
// Ignore `circumstance` - we never send read receipts for error messages.
243
}
244
245
@end
246
247
NS_ASSUME_NONNULL_END
248
249