Merge branch 'mkirk/show-name-in-sn-change'

pull/1/head
Michael Kirk 9 years ago
commit 52097864f1

@ -5,6 +5,8 @@
#import "OWSSignalServiceProtos.pb.h" #import "OWSSignalServiceProtos.pb.h"
#import "TSMessage.h" #import "TSMessage.h"
NS_ASSUME_NONNULL_BEGIN
@interface TSErrorMessage : TSMessage @interface TSErrorMessage : TSMessage
typedef NS_ENUM(int32_t, TSErrorMessageType) { typedef NS_ENUM(int32_t, TSErrorMessageType) {
@ -20,13 +22,19 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
}; };
- (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER; - (instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTimestamp:(uint64_t)timestamp - (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread inThread:(TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType NS_DESIGNATED_INITIALIZER; failedMessageType:(TSErrorMessageType)errorMessageType
recipientId:(nullable NSString *)recipientId NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTimestamp:(uint64_t)timestamp - (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread inThread:(TSThread *)thread
messageBody:(NSString *)body failedMessageType:(TSErrorMessageType)errorMessageType;
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(nullable TSThread *)thread
messageBody:(nullable NSString *)body
attachmentIds:(NSArray<NSString *> *)attachmentIds attachmentIds:(NSArray<NSString *> *)attachmentIds
expiresInSeconds:(uint32_t)expiresInSeconds expiresInSeconds:(uint32_t)expiresInSeconds
expireStartedAt:(uint64_t)expireStartedAt NS_UNAVAILABLE; expireStartedAt:(uint64_t)expireStartedAt NS_UNAVAILABLE;
@ -43,6 +51,11 @@ typedef NS_ENUM(int32_t, TSErrorMessageType) {
+ (instancetype)missingSessionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope + (instancetype)missingSessionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction; withTransaction:(YapDatabaseReadWriteTransaction *)transaction;
+ (instancetype)nonblockingIdentityChangeInThread:(TSThread *)thread recipientId:(NSString *)recipientId;
@property (nonatomic, readonly) TSErrorMessageType errorType; @property (nonatomic, readonly) TSErrorMessageType errorType;
@property (nullable, nonatomic, readonly) NSString *recipientId;
@end @end
NS_ASSUME_NONNULL_END

@ -3,12 +3,16 @@
// //
#import "TSErrorMessage.h" #import "TSErrorMessage.h"
#import "ContactsManagerProtocol.h"
#import "NSDate+millisecondTimeStamp.h"
#import "NotificationsProtocol.h" #import "NotificationsProtocol.h"
#import "TSContactThread.h" #import "TSContactThread.h"
#import "TSErrorMessage_privateConstructor.h" #import "TSErrorMessage_privateConstructor.h"
#import "TSMessagesManager.h" #import "TSMessagesManager.h"
#import "TextSecureKitEnv.h" #import "TextSecureKitEnv.h"
NS_ASSUME_NONNULL_BEGIN
@implementation TSErrorMessage @implementation TSErrorMessage
- (instancetype)initWithCoder:(NSCoder *)coder - (instancetype)initWithCoder:(NSCoder *)coder
@ -19,6 +23,14 @@
- (instancetype)initWithTimestamp:(uint64_t)timestamp - (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread inThread:(TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType 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 self = [super initWithTimestamp:timestamp
inThread:thread inThread:thread
@ -32,6 +44,8 @@
} }
_errorType = errorMessageType; _errorType = errorMessageType;
_recipientId = recipientId;
// TODO: Move this out of model class. // TODO: Move this out of model class.
// //
// For now, dispatch async to ensure we're not inside a transaction // For now, dispatch async to ensure we're not inside a transaction
@ -68,8 +82,21 @@
return NSLocalizedString(@"ERROR_MESSAGE_INVALID_KEY_EXCEPTION", @""); return NSLocalizedString(@"ERROR_MESSAGE_INVALID_KEY_EXCEPTION", @"");
case TSErrorMessageWrongTrustedIdentityKey: case TSErrorMessageWrongTrustedIdentityKey:
return NSLocalizedString(@"ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY", @""); return NSLocalizedString(@"ERROR_MESSAGE_WRONG_TRUSTED_IDENTITY_KEY", @"");
case TSErrorMessageNonBlockingIdentityChange: case TSErrorMessageNonBlockingIdentityChange: {
return NSLocalizedString(@"ERROR_MESSAGE_NON_BLOCKING_IDENTITY_CHANGE", @""); 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: case TSErrorMessageUnknownContactBlockOffer:
return NSLocalizedString(@"UNKNOWN_CONTACT_BLOCK_OFFER", nil); return NSLocalizedString(@"UNKNOWN_CONTACT_BLOCK_OFFER", nil);
default: default:
@ -109,4 +136,14 @@
[[self alloc] initWithEnvelope:envelope withTransaction:transaction failedMessageType:TSErrorMessageNoSession]; [[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 @end
NS_ASSUME_NONNULL_END

@ -1,9 +1,5 @@
// //
// TSInvalidIdentityKeySendingErrorMessage.h // Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Signal
//
// Created by Frederic Jacobs on 15/02/15.
// Copyright (c) 2015 Open Whisper Systems. All rights reserved.
// //
#import "TSInvalidIdentityKeyErrorMessage.h" #import "TSInvalidIdentityKeyErrorMessage.h"
@ -24,7 +20,6 @@ extern NSString *TSInvalidRecipientKey;
forRecipient:(NSString *)recipientId forRecipient:(NSString *)recipientId
preKeyBundle:(PreKeyBundle *)preKeyBundle; preKeyBundle:(PreKeyBundle *)preKeyBundle;
@property (nonatomic, readonly) NSString *recipientId;
@property (nonatomic, readonly) NSString *messageId; @property (nonatomic, readonly) NSString *messageId;
@end @end

@ -32,12 +32,12 @@ NSString *TSInvalidRecipientKey = @"TSInvalidRecipientKey";
{ {
self = [super initWithTimestamp:message.timestamp self = [super initWithTimestamp:message.timestamp
inThread:thread inThread:thread
failedMessageType:TSErrorMessageWrongTrustedIdentityKey]; failedMessageType:TSErrorMessageWrongTrustedIdentityKey
recipientId:recipientId];
if (self) { if (self) {
_messageId = message.uniqueId; _messageId = message.uniqueId;
_preKeyBundle = preKeyBundle; _preKeyBundle = preKeyBundle;
_recipientId = recipientId;
} }
return self; return self;

@ -84,19 +84,12 @@
- (void)createIdentityChangeInfoMessageForRecipientId:(NSString *)recipientId - (void)createIdentityChangeInfoMessageForRecipientId:(NSString *)recipientId
{ {
UInt64 nowTimestamp = [NSDate ows_millisecondTimeStamp];
TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:recipientId]; TSContactThread *contactThread = [TSContactThread getOrCreateThreadWithContactId:recipientId];
[[[TSErrorMessage alloc] initWithTimestamp:nowTimestamp [[TSErrorMessage nonblockingIdentityChangeInThread:contactThread recipientId:recipientId] save];
inThread:contactThread
failedMessageType:TSErrorMessageNonBlockingIdentityChange] save];
for (TSGroupThread *groupThread in [TSGroupThread groupThreadsWithRecipientId:recipientId]) { for (TSGroupThread *groupThread in [TSGroupThread groupThreadsWithRecipientId:recipientId]) {
[[[TSErrorMessage alloc] initWithTimestamp:nowTimestamp [[TSErrorMessage nonblockingIdentityChangeInThread:groupThread recipientId:recipientId] save];
inThread:groupThread
failedMessageType:TSErrorMessageNonBlockingIdentityChange] save];
} }
} }
@end @end

Loading…
Cancel
Save