Fixes crash (since ee07490) on loading empty MessagesVC

//FREEBIE
pull/1/head
Frederic Jacobs 10 years ago
parent 1784fcf900
commit f3f3eb55cc

@ -138,7 +138,7 @@ typedef enum : NSUInteger {
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
[self.messageMappings updateWithTransaction:transaction]; [self.messageMappings updateWithTransaction:transaction];
}]; }];
[self initializeToolbars]; [self initializeToolbars];
[self initializeCollectionViewLayout]; [self initializeCollectionViewLayout];
@ -155,9 +155,12 @@ typedef enum : NSUInteger {
{ {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
NSIndexPath * lastCellIndexPath = [NSIndexPath indexPathForRow:(NSInteger)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId]-1 inSection:0]; NSInteger numberOfMessages = (NSInteger)[self.messageMappings numberOfItemsInGroup:self.thread.uniqueId];
[self.collectionView scrollToItemAtIndexPath:lastCellIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:NO];
if (numberOfMessages > 0) {
NSIndexPath * lastCellIndexPath = [NSIndexPath indexPathForRow:numberOfMessages-1 inSection:0];
[self.collectionView scrollToItemAtIndexPath:lastCellIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:NO];
}
} }
- (void)startReadTimer{ - (void)startReadTimer{
@ -187,16 +190,16 @@ typedef enum : NSUInteger {
-(void)initializeToolbars -(void)initializeToolbars
{ {
self.title = self.thread.name; self.title = self.thread.name;
UIBarButtonItem *negativeSeparator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; UIBarButtonItem *negativeSeparator = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
if (!isGroupConversation) { if (!isGroupConversation) {
UIBarButtonItem * lockButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"lock"] style:UIBarButtonItemStylePlain target:self action:@selector(showFingerprint)]; UIBarButtonItem * lockButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"lock"] style:UIBarButtonItemStylePlain target:self action:@selector(showFingerprint)];
if ([self isRedPhoneReachable]) { if ([self isRedPhoneReachable]) {
UIBarButtonItem * callButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"call_tab"] style:UIBarButtonItemStylePlain target:self action:@selector(callAction)]; UIBarButtonItem * callButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"call_tab"] style:UIBarButtonItemStylePlain target:self action:@selector(callAction)];
[callButton setImageInsets:UIEdgeInsetsMake(0, -10, 0, -50)]; [callButton setImageInsets:UIEdgeInsetsMake(0, -10, 0, -50)];
negativeSeparator.width = -8; negativeSeparator.width = -8;
self.navigationItem.rightBarButtonItems = @[negativeSeparator, lockButton, callButton]; self.navigationItem.rightBarButtonItems = @[negativeSeparator, lockButton, callButton];
} }
else { else {
@ -271,7 +274,7 @@ typedef enum : NSUInteger {
if ([self isRedPhoneReachable]) { if ([self isRedPhoneReachable]) {
PhoneNumber *number = [self phoneNumberForThread]; PhoneNumber *number = [self phoneNumberForThread];
Contact *contact = [[Environment.getCurrent contactsManager] latestContactForPhoneNumber:number]; Contact *contact = [[Environment.getCurrent contactsManager] latestContactForPhoneNumber:number];
[Environment.phoneManager initiateOutgoingCallToContact:contact atRemoteNumber:number]; [Environment.phoneManager initiateOutgoingCallToContact:contact atRemoteNumber:number];
} else { } else {
DDLogWarn(@"Tried to initiate a call but contact has no RedPhone identifier"); DDLogWarn(@"Tried to initiate a call but contact has no RedPhone identifier");
@ -439,7 +442,7 @@ typedef enum : NSUInteger {
-(BOOL)shouldShowMessageStatusAtIndexPath:(NSIndexPath*)indexPath -(BOOL)shouldShowMessageStatusAtIndexPath:(NSIndexPath*)indexPath
{ {
TSMessageAdapter *currentMessage = [self messageAtIndexPath:indexPath]; TSMessageAdapter *currentMessage = [self messageAtIndexPath:indexPath];
if([self.thread isKindOfClass:[TSGroupThread class]]) { if([self.thread isKindOfClass:[TSGroupThread class]]) {
return currentMessage.messageType == TSIncomingMessageAdapter; return currentMessage.messageType == TSIncomingMessageAdapter;
@ -526,7 +529,7 @@ typedef enum : NSUInteger {
{ {
TSMessageAdapter *messageItem = [collectionView.dataSource collectionView:collectionView messageDataForItemAtIndexPath:indexPath]; TSMessageAdapter *messageItem = [collectionView.dataSource collectionView:collectionView messageDataForItemAtIndexPath:indexPath];
TSInteraction *interaction = [self interactionAtIndexPath:indexPath]; TSInteraction *interaction = [self interactionAtIndexPath:indexPath];
switch (messageItem.messageType) { switch (messageItem.messageType) {
case TSOutgoingMessageAdapter: case TSOutgoingMessageAdapter:
if (messageItem.messageState == TSOutgoingMessageStateUnsent) { if (messageItem.messageState == TSOutgoingMessageStateUnsent) {
@ -595,7 +598,7 @@ typedef enum : NSUInteger {
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction){ [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction){
show = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId] < [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInGroup:self.thread.uniqueId]; show = [self.messageMappings numberOfItemsInGroup:self.thread.uniqueId] < [[transaction ext:TSMessageDatabaseViewExtensionName] numberOfItemsInGroup:self.thread.uniqueId];
}]; }];
return show; return show;
} }
@ -642,7 +645,7 @@ typedef enum : NSUInteger {
rangeOptions.minLength = kYapDatabaseRangeMinLength; rangeOptions.minLength = kYapDatabaseRangeMinLength;
[self.messageMappings setRangeOptions:rangeOptions forGroup:self.thread.uniqueId]; [self.messageMappings setRangeOptions:rangeOptions forGroup:self.thread.uniqueId];
} }
#pragma mark Bubble User Actions #pragma mark Bubble User Actions
@ -677,7 +680,7 @@ typedef enum : NSUInteger {
NSArray *actions = @[@"Accept new identity key", @"Copy new identity key to pasteboard"]; NSArray *actions = @[@"Accept new identity key", @"Copy new identity key to pasteboard"];
[self.inputToolbar.contentView resignFirstResponder]; [self.inputToolbar.contentView resignFirstResponder];
[DJWActionSheet showInView:self.tabBarController.view withTitle:messageString cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:actions tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) { [DJWActionSheet showInView:self.tabBarController.view withTitle:messageString cancelButtonTitle:@"Cancel" destructiveButtonTitle:@"Delete" otherButtonTitles:actions tapBlock:^(DJWActionSheet *actionSheet, NSInteger tappedButtonIndex) {
if (tappedButtonIndex == actionSheet.cancelButtonIndex) { if (tappedButtonIndex == actionSheet.cancelButtonIndex) {
NSLog(@"User Cancelled"); NSLog(@"User Cancelled");
@ -704,7 +707,7 @@ typedef enum : NSUInteger {
#pragma mark - Navigation #pragma mark - Navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:kFingerprintSegueIdentifier]){ if ([segue.identifier isEqualToString:kFingerprintSegueIdentifier]){
FingerprintViewController *vc = [segue destinationViewController]; FingerprintViewController *vc = [segue destinationViewController];
[self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) { [self.uiDatabaseConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
@ -793,7 +796,7 @@ typedef enum : NSUInteger {
[self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) { [self.editingDatabaseConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
[message saveWithTransaction:transaction]; [message saveWithTransaction:transaction];
}]; }];
[[TSMessagesManager sharedManager] sendAttachment:[self qualityAdjustedAttachmentForImage:picture_camera] contentType:@"image/jpeg" inMessage:message thread:self.thread]; [[TSMessagesManager sharedManager] sendAttachment:[self qualityAdjustedAttachmentForImage:picture_camera] contentType:@"image/jpeg" inMessage:message thread:self.thread];
[self finishSendingMessage]; [self finishSendingMessage];
} }
@ -917,7 +920,7 @@ typedef enum : NSUInteger {
} }
[self.collectionView performBatchUpdates:^{ [self.collectionView performBatchUpdates:^{
for (YapDatabaseViewRowChange *rowChange in messageRowChanges) for (YapDatabaseViewRowChange *rowChange in messageRowChanges)
{ {
switch (rowChange.type) switch (rowChange.type)
@ -946,7 +949,7 @@ typedef enum : NSUInteger {
case YapDatabaseViewChangeUpdate : case YapDatabaseViewChangeUpdate :
{ {
NSMutableArray *rowsToUpdate = [@[rowChange.indexPath] mutableCopy]; NSMutableArray *rowsToUpdate = [@[rowChange.indexPath] mutableCopy];
if (_lastDeliveredMessageIndexPath) { if (_lastDeliveredMessageIndexPath) {
[rowsToUpdate addObject:_lastDeliveredMessageIndexPath]; [rowsToUpdate addObject:_lastDeliveredMessageIndexPath];
} }
@ -1143,7 +1146,6 @@ typedef enum : NSUInteger {
self.thread = gThread; self.thread = gThread;
}]; }];
} }
- (IBAction)unwindGroupUpdated:(UIStoryboardSegue *)segue{ - (IBAction)unwindGroupUpdated:(UIStoryboardSegue *)segue{

Loading…
Cancel
Save