diff --git a/Classes/Base.lproj/ChatsListView.xib b/Classes/Base.lproj/ChatsListView.xib index facfd51be..54d4b1188 100644 --- a/Classes/Base.lproj/ChatsListView.xib +++ b/Classes/Base.lproj/ChatsListView.xib @@ -1,8 +1,12 @@ - - + + + + + - + + @@ -11,6 +15,7 @@ + @@ -29,17 +34,15 @@ - - - + - - + - + @@ -144,19 +140,28 @@ + - - - - + + @@ -176,16 +181,16 @@ - - + + - - - - - - - + + + + + + + diff --git a/Classes/ChatsListTableView.h b/Classes/ChatsListTableView.h index 79f50c9ee..8494c55b6 100644 --- a/Classes/ChatsListTableView.h +++ b/Classes/ChatsListTableView.h @@ -23,6 +23,10 @@ @interface ChatsListTableView : UICheckBoxTableView +@property (nonatomic) NSInteger nbOfChatRoomToDelete; +@property (nonatomic) bctbx_list_t *chatRooms; +@property (weak, nonatomic) IBOutlet UIView *waitView; + - (void)loadData; - (void)markCellAsRead:(LinphoneChatRoom *)chatRoom; @end diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index b2b81d8c7..89fe0a2eb 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -36,6 +36,8 @@ self = super.init; if (self) { data = nil; + _nbOfChatRoomToDelete = 0; + _waitView.hidden = TRUE; } return self; } @@ -46,6 +48,7 @@ [super viewWillAppear:animated]; self.tableView.accessibilityIdentifier = @"Chat list"; [self loadData]; + _chatRooms = NULL; } - (void)viewDidAppear:(BOOL)animated { @@ -57,6 +60,19 @@ } } +- (void)viewWillDisappear:(BOOL)animated { + while (_chatRooms) { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)_chatRooms->data; + if (!chatRoom) + continue; + + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(chatRoom); + linphone_chat_room_cbs_set_state_changed(cbs, NULL); + linphone_chat_room_cbs_set_user_data(cbs, NULL); + _chatRooms = _chatRooms->next; + } +} + - (void)layoutSubviews { [self.tableView layoutSubviews]; @@ -162,13 +178,35 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } } -- (void)tableView:(UITableView *)tableView - commitEditingStyle:(UITableViewCellEditingStyle)editingStyle - forRowAtIndexPath:(NSIndexPath *)indexPath { - if (editingStyle == UITableViewCellEditingStyleDelete) { - [tableView beginUpdates]; +void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) { + ChatsListTableView *view = (__bridge ChatsListTableView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr)) ?: NULL; + if (newState == LinphoneChatRoomStateDeleted || newState == LinphoneChatRoomStateTerminationFailed) { + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(cr); + linphone_chat_room_cbs_set_state_changed(cbs, NULL); + linphone_chat_room_cbs_set_user_data(cbs, NULL); + view.nbOfChatRoomToDelete--; + } + + if (view.nbOfChatRoomToDelete == 0) { + // will force a call to [self loadData] + [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:view]; + view.waitView.hidden = TRUE; + } +} + +- (void) deleteChatRooms { + _waitView.hidden = FALSE; + bctbx_list_t *chatRooms = bctbx_list_copy(_chatRooms); + while (chatRooms) { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)chatRooms->data; + if (!chatRoom) + continue; + + _nbOfChatRoomToDelete++; + LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(chatRoom); + linphone_chat_room_cbs_set_state_changed(cbs, deletion_chat_room_state_changed); + linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self); - LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); FileTransferDelegate *ftdToDelete = nil; for (FileTransferDelegate *ftd in [LinphoneManager.instance fileTransferDelegates]) { if (linphone_chat_message_get_chat_room(ftd.message) == chatRoom) { @@ -178,36 +216,35 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } [ftdToDelete cancel]; - linphone_core_delete_chat_room(linphone_chat_room_get_core(chatRoom), chatRoom); - data = bctbx_list_remove(data, chatRoom); + linphone_core_delete_chat_room(LC, chatRoom); + chatRooms = chatRooms->next; + } +} - // will force a call to [self loadData] - [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:self]; - - [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] - withRowAnimation:UITableViewRowAnimationFade]; - [tableView endUpdates]; +- (void)tableView:(UITableView *)tableView + commitEditingStyle:(UITableViewCellEditingStyle)editingStyle + forRowAtIndexPath:(NSIndexPath *)indexPath { + if (editingStyle == UITableViewCellEditingStyleDelete) { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); + _chatRooms = bctbx_list_new((void *)chatRoom); + [self deleteChatRooms]; } } - (void)removeSelectionUsing:(void (^)(NSIndexPath *))remover { - [super removeSelectionUsing:^(NSIndexPath *indexPath) { - LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); - FileTransferDelegate *ftdToDelete = nil; - for (FileTransferDelegate *ftd in [LinphoneManager.instance fileTransferDelegates]) { - if (linphone_chat_message_get_chat_room(ftd.message) == chatRoom) { - ftdToDelete = ftd; - break; - } - } - [ftdToDelete cancel]; - - linphone_core_delete_chat_room(linphone_chat_room_get_core(chatRoom), chatRoom); - data = bctbx_list_remove(data, chatRoom); - - // will force a call to [self loadData] - [NSNotificationCenter.defaultCenter postNotificationName:kLinphoneMessageReceived object:self]; + _chatRooms = NULL; + // we must iterate through selected items in reverse order + [self.selectedItems sortUsingComparator:^(NSIndexPath *obj1, NSIndexPath *obj2) { + return [obj2 compare:obj1]; }]; + NSArray *copy = [[NSArray alloc] initWithArray:self.selectedItems]; + for (NSIndexPath *indexPath in copy) { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); + _chatRooms = _chatRooms ? bctbx_list_append(_chatRooms, chatRoom) : bctbx_list_new(chatRoom); + } + [self deleteChatRooms]; + [self.selectedItems removeAllObjects]; + [self setEditing:NO animated:YES]; } @end diff --git a/Classes/ChatsListView.h b/Classes/ChatsListView.h index 4021f21bb..07ec17698 100644 --- a/Classes/ChatsListView.h +++ b/Classes/ChatsListView.h @@ -31,6 +31,7 @@ @property(nonatomic, strong) IBOutlet ChatsListTableView *tableController; @property(weak, nonatomic) IBOutlet UIButton *addButton; @property(weak, nonatomic) IBOutlet UIBackToCallButton *backToCallButton; +@property (weak, nonatomic) IBOutlet UIView *waitView; - (IBAction)onAddClick:(id)event; - (IBAction)onEditionChangeClick:(id)sender; diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index 5ab23413c..1967f1999 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -36,6 +36,7 @@ name:kLinphoneCallUpdate object:nil]; [_backToCallButton update]; + self.tableController.waitView = _waitView; [self setEditing:NO]; } @@ -102,7 +103,6 @@ static UICompositeViewDescription *compositeDescription = nil; } onConfirmationClick:^() { [_tableController removeSelectionUsing:nil]; - [_tableController loadData]; [self onEditionChangeClick:nil]; }]; }