Error handling messages and Info Messages

pull/1/head
Frederic Jacobs 10 years ago
parent dde6fc0a7f
commit d90d27995c

@ -12,7 +12,7 @@
@implementation TSErrorMessage
- (instancetype)initWithTimestamp:(uint64_t)timestamp inThread:(TSThread *)thread failedMessageType:(TSErrorMessageType)errorMessageType{
self = [super initWithTimestamp:timestamp inThread:thread messageBody:@"Placeholder for error message." attachements:nil];
self = [super initWithTimestamp:timestamp inThread:thread messageBody:nil attachements:nil];
if (self) {
_errorType = errorMessageType;
@ -21,6 +21,28 @@
return self;
}
- (NSString*)description{
switch (_errorType) {
case TSErrorMessageNoSession:
return @"No available session for contact";
case TSErrorMessageMissingKeyId:
return @"Received a message with unknown PreKey";
case TSErrorMessageInvalidMessage:
return @"Received a corrupted message";
case TSErrorMessageInvalidVersion:
return @"Received a message not compatible with this version";
case TSErrorMessageDuplicateMessage:
return @"Received a duplicated message";
case TSErrorMessageInvalidKeyException:
return @"The recipient's key is not valid.";
case TSErrorMessageWrongTrustedIdentityKey:
return @"Your contact's identity key changed. Tap to verify and accept new key";
default:
return @"An unknown error occured";
break;
}
}
+ (instancetype)userNotRegisteredErrorMessageInThread:(TSThread*)thread{
return [[self alloc] initWithTimestamp:[NSDate ows_millisecondTimeStamp] inThread:thread];
}

@ -11,7 +11,8 @@
@interface TSInfoMessage : TSMessage
typedef NS_ENUM(NSInteger, TSInfoMessageType){
TSInfoMessageTypeSessionDidEnd
TSInfoMessageTypeSessionDidEnd,
TSInfoMessageTypeUnsupportedMessage
};
@property TSInfoMessageType messageType;

@ -20,4 +20,17 @@
return self;
}
- (NSString *)description{
switch (_messageType) {
case TSInfoMessageTypeSessionDidEnd:
return @"Secure session ended.";
case TSInfoMessageTypeUnsupportedMessage:
return @"Media messages are currently not supported.";
default:
break;
}
return @"Unknown Info Message Type";
}
@end

@ -180,6 +180,13 @@
} else if (content.attachments.count > 0) {
DDLogVerbose(@"Received push media message (attachement) ...");
[self handleReceivedMediaMessage:incomingMessage withContent:content];
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSInfoMessage *message = [[TSInfoMessage alloc] initWithTimestamp:incomingMessage.timestamp
inThread:[TSContactThread threadWithContactId:incomingMessage.source transaction:transaction]
messageType:TSInfoMessageTypeUnsupportedMessage];
[message saveWithTransaction:transaction];
}];
} else {
DDLogVerbose(@"Received push text message...");
[self handleReceivedTextMessage:incomingMessage withContent:content];
@ -231,7 +238,7 @@
}
- (void)processException:(NSException*)exception pushSignal:(IncomingPushMessageSignal*)signal{
NSLog(@"Got exception: %@", exception.description);
DDLogError(@"Got exception: %@", exception.description);
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSErrorMessage *errorMessage = [[TSErrorMessage alloc] initWithTimestamp:signal.timestamp inThread:[TSContactThread threadWithContactId:signal.source transaction:transaction] failedMessageType:TSErrorMessageNoSession];
[errorMessage saveWithTransaction:transaction];

@ -146,7 +146,7 @@ typedef enum : NSUInteger {
[callButton setImageInsets:UIEdgeInsetsMake(0, -10, 0, -50)];
UIBarButtonItem *negativeSeparator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
negativeSeparator.width = -8;
self.navigationItem.rightBarButtonItems = @[negativeSeparator, lockButton, callButton];
} else {
self.navigationItem.rightBarButtonItem = lockButton;
@ -160,21 +160,22 @@ typedef enum : NSUInteger {
self.outgoingBubbleImageData = [bubbleFactory outgoingMessagesBubbleImageWithColor:[UIColor ows_blueColor]];
self.incomingBubbleImageData = [bubbleFactory incomingMessagesBubbleImageWithColor:[UIColor jsq_messageBubbleLightGrayColor]];
self.outgoingMessageFailedImageData = [bubbleFactory outgoingMessageFailedBubbleImageWithColor:[UIColor ows_fadedBlueColor]];
}
-(void)initializeCollectionViewLayout
{
[self.collectionView.collectionViewLayout setMessageBubbleFont:[UIFont ows_lightFontWithSize:16.0f]];
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.automaticallyScrollsToMostRecentMessage = YES;
self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeZero;
self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero;
if (self.collectionView){
[self.collectionView.collectionViewLayout setMessageBubbleFont:[UIFont ows_lightFontWithSize:16.0f]];
self.collectionView.showsVerticalScrollIndicator = NO;
self.collectionView.showsHorizontalScrollIndicator = NO;
self.automaticallyScrollsToMostRecentMessage = YES;
self.collectionView.collectionViewLayout.incomingAvatarViewSize = CGSizeZero;
self.collectionView.collectionViewLayout.outgoingAvatarViewSize = CGSizeZero;
}
}
#pragma mark - Fingerprints
@ -190,7 +191,7 @@ typedef enum : NSUInteger {
-(BOOL)isRedPhoneReachable
{
return [[Environment getCurrent].contactsManager isPhoneNumberRegisteredWithRedPhone:[self phoneNumberForThread]];
return [[Environment getCurrent].contactsManager isPhoneNumberRegisteredWithRedPhone:[self phoneNumberForThread]];
}
-(PhoneNumber*)phoneNumberForThread
@ -250,7 +251,7 @@ typedef enum : NSUInteger {
if ([message.senderId isEqualToString:self.senderId]) {
if (message.messageState == TSOutgoingMessageStateUnsent || message.messageState == TSOutgoingMessageStateAttemptingOut) {
return self.outgoingMessageFailedImageData;
}
}
return self.outgoingBubbleImageData;
}
@ -317,7 +318,7 @@ typedef enum : NSUInteger {
}
return cell;
}
-(JSQCallCollectionViewCell*)loadCallCellForCall:(id<JSQMessageData>)call atIndexPath:(NSIndexPath*)indexPath
@ -381,7 +382,7 @@ typedef enum : NSUInteger {
-(BOOL)shouldShowMessageStatusAtIndexPath:(NSIndexPath*)indexPath
{
TSMessageAdapter * currentMessage = [self messageAtIndexPath:indexPath];
if (indexPath.item == [self.collectionView numberOfItemsInSection:indexPath.section]-1)
@ -393,7 +394,7 @@ typedef enum : NSUInteger {
{
return NO;
}
TSMessageAdapter * nextMessage = [self nextOutgoingMessage:indexPath];
return ![self isMessageOutgoingAndDelivered:nextMessage];
}
@ -679,7 +680,7 @@ typedef enum : NSUInteger {
if (_lastDeliveredMessageIndexPath) {
[rowsToUpdate addObject:_lastDeliveredMessageIndexPath];
}
[self.collectionView reloadItemsAtIndexPaths:rowsToUpdate];
break;
}

Loading…
Cancel
Save