diff --git a/Classes/ChatConversationCreateTableView.m b/Classes/ChatConversationCreateTableView.m index 146e6524b..67e5644cf 100644 --- a/Classes/ChatConversationCreateTableView.m +++ b/Classes/ChatConversationCreateTableView.m @@ -25,7 +25,6 @@ _allContacts = [[NSDictionary alloc] initWithDictionary:LinphoneManager.instance.fastAddressBook.addressBookMap]; if(_notFirstTime) { - _notFirstTime = FALSE; for(NSString *addr in _contactsGroup) { [_collectionView registerClass:UIChatCreateCollectionViewCell.class forCellWithReuseIdentifier:addr]; } diff --git a/Classes/ChatConversationCreateView.m b/Classes/ChatConversationCreateView.m index 599971afd..ea401a4c8 100644 --- a/Classes/ChatConversationCreateView.m +++ b/Classes/ChatConversationCreateView.m @@ -73,14 +73,6 @@ static UICompositeViewDescription *compositeDescription = nil; _tableController.isForEditing = _isForEditing; } -#pragma mark - searchBar delegate - -- (IBAction)onBackClick:(id)sender { - [_tableController.contactsDict removeAllObjects]; - [_tableController.contactsGroup removeAllObjects]; - [PhoneMainView.instance popToView:ChatsListView.compositeViewDescription]; -} - #pragma mark - Chat room functions void create_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) { @@ -117,28 +109,27 @@ void create_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState #pragma mark - Buttons signals +- (IBAction)onBackClick:(id)sender { + [_tableController.contactsDict removeAllObjects]; + [_tableController.contactsGroup removeAllObjects]; + [PhoneMainView.instance popToView:ChatsListView.compositeViewDescription]; +} + - (IBAction)onNextClick:(id)sender { - if (_tableController.contactsGroup.count == 1) { + if (_tableController.contactsGroup.count == 1 && !_isForEditing) { [self createChatRoom]; return; } - ChatConversationInfoView *view = VIEW(ChatConversationInfoView); - if (!_isForEditing) - view.contacts = _tableController.contactsDict; - else { - for (NSString *uri in _tableController.contactsDict) { - [view.contacts setObject:[_tableController.contactsDict objectForKey:uri] forKey:uri]; - } - } + ChatConversationInfoView *view = VIEW(ChatConversationInfoView); + view.contacts = _tableController.contactsDict; view.create = !_isForEditing; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } - (void)dismissKeyboards { - if ([self.tableController.searchBar isFirstResponder]) { + if ([self.tableController.searchBar isFirstResponder]) [self.tableController.searchBar resignFirstResponder]; - } } #pragma mark - Contacts filter @@ -192,7 +183,9 @@ typedef enum { ContactsAll, ContactsLinphone, ContactsMAX } ContactsCategory; UIChatCreateCollectionViewCell *cell = (UIChatCreateCollectionViewCell *)[_collectionView dequeueReusableCellWithReuseIdentifier:uri forIndexPath:indexPath]; cell.controller = self; cell.uri = uri; - cell = [cell initWithName:_tableController.contactsDict[uri]]; + LinphoneAddress *addr = linphone_address_new(uri.UTF8String); + cell = [cell initWithName:[FastAddressBook displayNameForAddress:addr]]; + linphone_address_unref(addr); return cell; } diff --git a/Classes/ChatConversationInfoView.h b/Classes/ChatConversationInfoView.h index 5fd3eea92..9893e83fb 100644 --- a/Classes/ChatConversationInfoView.h +++ b/Classes/ChatConversationInfoView.h @@ -15,6 +15,7 @@ @property(nonatomic, strong) NSMutableDictionary *contacts; @property(nonatomic, strong) NSMutableArray *admins; @property(nonatomic) BOOL create; +@property(nonatomic) BOOL imAdmin; @property(nonatomic) NSString *oldSubject; @property(nonatomic, strong) NSMutableDictionary *oldContacts; @property(nonatomic, strong) NSMutableArray *oldAdmins; @@ -23,6 +24,7 @@ @property (weak, nonatomic) IBOutlet UIIconButton *nextButton; @property (weak, nonatomic) IBOutlet UIIconButton *backButton; @property (weak, nonatomic) IBOutlet UIRoundBorderedButton *quitButton; +@property (weak, nonatomic) IBOutlet UIIconButton *addButton; @property (weak, nonatomic) IBOutlet UITextField *nameLabel; @property (weak, nonatomic) IBOutlet UITableView *tableView; diff --git a/Classes/ChatConversationInfoView.m b/Classes/ChatConversationInfoView.m index 36191ba28..b91a87a4a 100644 --- a/Classes/ChatConversationInfoView.m +++ b/Classes/ChatConversationInfoView.m @@ -58,9 +58,31 @@ static UICompositeViewDescription *compositeDescription = nil; - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; + + if (_room) + _nameLabel.text = linphone_chat_room_get_subject(_room) + ? [NSString stringWithUTF8String:linphone_chat_room_get_subject(_room)] + : @""; _nextButton.enabled = _nameLabel.text.length > 0 && _contacts.count > 0; + LinphoneParticipant *me = _room ? linphone_chat_room_get_me(_room) : NULL; + _imAdmin = me ? linphone_participant_is_admin(me) : false; + _quitButton.hidden = _create || (me == NULL); + _nameLabel.enabled = _create || _imAdmin; + _addButton.hidden = !_create && !_imAdmin; + _nextButton.hidden = !_create && !_imAdmin; + + CGFloat height = _quitButton.hidden + ? self.view.frame.size.height - _tableView.frame.origin.y + : _quitButton.frame.origin.y - _tableView.frame.origin.y - 10; + + [_tableView setFrame:CGRectMake( + _tableView.frame.origin.x, + _tableView.frame.origin.y, + _tableView.frame.size.width, + height + )]; + [_tableView reloadData]; - _quitButton.hidden = _create; } #pragma mark - next functions @@ -95,13 +117,27 @@ static UICompositeViewDescription *compositeDescription = nil; if (![_oldSubject isEqualToString:_nameLabel.text]) linphone_chat_room_set_subject(_room, _nameLabel.text.UTF8String); + // Add participants if necessary + for (NSString *uri in _contacts.allKeys) { + if ([_oldContacts objectForKey:uri]) + continue; + + LinphoneAddress *addr = linphone_address_new(uri.UTF8String); + linphone_chat_room_add_participant(_room, addr); + linphone_address_unref(addr); + } + // Remove participants if necessary for (NSString *uri in _oldContacts.allKeys) { if ([_contacts objectForKey:uri]) continue; LinphoneAddress *addr = linphone_address_new(uri.UTF8String); - linphone_chat_room_remove_participant(_room, linphone_chat_room_find_participant(_room, addr)); + LinphoneParticipant *participant = linphone_chat_room_find_participant(_room, addr); + if (!participant) + continue; + + linphone_chat_room_remove_participant(_room, participant); linphone_address_unref(addr); } @@ -111,7 +147,11 @@ static UICompositeViewDescription *compositeDescription = nil; continue; LinphoneAddress *addr = linphone_address_new(admin.UTF8String); - linphone_chat_room_set_participant_admin_status(_room, linphone_chat_room_find_participant(_room, linphone_address_new(admin.UTF8String)), true); + LinphoneParticipant *participant = linphone_chat_room_find_participant(_room, addr); + if (!participant) + continue; + + linphone_chat_room_set_participant_admin_status(_room, participant, true); linphone_address_unref(addr); } @@ -121,7 +161,11 @@ static UICompositeViewDescription *compositeDescription = nil; continue; LinphoneAddress *addr = linphone_address_new(admin.UTF8String); - linphone_chat_room_set_participant_admin_status(_room, linphone_chat_room_find_participant(_room, linphone_address_new(admin.UTF8String)), false); + LinphoneParticipant *participant = linphone_chat_room_find_participant(_room, addr); + if (!participant) + continue; + + linphone_chat_room_set_participant_admin_status(_room, participant, false); linphone_address_unref(addr); } [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; @@ -161,8 +205,8 @@ static UICompositeViewDescription *compositeDescription = nil; ChatConversationCreateView *view = VIEW(ChatConversationCreateView); view.tableController.notFirstTime = TRUE; view.isForEditing = !_create; - [view.tableController.contactsDict removeAllObjects]; - [view.tableController.contactsGroup removeAllObjects]; + view.tableController.contactsDict = _contacts; + view.tableController.contactsGroup = [[_contacts allKeys] mutableCopy]; [PhoneMainView.instance popToView:view.compositeViewDescription]; } @@ -190,8 +234,12 @@ static UICompositeViewDescription *compositeDescription = nil; cell.adminLabel.enabled = FALSE; cell.adminImage.image = [UIImage imageNamed:@"check_unselected.png"]; } - cell.adminButton.hidden = _create; + cell.adminButton.hidden = _create; // (linphone_chat_room_find_participant(_room, addr) == NULL) ? linphone_address_unref(addr); + + cell.adminButton.hidden = !_imAdmin; + cell.removeButton.hidden = !_create && !_imAdmin; + return cell; } diff --git a/Classes/ChatConversationInfoView.xib b/Classes/ChatConversationInfoView.xib index e99868848..140074296 100644 --- a/Classes/ChatConversationInfoView.xib +++ b/Classes/ChatConversationInfoView.xib @@ -1,22 +1,23 @@ - + - + + - + diff --git a/Classes/ChatsListTableView.m b/Classes/ChatsListTableView.m index bca7677a4..60612b073 100644 --- a/Classes/ChatsListTableView.m +++ b/Classes/ChatsListTableView.m @@ -140,7 +140,9 @@ static void chatTable_free_chatrooms(void *data) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:idx inSection:0]; [self.tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; } else if (![self selectFirstRow]) { - [PhoneMainView.instance changeCurrentView:ChatConversationCreateView.compositeViewDescription]; + ChatConversationCreateView *view = VIEW(ChatConversationCreateView); + view.tableController.notFirstTime = FALSE; + [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } } } diff --git a/Classes/ChatsListView.m b/Classes/ChatsListView.m index bac12b035..5ab23413c 100644 --- a/Classes/ChatsListView.m +++ b/Classes/ChatsListView.m @@ -82,6 +82,7 @@ static UICompositeViewDescription *compositeDescription = nil; - (IBAction)onAddClick:(id)event { ChatConversationCreateView *view = VIEW(ChatConversationCreateView); view.isForEditing = false; + view.tableController.notFirstTime = FALSE; [PhoneMainView.instance changeCurrentView:view.compositeViewDescription]; } diff --git a/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.h b/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.h index 07390ffaa..275ace4dd 100644 --- a/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.h +++ b/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.h @@ -10,6 +10,7 @@ @interface UIChatConversationInfoTableViewCell : UITableViewCell +@property (weak, nonatomic) IBOutlet UIIconButton *removeButton; @property (weak, nonatomic) IBOutlet UIView *adminButton; @property (weak, nonatomic) IBOutlet UILabel *adminLabel; @property (weak, nonatomic) IBOutlet UIImageView *adminImage; diff --git a/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.xib b/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.xib index 39fa1f379..acf1ca654 100644 --- a/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.xib +++ b/Classes/LinphoneUI/UIChatConversationInfoTableViewCell.xib @@ -1,11 +1,11 @@ - + - + @@ -15,11 +15,11 @@ - +