Merge pull request #619 from vector-im/people_tab_support_email_invite

People tab: support email and matrix id selection.
This commit is contained in:
giomfo 2016-09-14 15:52:59 +02:00 committed by GitHub
commit a956bfc282
2 changed files with 182 additions and 59 deletions

View file

@ -36,6 +36,9 @@
RoomMemberTitleView* contactTitleView;
MXKImageView *contactAvatar;
// HTTP Request
MXHTTPOperation *roomCreationRequest;
/**
Observe UIApplicationWillChangeStatusBarOrientationNotification to hide/show bubbles bg.
*/
@ -215,6 +218,12 @@
{
[super destroy];
if (roomCreationRequest)
{
[roomCreationRequest cancel];
roomCreationRequest = nil;
}
[self cancelRegistrationOnContactChangeNotifications];
if (UIApplicationWillChangeStatusBarOrientationNotificationObserver)
@ -236,6 +245,8 @@
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if (contactTitleView)
{
// Adjust the header height by taking into account the actual position of the member avatar in title view
@ -380,7 +391,7 @@
}
else
{
image = [UIImage imageNamed:@"placeholder"];
image = [AvatarGenerator generateAvatarForText:_contact.displayName];
}
}
@ -498,6 +509,11 @@
}
}
}
// Else check whether the contact has been instantiated with an email or a matrix id
else if ([MXTools isEmailAddress:_contact.displayName] || [MXTools isMatrixUserIdentifier:_contact.displayName])
{
[actionsArray addObject:@(ContactDetailsActionStartChat)];
}
return actionsArray.count;
}
@ -642,7 +658,7 @@
NSLog(@"[ContactDetailsViewController] Ignore %@ failed: %@", strongSelf.firstMatrixId, error);
// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
@ -675,7 +691,7 @@
NSLog(@"[ContactDetailsViewController] Unignore %@ failed: %@", self.firstMatrixId, error);
// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
break;
@ -684,10 +700,73 @@
{
[self addPendingActionMask];
[[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:self.firstMatrixId completion:^{
[self removePendingActionMask];
}];
if (_contact.matrixIdentifiers.count)
{
[[AppDelegate theDelegate] startPrivateOneToOneRoomWithUserId:self.firstMatrixId completion:^{
[self removePendingActionMask];
}];
}
else
{
// Create a new room
roomCreationRequest = [self.mainSession createRoom:nil
visibility:kMXRoomDirectoryVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXRoom *room) {
roomCreationRequest = nil;
NSString *participantId = _contact.displayName;
// Is it an email or a Matrix user ID?
if ([MXTools isEmailAddress:participantId])
{
[room inviteUserByEmail:participantId success:^{
NSLog(@"[ContactDetailsViewController] %@ has been invited (roomId: %@)", participantId, room.state.roomId);
} failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] Invite %@ failed", participantId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
else
{
[room inviteUser:participantId success:^{
NSLog(@"[ContactDetailsViewController] %@ has been invited (roomId: %@)", participantId, room.state.roomId);
} failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] Invite %@ failed", participantId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
[self removePendingActionMask];
[[AppDelegate theDelegate] showRoom:room.state.roomId andEventId:nil withMatrixSession:self.mainSession];
}
failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] Create room failed: %@", error);
roomCreationRequest = nil;
[self removePendingActionMask];
// Notify user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
break;
}
case ContactDetailsActionStartVoiceCall:
@ -708,42 +787,46 @@
else
{
// Create a new room
[self.mainSession createRoom:nil
visibility:kMXRoomDirectoryVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXRoom *room) {
// Add the user
[room inviteUser:matrixId success:^{
// Delay the call in order to be sure that the room is ready
dispatch_async(dispatch_get_main_queue(), ^{
[room placeCallWithVideo:isVideoCall success:nil failure:nil];
[self removePendingActionMask];
});
} failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] %@ invitation failed (roomId: %@): %@", matrixId, room.state.roomId, error);
[self removePendingActionMask];
// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
}];
} failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] Create room failed: %@", error);
[self removePendingActionMask];
// Notify MatrixKit user
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
}];
roomCreationRequest = [self.mainSession createRoom:nil
visibility:kMXRoomDirectoryVisibilityPrivate
roomAlias:nil
topic:nil
success:^(MXRoom *room) {
roomCreationRequest = nil;
// Add the user
[room inviteUser:matrixId success:^{
// Delay the call in order to be sure that the room is ready
dispatch_async(dispatch_get_main_queue(), ^{
[room placeCallWithVideo:isVideoCall success:nil failure:nil];
[self removePendingActionMask];
});
} failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] %@ invitation failed (roomId: %@): %@", matrixId, room.state.roomId, error);
[self removePendingActionMask];
// Notify MatrixKit user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
} failure:^(NSError *error) {
NSLog(@"[ContactDetailsViewController] Create room failed: %@", error);
roomCreationRequest = nil;
[self removePendingActionMask];
// Notify user
[[AppDelegate theDelegate] showErrorAsAlert:error];
}];
}
break;
}

View file

@ -139,26 +139,41 @@
- (void)refreshContactsList
{
// Retrieve all known matrix users
matrixContacts = [NSMutableArray arrayWithArray:[MXKContactManager sharedManager].matrixContacts];
NSArray *contacts = [NSArray arrayWithArray:[MXKContactManager sharedManager].matrixContacts];
// Sort alphabetically the matrix contacts
// Retrieve all known email addresses from local contacts
NSArray *localEmailContacts = [MXKContactManager sharedManager].localEmailContacts;
matrixContacts = [NSMutableArray arrayWithCapacity:(contacts.count + localEmailContacts.count)];
// Add first email contacts
if (localEmailContacts.count)
{
[matrixContacts addObjectsFromArray:localEmailContacts];
}
if (contacts.count)
{
[matrixContacts addObjectsFromArray:contacts];
}
// Sort invitable contacts by displaying local email first
// ...and then alphabetically.
NSComparator comparator = ^NSComparisonResult(MXKContact *contactA, MXKContact *contactB) {
// Then order by name
if (contactA.sortingDisplayName.length && contactB.sortingDisplayName.length)
{
return [contactA.sortingDisplayName compare:contactB.sortingDisplayName options:NSCaseInsensitiveSearch];
}
else if (contactA.sortingDisplayName.length)
{
return NSOrderedAscending;
}
else if (contactB.sortingDisplayName.length)
BOOL isLocalEmailA = !contactA.matrixIdentifiers.count;
BOOL isLocalEmailB = !contactB.matrixIdentifiers.count;
if (!isLocalEmailA && isLocalEmailB)
{
return NSOrderedDescending;
}
return [contactA.displayName compare:contactB.displayName options:NSCaseInsensitiveSearch];
if (isLocalEmailA && !isLocalEmailB)
{
return NSOrderedAscending;
}
return [contactA.sortingDisplayName compare:contactB.sortingDisplayName options:NSCaseInsensitiveSearch];
};
[matrixContacts sortUsingComparator:comparator];
@ -212,6 +227,9 @@
if (currentSearchText.length)
{
// Check whether the search input is a valid email or a Matrix user ID
BOOL isValidInput = ([MXTools isEmailAddress:currentSearchText] || [MXTools isMatrixUserIdentifier:currentSearchText]);
filteredContacts = [NSMutableArray array];
isMultiUseNameByDisplayName = [NSMutableDictionary dictionary];
@ -219,11 +237,19 @@
{
if ([contact matchedWithPatterns:@[currentSearchText]])
{
[filteredContacts addObject:contact];
isMultiUseNameByDisplayName[contact.displayName] = (isMultiUseNameByDisplayName[contact.displayName] ? @(YES) : @(NO));
// Ignore the contact if it corresponds to the search input
if (!isValidInput || [contact.displayName isEqualToString:currentSearchText] == NO)
{
[filteredContacts addObject:contact];
isMultiUseNameByDisplayName[contact.displayName] = (isMultiUseNameByDisplayName[contact.displayName] ? @(YES) : @(NO));
}
}
}
// Show what the user is typing in a cell. So that he can click on it
MXKContact *contact = [[MXKContact alloc] initMatrixContactWithDisplayName:currentSearchText andMatrixID:nil];
[filteredContacts insertObject:contact atIndex:0];
}
else
{
@ -275,6 +301,20 @@
if (contact)
{
participantCell.contentView.alpha = 1.0;
participantCell.userInteractionEnabled = YES;
if (currentSearchText.length && indexPath.row == 0)
{
// This is the text entered by the user
// Check whether the search input is a valid email or a Matrix user ID before adding the plus icon.
if (![MXTools isEmailAddress:currentSearchText] && ![MXTools isMatrixUserIdentifier:currentSearchText])
{
participantCell.contentView.alpha = 0.5;
participantCell.userInteractionEnabled = NO;
}
}
// Disambiguate the display name when it appears several times.
if (contact.displayName && [isMultiUseNameByDisplayName[contact.displayName] isEqualToNumber:@(YES)])
{