@@ -335,16 +335,6 @@ -(void) handleDeviceRotation
335
335
336
336
-(void ) refreshDisplay
337
337
{
338
- size_t unpinnedConCntBefore = self.unpinnedContacts .count ;
339
- size_t pinnedConCntBefore = self.pinnedContacts .count ;
340
- NSMutableArray <MLContact*>* newUnpinnedContacts = [[DataLayer sharedInstance ] activeContactsWithPinned: NO ];
341
- NSMutableArray <MLContact*>* newPinnedContacts = [[DataLayer sharedInstance ] activeContactsWithPinned: YES ];
342
- if (!newUnpinnedContacts || ! newPinnedContacts)
343
- return ;
344
-
345
- int unpinnedCntDiff = (int )unpinnedConCntBefore - (int )newUnpinnedContacts.count ;
346
- int pinnedCntDiff = (int )pinnedConCntBefore - (int )newPinnedContacts.count ;
347
-
348
338
void (^resizeSections)(UITableView*, size_t , int ) = ^void (UITableView* table, size_t section, int diff){
349
339
if (diff > 0 )
350
340
{
@@ -367,6 +357,16 @@ -(void) refreshDisplay
367
357
};
368
358
369
359
dispatch_async (dispatch_get_main_queue (), ^{
360
+ size_t unpinnedConCntBefore = self.unpinnedContacts .count ;
361
+ size_t pinnedConCntBefore = self.pinnedContacts .count ;
362
+ NSMutableArray <MLContact*>* newUnpinnedContacts = [[DataLayer sharedInstance ] activeContactsWithPinned: NO ];
363
+ NSMutableArray <MLContact*>* newPinnedContacts = [[DataLayer sharedInstance ] activeContactsWithPinned: YES ];
364
+ if (!newUnpinnedContacts || !newPinnedContacts)
365
+ return ;
366
+
367
+ int unpinnedCntDiff = (int )unpinnedConCntBefore - (int )newUnpinnedContacts.count ;
368
+ int pinnedCntDiff = (int )pinnedConCntBefore - (int )newPinnedContacts.count ;
369
+
370
370
// make sure we don't display a chat view for a disabled account
371
371
if ([MLNotificationManager sharedInstance ].currentContact != nil )
372
372
{
@@ -508,7 +508,15 @@ -(void) handleNewMessage:(NSNotification*) notification
508
508
-(void ) insertOrMoveContact : (MLContact*) contact completion : (void (^ _Nullable)(BOOL finished)) completion
509
509
{
510
510
dispatch_async (dispatch_get_main_queue (), ^{
511
- [self .chatListTable performBatchUpdates: ^{
511
+ if (self.chatListTable .hasUncommittedUpdates )
512
+ {
513
+ if (completion) completion (NO );
514
+ return ;
515
+ }
516
+ [CATransaction begin ];
517
+ [UIView performWithoutAnimation: ^{
518
+ [self .chatListTable beginUpdates ];
519
+
512
520
__block NSIndexPath * indexPath = nil ;
513
521
for (size_t section = pinnedChats; section < activeChatsViewControllerSectionCnt && !indexPath; section++) {
514
522
NSMutableArray * curContactArray = [self getChatArrayForSection: section];
@@ -554,11 +562,16 @@ -(void) insertOrMoveContact:(MLContact*) contact completion:(void (^ _Nullable)(
554
562
[self .chatListTable insertRowsAtIndexPaths: @[insertAtPath] withRowAnimation: UITableViewRowAnimationRight];
555
563
// make sure to fully refresh to remove the empty dataset (yes this will trigger on first chat pinning, too, but that does no harm)
556
564
if (oldCount == 0 )
557
- [self refreshDisplay ];
565
+ dispatch_async (dispatch_get_main_queue (), ^{
566
+ [self refreshDisplay ];
567
+ });
558
568
}
559
- } completion: ^( BOOL finished) {
560
- if (completion) completion (finished) ;
569
+
570
+ [ self .chatListTable endUpdates ] ;
561
571
}];
572
+ [CATransaction commit ];
573
+ [self .chatListTable reloadEmptyDataSet ];
574
+ if (completion) completion (YES );
562
575
});
563
576
}
564
577
0 commit comments