Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.

Commit 4ace823

Browse files
committed
Fix dead lock when send message
1 parent b06a9cf commit 4ace823

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

ChatKit/Class/Module/Conversation/Model/LCCKConversationViewModel.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,6 @@ - (void)preloadMessageToTableView:(id)aMessage callback:(LCCKVoidBlock)callback
712712
NSUInteger newLastMessageCout = self.dataArray.count;
713713
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.dataArray.count - 1 inSection:0];
714714
[self.delegate messageSendStateChanged:LCCKMessageSendStateSending withProgress:0.0f forIndex:indexPath.row];
715-
LCCKLock();
716715
NSMutableArray *indexPaths = [NSMutableArray arrayWithObject:indexPath];
717716
NSUInteger additionItemsCount = newLastMessageCout - oldLastMessageCount;
718717
if (additionItemsCount > 1) {
@@ -721,12 +720,17 @@ - (void)preloadMessageToTableView:(id)aMessage callback:(LCCKVoidBlock)callback
721720
[indexPaths addObject:indexPath];
722721
}
723722
}
724-
dispatch_async(dispatch_get_main_queue(),^{
723+
if (NSThread.isMainThread) {
725724
[self.parentConversationViewController.tableView insertRowsAtIndexPaths:[indexPaths copy] withRowAnimation:UITableViewRowAnimationNone];
726-
LCCKUnlock();
727725
[self.parentConversationViewController scrollToBottomAnimated:YES];
728726
!callback ?: callback();
729-
});
727+
} else {
728+
dispatch_async(dispatch_get_main_queue(), ^{
729+
[self.parentConversationViewController.tableView insertRowsAtIndexPaths:[indexPaths copy] withRowAnimation:UITableViewRowAnimationNone];
730+
[self.parentConversationViewController scrollToBottomAnimated:YES];
731+
!callback ?: callback();
732+
});
733+
}
730734
}
731735

732736
#pragma mark - Getters

0 commit comments

Comments
 (0)