dynamically change ChatConversationInfoView when another admin changes the chat room

This commit is contained in:
Benjamin Reis 2017-11-13 11:40:41 +01:00
parent dfcc3642d5
commit 6fad67f9e3
10 changed files with 98 additions and 45 deletions

View file

@ -13,7 +13,6 @@
@property(nonatomic) Boolean allFilter;
@property(nonatomic) Boolean notFirstTime;
@property(nonatomic, strong) NSMutableArray *contactsGroup;
@property(nonatomic, strong) NSMutableDictionary *contactsDict;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;
@property (weak, nonatomic) IBOutlet UIIconButton *controllerNextButton;

View file

@ -32,7 +32,6 @@
}
_contacts = [[NSMutableDictionary alloc] initWithCapacity:_allContacts.count];
_contactsGroup = [[NSMutableArray alloc] init];
_contactsDict = [[NSMutableDictionary alloc] init];
_allFilter = TRUE;
[_searchBar setText:@""];
[self searchBar:_searchBar textDidChange:_searchBar.text];
@ -146,14 +145,13 @@
if(cell.selectedImage.hidden) {
if(![_contactsGroup containsObject:cell.addressLabel.text]) {
[_contactsGroup addObject:cell.addressLabel.text];
_contactsDict[cell.addressLabel.text] = cell.displayNameLabel.text;
[_collectionView registerClass:UIChatCreateCollectionViewCell.class forCellWithReuseIdentifier:cell.addressLabel.text];
}
} else if([_contactsGroup containsObject:cell.addressLabel.text]) {
index = (NSInteger)[_contactsGroup indexOfObject:cell.addressLabel.text];
[_contactsGroup removeObject:cell.addressLabel.text];
if(index == _contactsGroup.count) index = index-1;
[_contactsDict removeObjectForKey:cell.addressLabel.text];
if(index == _contactsGroup.count)
index = index-1;
}
cell.selectedImage.hidden = !cell.selectedImage.hidden;
_controllerNextButton.enabled = (_contactsGroup.count > 0) || _isForEditing;

View file

@ -102,7 +102,7 @@ void create_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState
- (void)createChatRoom {
_waitView.hidden = NO;
LinphoneChatRoom *room = linphone_core_create_client_group_chat_room(LC, "dummy subject");
NSString *addr = _tableController.contactsDict.allKeys[0];
NSString *addr = _tableController.contactsGroup[0];
LinphoneAddress *linphoneAddress = linphone_address_new(addr.UTF8String);
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(room);
linphone_chat_room_cbs_set_state_changed(cbs, create_chat_room_state_changed);
@ -115,7 +115,6 @@ 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];
}
@ -127,7 +126,7 @@ void create_chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState
}
ChatConversationInfoView *view = VIEW(ChatConversationInfoView);
view.contacts = _tableController.contactsDict;
view.contacts = _tableController.contactsGroup;
view.create = !_isForEditing;
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
}

View file

@ -12,13 +12,13 @@
@interface ChatConversationInfoView : UIViewController <UICompositeViewDelegate, UIGestureRecognizerDelegate, UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>
@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 *contacts;
@property(nonatomic, strong) NSMutableArray *admins;
@property(nonatomic, strong) NSMutableArray *oldContacts;
@property(nonatomic, strong) NSMutableArray *oldAdmins;
@property(nonatomic) NSString *oldSubject;
@property(nonatomic) LinphoneChatRoom *room;
@property (weak, nonatomic) IBOutlet UIIconButton *nextButton;

View file

@ -52,7 +52,7 @@ static UICompositeViewDescription *compositeDescription = nil;
_tableView.delegate = self;
_admins = [[NSMutableArray alloc] init];
_oldAdmins = [[NSMutableArray alloc] init];
_oldContacts = [[NSMutableDictionary alloc] init];
_oldContacts = [[NSMutableArray alloc] init];
_room = NULL;
}
@ -85,6 +85,16 @@ static UICompositeViewDescription *compositeDescription = nil;
height
)];
if (_room) {
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_room);
linphone_chat_room_cbs_set_state_changed(cbs, chat_room_state_changed);
linphone_chat_room_cbs_set_subject_changed(cbs, chat_room_subject_changed);
linphone_chat_room_cbs_set_participant_added(cbs, chat_room_participant_added);
linphone_chat_room_cbs_set_participant_removed(cbs, chat_room_participant_removed);
linphone_chat_room_cbs_set_participant_admin_status_changed(cbs, chat_room_participant_admin_status_changed);
linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self);
}
[_tableView reloadData];
}
@ -100,7 +110,7 @@ static UICompositeViewDescription *compositeDescription = nil;
linphone_chat_room_cbs_set_state_changed(cbs, chat_room_state_changed);
linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self);
bctbx_list_t *addresses = NULL;
for(NSString *addr in _contacts.allKeys) {
for(NSString *addr in _contacts) {
LinphoneAddress *linphoneAddress = linphone_address_new(addr.UTF8String);
if (!linphoneAddress)
continue;
@ -123,8 +133,8 @@ static UICompositeViewDescription *compositeDescription = nil;
// Add participants if necessary
bctbx_list_t *addedPartipants = NULL;
for (NSString *uri in _contacts.allKeys) {
if ([_oldContacts objectForKey:uri])
for (NSString *uri in _contacts) {
if ([_oldContacts containsObject:uri])
continue;
LinphoneAddress *addr = linphone_address_new(uri.UTF8String);
@ -141,8 +151,8 @@ static UICompositeViewDescription *compositeDescription = nil;
// Remove participants if necessary
bctbx_list_t *removedPartipants = NULL;
for (NSString *uri in _oldContacts.allKeys) {
if ([_contacts objectForKey:uri])
for (NSString *uri in _oldContacts) {
if ([_contacts containsObject:uri])
continue;
LinphoneAddress *addr = linphone_address_new(uri.UTF8String);
@ -204,8 +214,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (IBAction)onBackClick:(id)sender {
if(_create) {
ChatConversationCreateView *view = VIEW(ChatConversationCreateView);
view.tableController.contactsDict = _contacts;
view.tableController.contactsGroup = [[_contacts allKeys] mutableCopy];
view.tableController.contactsGroup = [_contacts mutableCopy];
view.tableController.notFirstTime = TRUE;
view.isForEditing = FALSE;
[PhoneMainView.instance popToView:view.compositeViewDescription];
@ -216,9 +225,6 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (IBAction)onQuitClick:(id)sender {
LinphoneChatRoomCbs *cbs = linphone_chat_room_get_callbacks(_room);
linphone_chat_room_cbs_set_user_data(cbs, (__bridge void*)self);
linphone_chat_room_cbs_set_state_changed(cbs, chat_room_state_changed);
linphone_chat_room_leave(_room);
}
@ -226,8 +232,7 @@ static UICompositeViewDescription *compositeDescription = nil;
ChatConversationCreateView *view = VIEW(ChatConversationCreateView);
view.tableController.notFirstTime = TRUE;
view.isForEditing = !_create;
view.tableController.contactsDict = _contacts;
view.tableController.contactsGroup = [[_contacts allKeys] mutableCopy];
view.tableController.contactsGroup = [_contacts mutableCopy];
[PhoneMainView.instance popToView:view.compositeViewDescription];
}
@ -247,7 +252,7 @@ static UICompositeViewDescription *compositeDescription = nil;
if (cell == nil) {
cell = [[UIChatConversationInfoTableViewCell alloc] initWithIdentifier:kCellId];
}
cell.uri = _contacts.allKeys[indexPath.row];
cell.uri = _contacts[indexPath.row];
LinphoneAddress *addr = linphone_address_new(cell.uri.UTF8String);
cell.nameLabel.text = [FastAddressBook displayNameForAddress:addr];
[cell.avatarImage setImage:[FastAddressBook imageForAddress:addr] bordered:YES withRoundedRadius:YES];
@ -256,11 +261,10 @@ static UICompositeViewDescription *compositeDescription = nil;
cell.adminLabel.enabled = FALSE;
cell.adminImage.image = [UIImage imageNamed:@"check_unselected.png"];
}
cell.adminButton.hidden = _create; // (linphone_chat_room_find_participant(_room, addr) == NULL) ?
linphone_address_unref(addr);
cell.adminButton.hidden = !_imAdmin;
cell.adminButton.hidden = _create || (!_imAdmin && !cell.adminLabel.enabled);
cell.adminButton.userInteractionEnabled = _imAdmin;
cell.removeButton.hidden = !_create && !_imAdmin;
linphone_address_unref(addr);
return cell;
}
@ -290,6 +294,25 @@ static UICompositeViewDescription *compositeDescription = nil;
[PhoneMainView.instance changeCurrentView:view.compositeViewDescription];
}
- (void)myAdminStatusChanged:(BOOL)admin {
NSString *message = admin
? NSLocalizedString(@"You are now an admin of the chat room", nil)
: NSLocalizedString(@"You are no longer an admin of the chat room", nil);
static UIAlertController *alertView;
// avoid having multiple popups
[PhoneMainView.instance dismissViewControllerAnimated:YES completion:nil];
alertView = [UIAlertController alertControllerWithTitle:[NSString stringWithFormat:@"%@", message]
message:nil
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", nil)
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {}];
[alertView addAction:defaultAction];
[PhoneMainView.instance presentViewController:alertView animated:YES completion:nil];
}
void chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newState) {
ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr));
switch (newState) {
@ -310,4 +333,46 @@ void chat_room_state_changed(LinphoneChatRoom *cr, LinphoneChatRoomState newStat
}
}
void chat_room_subject_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) {
ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr));
view.nameLabel.text = [NSString stringWithUTF8String:linphone_event_log_get_subject(event_log)];
}
void chat_room_participant_added(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) {
ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr));
NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))];
[view.oldContacts addObject:participantAddress];
[view.contacts addObject:participantAddress];
[view.tableView reloadData];
}
void chat_room_participant_removed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) {
ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr));
NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))];
[view.oldContacts removeObject:participantAddress];
[view.contacts removeObject:participantAddress];
[view.tableView reloadData];
}
void chat_room_participant_admin_status_changed(LinphoneChatRoom *cr, const LinphoneEventLog *event_log) {
ChatConversationInfoView *view = (__bridge ChatConversationInfoView *)linphone_chat_room_cbs_get_user_data(linphone_chat_room_get_callbacks(cr));
NSString *participantAddress = [NSString stringWithUTF8String:linphone_address_as_string(linphone_event_log_get_participant_address(event_log))];
LinphoneParticipant *me = linphone_chat_room_get_me(cr);
if (me && linphone_address_equal(linphone_participant_get_address(me), linphone_event_log_get_participant_address(event_log))) {
[view myAdminStatusChanged:(linphone_event_log_get_type(event_log) == LinphoneEventLogTypeConferenceParticipantSetAdmin)];
[view viewWillAppear:TRUE];
return;
}
if (linphone_event_log_get_type(event_log) == LinphoneEventLogTypeConferenceParticipantSetAdmin) {
[view.admins addObject:participantAddress];
[view.oldAdmins addObject:participantAddress];
} else { // linphone_event_log_get_type(event_log) == LinphoneEventLogTypeConferenceParticipantUnsetAdmin
[view.admins removeObject:participantAddress];
[view.oldAdmins removeObject:participantAddress];
}
[view.tableView reloadData];
}
@end

View file

@ -517,16 +517,13 @@ static UICompositeViewDescription *compositeDescription = nil;
}
- (IBAction)onInfoClick:(id)sender {
NSMutableDictionary *contactsDict = [[NSMutableDictionary alloc] init];
NSMutableArray *contactsArray = [[NSMutableArray alloc] init];
NSMutableArray *admins = [[NSMutableArray alloc] init];
bctbx_list_t *participants = linphone_chat_room_get_participants(_chatRoom);
while (participants) {
LinphoneParticipant *participant = (LinphoneParticipant *)participants->data;
NSString *name = [NSString stringWithUTF8String:linphone_address_get_display_name(linphone_participant_get_address(participant))
? linphone_address_get_display_name(linphone_participant_get_address(participant))
: linphone_address_get_username(linphone_participant_get_address(participant))];
NSString *uri = [NSString stringWithUTF8String:linphone_address_as_string_uri_only(linphone_participant_get_address(participant))];
[contactsDict setObject:name forKey:uri];
[contactsArray addObject:uri];
if(linphone_participant_is_admin(participant))
[admins addObject:uri];
@ -534,8 +531,8 @@ static UICompositeViewDescription *compositeDescription = nil;
}
ChatConversationInfoView *view = VIEW(ChatConversationInfoView);
view.create = FALSE;
view.contacts = [contactsDict mutableCopy];
view.oldContacts = [contactsDict mutableCopy];
view.contacts = [contactsArray mutableCopy];
view.oldContacts = [contactsArray mutableCopy];
view.admins = [admins mutableCopy];
view.oldAdmins = [admins mutableCopy];
view.oldSubject = [NSString stringWithUTF8String:linphone_chat_room_get_subject(_chatRoom)];

View file

@ -383,9 +383,7 @@ static UICompositeViewDescription *compositeDescription = nil;
- (void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError *)error {
[controller dismissViewControllerAnimated:TRUE
completion:^{
}];
[controller dismissViewControllerAnimated:TRUE completion:nil];
[self.navigationController setNavigationBarHidden:TRUE animated:FALSE];
}

View file

@ -1011,9 +1011,7 @@ static void linphone_iphone_popup_password_request(LinphoneCore *lc, LinphoneAut
static UIAlertController *alertView = nil;
// avoid having multiple popups
if ([alertView isBeingPresented]) {
[alertView dismissViewControllerAnimated:YES completion:nil];
}
[PhoneMainView.instance dismissViewControllerAnimated:YES completion:nil];
// dont pop up if we are in background, in any case we will refresh registers when entering
// the application again

View file

@ -36,7 +36,7 @@
}
- (IBAction)onDelete:(id)sender {
[_controllerView.contacts removeObjectForKey:_uri];
[_controllerView.contacts removeObject:_uri];
if ([_controllerView.admins containsObject:_uri])
[_controllerView.admins removeObject:_uri];

View file

@ -32,7 +32,6 @@
- (void) onDelete {
[_controller.tableController.contactsGroup removeObject:_uri];
[_controller.tableController.contactsDict removeObjectForKey:_uri];
if (_controller.tableController.contactsGroup.count == 0) {
[UIView animateWithDuration:0.2
delay:0