add possibiliy to remove participant, add/remove admin and change subject of a chat room

This commit is contained in:
Benjamin Reis 2017-11-08 15:42:03 +01:00
parent 4d7b1b7984
commit 8f8805ff03
5 changed files with 60 additions and 13 deletions

View file

@ -142,6 +142,8 @@
[tableView deselectRowAtIndexPath:indexPath animated:YES];
UIChatCreateCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSInteger index = 0;
_searchBar.text = @"";
[self searchBar:_searchBar textDidChange:@""];
if(cell.selectedImage.hidden) {
if(![_contactsGroup containsObject:cell.addressLabel.text]) {
[_contactsGroup addObject:cell.addressLabel.text];
@ -210,6 +212,8 @@
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {
searchBar.showsCancelButton = (searchText.length > 0);
[self reloadDataWithFilter:searchText];
if ([searchText isEqualToString:@""])
[_searchBar resignFirstResponder];
}
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {

View file

@ -15,6 +15,10 @@
@property(nonatomic, strong) NSMutableDictionary *contacts;
@property(nonatomic, strong) NSMutableArray *admins;
@property(nonatomic) BOOL create;
@property(nonatomic) NSString *oldSubject;
@property(nonatomic, strong) NSMutableDictionary *oldContacts;
@property(nonatomic, strong) NSMutableArray *oldAdmins;
@property(nonatomic) LinphoneChatRoom *room;
@property (weak, nonatomic) IBOutlet UIIconButton *nextButton;
@property (weak, nonatomic) IBOutlet UIIconButton *backButton;

View file

@ -51,6 +51,9 @@ static UICompositeViewDescription *compositeDescription = nil;
_tableView.dataSource = self;
_tableView.delegate = self;
_admins = [[NSMutableArray alloc] init];
_oldAdmins = [[NSMutableArray alloc] init];
_oldContacts = [[NSMutableDictionary alloc] init];
_room = NULL;
}
- (void)viewWillAppear:(BOOL)animated {
@ -87,8 +90,40 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (void)onValidate {
//TODO : Apply all modifications
ChatConversationView *view = VIEW(ChatConversationView);
// Change subject if necessary
if (![_oldSubject isEqualToString:_nameLabel.text])
linphone_chat_room_set_subject(_room, _nameLabel.text.UTF8String);
// 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));
linphone_address_unref(addr);
}
// add admins if necessary
for (NSString *admin in _admins) {
if ([_oldAdmins containsObject:admin])
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);
linphone_address_unref(addr);
}
// remove admins if necessary
for (NSString *admin in _oldAdmins) {
if ([_admins containsObject:admin])
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);
linphone_address_unref(addr);
}
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
}
@ -116,6 +151,7 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (IBAction)onQuitClick:(id)sender {
linphone_chat_room_leave(_room);
}
- (IBAction)onAddClick:(id)sender {
@ -144,13 +180,15 @@ static UICompositeViewDescription *compositeDescription = nil;
cell = [[UIChatConversationInfoTableViewCell alloc] initWithIdentifier:kCellId];
}
cell.uri = _contacts.allKeys[indexPath.row];
cell.nameLabel.text = [_contacts objectForKey:cell.uri];
LinphoneAddress *addr = linphone_address_new(cell.uri.UTF8String);
cell.nameLabel.text = [FastAddressBook displayNameForAddress:addr];
cell.controllerView = self;
if(![_admins containsObject:cell.uri]) {
cell.adminLabel.enabled = FALSE;
cell.adminImage.image = [UIImage imageNamed:@"check_unselected.png"];
}
cell.adminButton.hidden = _create;
linphone_address_unref(addr);
return cell;
}

View file

@ -529,9 +529,13 @@ static UICompositeViewDescription *compositeDescription = nil;
participants = participants->next;
}
ChatConversationInfoView *view = VIEW(ChatConversationInfoView);
view.contacts = contactsDict;
view.create = FALSE;
view.admins = admins;
view.contacts = [contactsDict mutableCopy];
view.oldContacts = [contactsDict mutableCopy];
view.admins = [admins mutableCopy];
view.oldAdmins = [admins mutableCopy];
view.oldSubject = [NSString stringWithUTF8String:linphone_chat_room_get_subject(_chatRoom)];
view.room = _chatRoom;
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
}

View file

@ -62,41 +62,38 @@ static const CGFloat NOTIFIED_CELL_HEIGHT = 44;
switch (linphone_event_log_get_type(event)) {
case LinphoneEventLogTypeConferenceSubjectChanged: {
NSString *subject = [NSString stringWithUTF8String:linphone_event_log_get_subject(event)];
NSString *formatedString = [NSString stringWithFormat:@"Chat room subject changed to : %@", subject];
NSString *formatedString = [NSString stringWithFormat:@"Chat room subject has changed to : %@", subject];
eventString = NSLocalizedString(formatedString, nil);
break;
}
case LinphoneEventLogTypeConferenceParticipantAdded: {
NSString *participant = [FastAddressBook displayNameForAddress:linphone_event_log_get_participant_address(event)];
NSString *formatedString = [NSString stringWithFormat:@"%@ was added to the chat room", participant];
NSString *formatedString = [NSString stringWithFormat:@"%@ has been added to the chat room", participant];
eventString = NSLocalizedString(formatedString, nil);
break;
}
case LinphoneEventLogTypeConferenceParticipantRemoved: {
NSString *participant = [FastAddressBook displayNameForAddress:linphone_event_log_get_participant_address(event)];
NSString *formatedString = [NSString stringWithFormat:@"%@ was removed to the chat room", participant];
NSString *formatedString = [NSString stringWithFormat:@"%@ has been removed of the chat room", participant];
eventString = NSLocalizedString(formatedString, nil);
break;
}
case LinphoneEventLogTypeConferenceParticipantSetAdmin: {
NSString *participant = [FastAddressBook displayNameForAddress:linphone_event_log_get_participant_address(event)];
NSString *formatedString = [NSString stringWithFormat:@"%@ was set admin of the chat room", participant];
NSString *formatedString = [NSString stringWithFormat:@"%@ is now an admin of the chat room", participant];
eventString = NSLocalizedString(formatedString, nil);
break;
}
case LinphoneEventLogTypeConferenceParticipantUnsetAdmin: {
NSString *participant = [FastAddressBook displayNameForAddress:linphone_event_log_get_participant_address(event)];
NSString *formatedString = [NSString stringWithFormat:@"%@ is no more an admin of the chat room", participant];
NSString *formatedString = [NSString stringWithFormat:@"%@ is no longer an admin of the chat room", participant];
eventString = NSLocalizedString(formatedString, nil);
break;
}
default:
return;
}
NSString *timeString = [LinphoneUtils timeToString:linphone_event_log_get_time(event)
withFormat:LinphoneDateChatBubble];
_contactDateLabel.text = [NSString stringWithFormat:@"%@ - %@", timeString, eventString];
_contactDateLabel.text = eventString;
CGSize newSize = [_contactDateLabel.text boundingRectWithSize:CGSizeZero
options:(NSStringDrawingUsesLineFragmentOrigin |