You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/src/Messages/Interactions/TSErrorMessage.m

109 lines
4.0 KiB
Matlab

10 years ago
//
// TSErrorMessage.m
// TextSecureKit
//
// Created by Frederic Jacobs on 12/11/14.
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
//
#import "TSErrorMessage.h"
#import "NotificationsProtocol.h"
#import "TSContactThread.h"
10 years ago
#import "TSErrorMessage_privateConstructor.h"
#import "TSMessagesManager.h"
#import "TextSecureKitEnv.h"
@implementation TSErrorMessage
- (instancetype)initWithCoder:(NSCoder *)coder
{
return [super initWithCoder:coder];
}
10 years ago
- (instancetype)initWithTimestamp:(uint64_t)timestamp
inThread:(TSThread *)thread
failedMessageType:(TSErrorMessageType)errorMessageType
{
self = [super initWithTimestamp:timestamp
inThread:thread
messageBody:nil
attachmentIds:@[]
expiresInSeconds:0
expireStartedAt:0];
10 years ago
if (!self) {
return self;
10 years ago
}
_errorType = errorMessageType;
// TODO Move this out of model class.
10 years ago
[[TextSecureKitEnv sharedEnv].notificationsManager notifyUserForErrorMessage:self inThread:thread];
return self;
}
- (instancetype)initWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
failedMessageType:(TSErrorMessageType)errorMessageType
{
10 years ago
TSContactThread *contactThread =
[TSContactThread getOrCreateThreadWithContactId:envelope.source transaction:transaction];
10 years ago
return [self initWithTimestamp:envelope.timestamp inThread:contactThread failedMessageType:errorMessageType];
10 years ago
}
- (NSString *)description {
switch (_errorType) {
case TSErrorMessageNoSession:
return NSLocalizedString(@"ERROR_MESSAGE_NO_SESSION", @"");
case TSErrorMessageInvalidMessage:
return NSLocalizedString(@"ERROR_MESSAGE_INVALID_MESSAGE", @"");
case TSErrorMessageInvalidVersion:
return NSLocalizedString(@"ERROR_MESSAGE_INVALID_VERSION", @"");
case TSErrorMessageDuplicateMessage:
return NSLocalizedString(@"ERROR_MESSAGE_DUPLICATE_MESSAGE", @"");
case TSErrorMessageInvalidKeyException:
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", @"");
10 years ago
default:
return NSLocalizedString(@"ERROR_MESSAGE_UNKNOWN_ERROR", @"");
break;
}
}
+ (instancetype)corruptedMessageWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
return [[self alloc] initWithEnvelope:envelope
withTransaction:transaction
failedMessageType:TSErrorMessageInvalidMessage];
10 years ago
}
+ (instancetype)invalidVersionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
return [[self alloc] initWithEnvelope:envelope
withTransaction:transaction
failedMessageType:TSErrorMessageInvalidVersion];
10 years ago
}
+ (instancetype)invalidKeyExceptionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
return [[self alloc] initWithEnvelope:envelope
withTransaction:transaction
failedMessageType:TSErrorMessageInvalidKeyException];
10 years ago
}
+ (instancetype)missingSessionWithEnvelope:(OWSSignalServiceProtosEnvelope *)envelope
withTransaction:(YapDatabaseReadWriteTransaction *)transaction
{
return
[[self alloc] initWithEnvelope:envelope withTransaction:transaction failedMessageType:TSErrorMessageNoSession];
10 years ago
}
@end