From 9a00596f9f3fe502bf07827d5ed6ddc9c4217dcf Mon Sep 17 00:00:00 2001 From: Benjamin Reis Date: Fri, 16 Feb 2018 11:01:31 +0100 Subject: [PATCH] adapt deletion message to chat rooms type --- Classes/ChatConversationView.m | 2 +- Classes/ChatsListTableView.h | 1 + Classes/ChatsListTableView.m | 27 +++++++++++++-------------- Classes/ChatsListView.m | 14 ++++++++++++-- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Classes/ChatConversationView.m b/Classes/ChatConversationView.m index 9e240acc4..722c4ccf5 100644 --- a/Classes/ChatConversationView.m +++ b/Classes/ChatConversationView.m @@ -479,7 +479,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onDeleteClick:(id)sender { LOGI(@"onDeleteClick"); - NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete and selected messages?", nil)]; + NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"Do you want to delete the selected messages?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil confirmMessage:nil diff --git a/Classes/ChatsListTableView.h b/Classes/ChatsListTableView.h index 8494c55b6..ed79f82f2 100644 --- a/Classes/ChatsListTableView.h +++ b/Classes/ChatsListTableView.h @@ -26,6 +26,7 @@ @property (nonatomic) NSInteger nbOfChatRoomToDelete; @property (nonatomic) bctbx_list_t *chatRooms; @property (weak, nonatomic) IBOutlet UIView *waitView; +@property bctbx_list_t *data; - (void)loadData; - (void)markCellAsRead:(LinphoneChatRoom *)chatRoom; diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index 1ee7949b9..069bfa5b5 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -26,16 +26,14 @@ #import "PhoneMainView.h" #import "Utils.h" -@implementation ChatsListTableView { - bctbx_list_t *data; -} +@implementation ChatsListTableView #pragma mark - Lifecycle Functions - (instancetype)init { self = super.init; if (self) { - data = nil; + _data = nil; _nbOfChatRoomToDelete = 0; _waitView.hidden = TRUE; } @@ -109,11 +107,11 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } - (void)loadData { - data = [self sortChatRooms]; + _data = [self sortChatRooms]; [super loadData]; if (IPAD) { - int idx = bctbx_list_index(data, VIEW(ChatConversationView).chatRoom); + int idx = bctbx_list_index(_data, VIEW(ChatConversationView).chatRoom); // if conversation view is using a chatroom that does not exist anymore, update it if (idx != -1) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; @@ -127,7 +125,7 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } - (void)markCellAsRead:(LinphoneChatRoom *)chatRoom { - int idx = bctbx_list_index(data, VIEW(ChatConversationView).chatRoom); + int idx = bctbx_list_index(_data, VIEW(ChatConversationView).chatRoom); NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; if (IPAD) { UIChatCell *cell = (UIChatCell *)[self.tableView cellForRowAtIndexPath:indexPath]; @@ -142,7 +140,7 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return bctbx_list_size(data); + return bctbx_list_size(_data); } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { @@ -152,7 +150,7 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo cell = [[UIChatCell alloc] initWithIdentifier:kCellId]; } - [cell setChatRoom:(LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row])]; + [cell setChatRoom:(LinphoneChatRoom *)bctbx_list_nth_data(_data, (int)[indexPath row])]; [super accessoryForCell:cell atPath:indexPath]; return cell; } @@ -162,7 +160,7 @@ static int sorted_history_comparison(LinphoneChatRoom *to_insert, LinphoneChatRo - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [super tableView:tableView didSelectRowAtIndexPath:indexPath]; if (![self isEditing]) { - LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(_data, (int)[indexPath row]); ChatConversationView *view = VIEW(ChatConversationView); view.chatRoom = chatRoom; // on iPad, force unread bubble to disappear by reloading the cell @@ -225,14 +223,15 @@ void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomStat commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { - NSString *msg = - [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete and leave this conversation?", nil)]; + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(_data, (int)[indexPath row]); + NSString *msg = (LinphoneChatRoomCapabilitiesOneToOne & linphone_chat_room_get_capabilities(chatRoom)) + ? [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete this conversation?", nil)] + : [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete and leave this conversation?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil confirmMessage:nil onCancelClick:^() {} onConfirmationClick:^() { - LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); _chatRooms = bctbx_list_new((void *)chatRoom); [self deleteChatRooms]; }]; @@ -247,7 +246,7 @@ void deletion_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomStat }]; NSArray *copy = [[NSArray alloc] initWithArray:self.selectedItems]; for (NSIndexPath *indexPath in copy) { - LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(data, (int)[indexPath row]); + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(_data, (int)[indexPath row]); _chatRooms = bctbx_list_append(_chatRooms, chatRoom); } [self deleteChatRooms]; diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index bf8e61c83..155ff1f8e 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -94,8 +94,18 @@ static UICompositeViewDescription *compositeDescription = nil; } - (IBAction)onDeleteClick:(id)sender { - NSString *msg = - [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete and leave the selected conversations?", nil)]; + BOOL group = false; + NSArray *copy = [[NSArray alloc] initWithArray:_tableController.selectedItems]; + for (NSIndexPath *indexPath in copy) { + LinphoneChatRoom *chatRoom = (LinphoneChatRoom *)bctbx_list_nth_data(_tableController.data, (int)[indexPath row]); + if (LinphoneChatRoomCapabilitiesConference & linphone_chat_room_get_capabilities(chatRoom)) { + group = true; + break; + } + } + NSString *msg = group + ? [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete and leave the selected conversations?", nil)] + : [NSString stringWithFormat:NSLocalizedString(@"Do you really want to delete the selected conversations?", nil)]; [UIConfirmationDialog ShowWithMessage:msg cancelMessage:nil confirmMessage:nil