Fix occasional crash when sending after deleting messages

// FREEBIE
pull/1/head
Michael Kirk 9 years ago
parent ee0cce75e8
commit 43a2eb9da1

@ -109,7 +109,6 @@ typedef enum : NSUInteger {
@property (nonatomic, retain) NSTimer *readTimer; @property (nonatomic, retain) NSTimer *readTimer;
@property (nonatomic, strong) UILabel *navbarTitleLabel; @property (nonatomic, strong) UILabel *navbarTitleLabel;
@property (nonatomic, retain) UIButton *attachButton; @property (nonatomic, retain) UIButton *attachButton;
@property (nonatomic, retain) NSIndexPath *lastDeliveredMessageIndexPath;
@property NSUInteger page; @property NSUInteger page;
@property (nonatomic) BOOL composeOnOpen; @property (nonatomic) BOOL composeOnOpen;
@ -172,7 +171,6 @@ typedef enum : NSUInteger {
_thread = thread; _thread = thread;
isGroupConversation = [self.thread isKindOfClass:[TSGroupThread class]]; isGroupConversation = [self.thread isKindOfClass:[TSGroupThread class]];
_composeOnOpen = keyboardAppearing; _composeOnOpen = keyboardAppearing;
_lastDeliveredMessageIndexPath = nil;
[self.uiDatabaseConnection beginLongLivedReadTransaction]; [self.uiDatabaseConnection beginLongLivedReadTransaction];
self.messageMappings = self.messageMappings =
@ -632,7 +630,10 @@ typedef enum : NSUInteger {
[[TSMessagesManager sharedManager] sendMessage:message [[TSMessagesManager sharedManager] sendMessage:message
inThread:self.thread inThread:self.thread
success:^{ success:^{
TSMessage *penultimateMessage = self.lastDeliveredMessage;
self.lastDeliveredMessage = message; self.lastDeliveredMessage = message;
// Touch the old one to remove "delivered" label
[penultimateMessage touch];
} }
failure:^{ failure:^{
DDLogWarn(@"%@ Failed to deliver message.", self.tag); DDLogWarn(@"%@ Failed to deliver message.", self.tag);
@ -954,7 +955,6 @@ typedef enum : NSUInteger {
return failedString; return failedString;
} else if ([outgoingMessage isEqual:self.lastDeliveredMessage]) { } else if ([outgoingMessage isEqual:self.lastDeliveredMessage]) {
_lastDeliveredMessageIndexPath = indexPath; // So we can remove it later.
NSAttributedString *deliveredString = NSAttributedString *deliveredString =
[[NSAttributedString alloc] initWithString:NSLocalizedString(@"DELIVERED_MESSAGE_TEXT", @"")]; [[NSAttributedString alloc] initWithString:NSLocalizedString(@"DELIVERED_MESSAGE_TEXT", @"")];
@ -1758,13 +1758,7 @@ typedef enum : NSUInteger {
if (collectionKey.key) { if (collectionKey.key) {
[self.messageAdapterCache removeObjectForKey:collectionKey.key]; [self.messageAdapterCache removeObjectForKey:collectionKey.key];
} }
[self.collectionView reloadItemsAtIndexPaths:@[ rowChange.indexPath ]];
// remove "delivered" from all but final message.
NSMutableArray *rowsToUpdate = [@[ rowChange.indexPath ] mutableCopy];
if (_lastDeliveredMessageIndexPath) {
[rowsToUpdate addObject:_lastDeliveredMessageIndexPath];
}
[self.collectionView reloadItemsAtIndexPaths:rowsToUpdate];
scrollToBottom = YES; scrollToBottom = YES;
break; break;
} }

Loading…
Cancel
Save