mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-30 00:02:47 +00:00
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:
commit
a956bfc282
2 changed files with 182 additions and 59 deletions
|
@ -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];
|
||||
|
||||
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,12 +787,14 @@
|
|||
else
|
||||
{
|
||||
// Create a new room
|
||||
[self.mainSession createRoom:nil
|
||||
roomCreationRequest = [self.mainSession createRoom:nil
|
||||
visibility:kMXRoomDirectoryVisibilityPrivate
|
||||
roomAlias:nil
|
||||
topic:nil
|
||||
success:^(MXRoom *room) {
|
||||
|
||||
roomCreationRequest = nil;
|
||||
|
||||
// Add the user
|
||||
[room inviteUser:matrixId success:^{
|
||||
|
||||
|
@ -730,7 +811,7 @@
|
|||
[self removePendingActionMask];
|
||||
|
||||
// Notify MatrixKit user
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
|
||||
}];
|
||||
|
||||
|
@ -738,10 +819,12 @@
|
|||
|
||||
NSLog(@"[ContactDetailsViewController] Create room failed: %@", error);
|
||||
|
||||
roomCreationRequest = nil;
|
||||
|
||||
[self removePendingActionMask];
|
||||
|
||||
// Notify MatrixKit user
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kMXKErrorNotification object:error];
|
||||
// Notify user
|
||||
[[AppDelegate theDelegate] showErrorAsAlert:error];
|
||||
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -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,12 +227,18 @@
|
|||
|
||||
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];
|
||||
|
||||
for (MXKContact* contact in contacts)
|
||||
{
|
||||
if ([contact matchedWithPatterns:@[currentSearchText]])
|
||||
{
|
||||
// Ignore the contact if it corresponds to the search input
|
||||
if (!isValidInput || [contact.displayName isEqualToString:currentSearchText] == NO)
|
||||
{
|
||||
[filteredContacts addObject:contact];
|
||||
|
||||
|
@ -225,6 +246,11 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
filteredContacts = nil;
|
||||
|
@ -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)])
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue