|
|
|
@ -3,12 +3,16 @@
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "TSErrorMessage.h"
|
|
|
|
|
#import "ContactsManagerProtocol.h"
|
|
|
|
|
#import "NSDate+millisecondTimeStamp.h"
|
|
|
|
|
#import "NotificationsProtocol.h"
|
|
|
|
|
#import "TSContactThread.h"
|
|
|
|
|
#import "TSErrorMessage_privateConstructor.h"
|
|
|
|
|
#import "TSMessagesManager.h"
|
|
|
|
|
#import "TextSecureKitEnv.h"
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
|
|
@implementation TSErrorMessage
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)coder
|
|
|
|
@ -19,6 +23,14 @@
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
|
|
|
inThread:(TSThread *)thread
|
|
|
|
|
failedMessageType:(TSErrorMessageType)errorMessageType
|
|
|
|
|
{
|
|
|
|
|
return [self initWithTimestamp:timestamp inThread:thread failedMessageType:errorMessageType recipientId:nil];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
|
|
|
|
inThread:(TSThread *)thread
|
|
|
|
|
failedMessageType:(TSErrorMessageType)errorMessageType
|
|
|
|
|
recipientId:(nullable NSString *)recipientId
|
|
|
|
|
{
|
|
|
|
|
self = [super initWithTimestamp:timestamp
|
|
|
|
|
inThread:thread
|
|
|
|
@ -32,6 +44,8 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_errorType = errorMessageType;
|
|
|
|
|
_recipientId = recipientId;
|
|
|
|
|
|
|
|
|
|
// TODO: Move this out of model class.
|
|
|
|
|
//
|
|
|
|
|
// For now, dispatch async to ensure we're not inside a transaction
|
|
|
|
@ -68,8 +82,21 @@
|
|
|
|
|
return NSLocalizedString(@"ERROR_MESSAGE_INVALID_KEY_EXCEPTION", @"");
|
|
|
|
|
case TSErrorMessageWrongTrustedIdentityKey:
|
|
|
|
|
return NSLocalizedString(@"ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY", @"");
|
|
|
|
|
case TSErrorMessageNonBlockingIdentityChange:
|
|
|
|
|
return NSLocalizedString(@"ERROR_MESSAGE_NON_BLOCKING_IDENTITY_CHANGE", @"");
|
|
|
|
|
case TSErrorMessageNonBlockingIdentityChange: {
|
|
|
|
|
if (self.recipientId) {
|
|
|
|
|
NSString *messageFormat = NSLocalizedString(@"ERROR_MESSAGE_NON_BLOCKING_IDENTITY_CHANGE_FORMAT",
|
|
|
|
|
@"Shown when signal users safety numbers changed, embeds the user's {{name or phone number}}");
|
|
|
|
|
|
|
|
|
|
NSString *recipientDisplayName =
|
|
|
|
|
[[TextSecureKitEnv sharedEnv].contactsManager displayNameForPhoneIdentifier:self.recipientId];
|
|
|
|
|
return [NSString stringWithFormat:messageFormat, recipientDisplayName];
|
|
|
|
|
} else {
|
|
|
|
|
// recipientId will be nil for legacy errors
|
|
|
|
|
return NSLocalizedString(
|
|
|
|
|
@"ERROR_MESSAGE_NON_BLOCKING_IDENTITY_CHANGE", @"Shown when signal users safety numbers changed");
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case TSErrorMessageUnknownContactBlockOffer:
|
|
|
|
|
return NSLocalizedString(@"UNKNOWN_CONTACT_BLOCK_OFFER", nil);
|
|
|
|
|
default:
|
|
|
|
@ -109,4 +136,14 @@
|
|
|
|
|
[[self alloc] initWithEnvelope:envelope withTransaction:transaction failedMessageType:TSErrorMessageNoSession];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId
|
|
|
|
|
{
|
|
|
|
|
return [[self alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp]
|
|
|
|
|
inThread:thread
|
|
|
|
|
failedMessageType:TSErrorMessageNonBlockingIdentityChange
|
|
|
|
|
recipientId:recipientId];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|
|
|
|
|