diff --git a/Classes/ChatConversationTableView.m b/Classes/ChatConversationTableView.m index c8e4812be..f8b01acdc 100644 --- a/Classes/ChatConversationTableView.m +++ b/Classes/ChatConversationTableView.m @@ -190,27 +190,32 @@ #pragma mark - UITableViewDelegate Functions +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { + LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]); + return [UIChatBubbleTextCell ViewHeightForMessage:chat withWidth:self.view.frame.size.width].height; +} + - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { [tableView beginUpdates]; LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]); - if (chat) { - linphone_chat_room_delete_message(chatRoom, chat); - messageList = ms_list_remove(messageList, chat); + linphone_chat_room_delete_message(chatRoom, chat); + messageList = ms_list_remove(messageList, chat); - [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] - withRowAnimation:UITableViewRowAnimationBottom]; - } + [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] + withRowAnimation:UITableViewRowAnimationBottom]; [tableView endUpdates]; } } -- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { - LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]); - return [UIChatBubbleTextCell ViewHeightForMessage:chat withWidth:self.view.frame.size.width].height; +- (void)removeSelectionUsing:(void (^)(NSIndexPath *))remover { + [super removeSelectionUsing:^(NSIndexPath *indexPath) { + LinphoneChatMessage *chat = ms_list_nth_data(messageList, (int)[indexPath row]); + linphone_chat_room_delete_message(chatRoom, chat); + messageList = ms_list_remove(messageList, chat); + }]; } - @end diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index c0d33d438..def333066 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -498,7 +498,7 @@ static UICompositeViewDescription *compositeDescription = nil; [self onEditionChangeClick:nil]; } onConfirmationClick:^() { - [_tableController removeSelection]; + [_tableController removeSelectionUsing:nil]; [_tableController loadData]; [self onEditionChangeClick:nil]; }]; diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 31050eada..136b442f8 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -176,4 +176,30 @@ static void chatTable_free_chatrooms(void *data) { } } +- (void)removeSelectionUsing:(void (^)(NSIndexPath *))remover { + [super removeSelectionUsing:^(NSIndexPath *indexPath) { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)ms_list_nth_data(data, (int)[indexPath row]); + LinphoneChatMessage *last_msg = linphone_chat_room_get_user_data(chatRoom); + if (last_msg) { + linphone_chat_message_unref(last_msg); + linphone_chat_room_set_user_data(chatRoom, NULL); + } + + 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 = ms_list_remove(data, chatRoom); + + // will force a call to [self loadData] + [[NSNotificationCenter defaultCenter] postNotificationName:kLinphoneMessageReceived object:self]; + }]; +} + @end diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index b6f3c83b1..e0ac2ac7b 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -88,7 +88,7 @@ static UICompositeViewDescription *compositeDescription = nil; [self onEditionChangeClick:nil]; } onConfirmationClick:^() { - [_tableController removeSelection]; + [_tableController removeSelectionUsing:nil]; [_tableController loadData]; [self onEditionChangeClick:nil]; }]; diff --git a/Classes/ContactsListTableView.m b/Classes/ContactsListTableView.m index b75715ebb..063e6c896 100644 --- a/Classes/ContactsListTableView.m +++ b/Classes/ContactsListTableView.m @@ -247,4 +247,20 @@ static void sync_address_book(ABAddressBookRef addressBook, CFDictionaryRef info ABAddressBookRegisterExternalChangeCallback(addressBook, sync_address_book, (__bridge void *)(self)); } } + +- (void)removeSelectionUsing:(void (^)(NSIndexPath *))remover { + [super removeSelectionUsing:^(NSIndexPath *indexPath) { + ABAddressBookUnregisterExternalChangeCallback(addressBook, sync_address_book, (__bridge void *)(self)); + OrderedDictionary *subDic = [addressBookMap objectForKey:[addressBookMap keyAtIndex:[indexPath section]]]; + NSString *key = [[subDic allKeys] objectAtIndex:[indexPath row]]; + ABRecordRef contact = (__bridge ABRecordRef)([subDic objectForKey:key]); + NSString *firstChar = [[self displayNameForContact:contact] substringToIndex:1]; + [[addressBookMap objectForKey:firstChar] removeObjectForKey:[self displayNameForContact:contact]]; + if ([self.tableView numberOfRowsInSection:indexPath.section] == 1) { + [addressBookMap removeObjectForKey:firstChar]; + } + [[[LinphoneManager instance] fastAddressBook] removeContact:contact]; + }]; +} + @end diff --git a/Classes/ContactsListView.m b/Classes/ContactsListView.m index e51a4ce76..a2bf67141 100644 --- a/Classes/ContactsListView.m +++ b/Classes/ContactsListView.m @@ -202,7 +202,7 @@ static UICompositeViewDescription *compositeDescription = nil; [self onEditionChangeClick:nil]; } onConfirmationClick:^() { - [tableController removeSelection]; + [tableController removeSelectionUsing:nil]; [tableController loadData]; }]; } diff --git a/Classes/HistoryListTableView.m b/Classes/HistoryListTableView.m index ece2606a8..86140a17f 100644 --- a/Classes/HistoryListTableView.m +++ b/Classes/HistoryListTableView.m @@ -222,4 +222,17 @@ } } +- (void)removeSelectionUsing:(void (^)(NSIndexPath *))remover { + [super removeSelectionUsing:^(NSIndexPath *indexPath) { + id log = [_sections objectForKey:_sortedDays[indexPath.section]][indexPath.row]; + LinphoneCallLog *callLog = [log pointerValue]; + linphone_core_remove_call_log([LinphoneManager getLc], callLog); + [[_sections objectForKey:_sortedDays[indexPath.section]] removeObject:log]; + if (((NSArray *)[_sections objectForKey:_sortedDays[indexPath.section]]).count == 0) { + [_sections removeObjectForKey:_sortedDays[indexPath.section]]; + [_sortedDays removeObjectAtIndex:indexPath.section]; + } + }]; +} + @end diff --git a/Classes/HistoryListView.m b/Classes/HistoryListView.m index e84077530..eb4296257 100644 --- a/Classes/HistoryListView.m +++ b/Classes/HistoryListView.m @@ -99,7 +99,7 @@ static UICompositeViewDescription *compositeDescription = nil; [self onEditionChangeClick:nil]; } onConfirmationClick:^() { - [_tableController removeSelection]; + [_tableController removeSelectionUsing:nil]; [_tableController loadData]; [self onEditionChangeClick:nil]; }]; diff --git a/Classes/LinphoneUI/UICheckBoxTableViewController.h b/Classes/LinphoneUI/UICheckBoxTableViewController.h index bf273fc0e..19630f714 100644 --- a/Classes/LinphoneUI/UICheckBoxTableViewController.h +++ b/Classes/LinphoneUI/UICheckBoxTableViewController.h @@ -21,7 +21,7 @@ - (void)loadData; - (void)accessoryForCell:(UITableViewCell *)cell atPath:(NSIndexPath *)indexPath; -- (void)removeSelection; +- (void)removeSelectionUsing:(void (^)(NSIndexPath *indexPath))remover; - (IBAction)onSelectionToggle:(id)sender; - (IBAction)onEditClick:(id)sender; diff --git a/Classes/LinphoneUI/UICheckBoxTableViewController.m b/Classes/LinphoneUI/UICheckBoxTableViewController.m index 59511428a..6a3779b87 100644 --- a/Classes/LinphoneUI/UICheckBoxTableViewController.m +++ b/Classes/LinphoneUI/UICheckBoxTableViewController.m @@ -107,16 +107,20 @@ _editButton.enabled = _emptyView.hidden = ([self totalNumberOfItems] > 0); } -- (void)removeSelection { +- (void)removeSelectionUsing:(void (^)(NSIndexPath *indexPath))remover { // we must iterate through selected items in reverse order [_selectedItems sortUsingComparator:^(NSIndexPath *obj1, NSIndexPath *obj2) { return [obj2 compare:obj1]; }]; NSArray *copy = [[NSArray alloc] initWithArray:_selectedItems]; for (NSIndexPath *indexPath in copy) { - [self tableView:self.tableView - commitEditingStyle:UITableViewCellEditingStyleDelete - forRowAtIndexPath:indexPath]; + if (remover) { + remover(indexPath); + } else { + [self tableView:self.tableView + commitEditingStyle:UITableViewCellEditingStyleDelete + forRowAtIndexPath:indexPath]; + } } [_selectedItems removeAllObjects]; [self setEditing:NO animated:YES];