Skip to content

Commit

Permalink
Prepare #904: Improve the people invite screens
Browse files Browse the repository at this point in the history
- Make `HomePeopleSearchViewController` inherit of the new class `ContactsTableViewController` to handle room members.
  • Loading branch information
giomfo committed Jan 12, 2017
1 parent 3b34e17 commit da0016c
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 363 deletions.
32 changes: 30 additions & 2 deletions Vector/ViewController/ContactsTableViewController.h
Expand Up @@ -19,6 +19,23 @@
#import "ContactTableViewCell.h"
#import "VectorDesignValues.h"

@class ContactsTableViewController;

/**
`ContactsTableViewController` delegate.
*/
@protocol ContactsTableViewControllerDelegate <NSObject>

/**
Tells the delegate that the user selected a contact.
@param contactsTableViewController the `ContactsTableViewController` instance.
@param contact the selected contact.
*/
- (void)contactsTableViewController:(ContactsTableViewController *)contactsTableViewController didSelectContact:(MXKContact*)contact;

@end

/**
'ContactsTableViewController' instance is used to display/filter a list of contacts.
See 'ContactsTableViewController-inherited' object for example of use.
Expand Down Expand Up @@ -50,19 +67,30 @@

@property (weak, nonatomic) IBOutlet UITableView *tableView;

/**
Tell whether the matrix id should be added by default in the matrix contact display name (NO by default).
If NO, the matrix id is added only to disambiguate the contact display names which appear several times.
*/
@property (nonatomic) BOOL forceMatrixIdInDisplayName;

/**
Filter the contacts list, by keeping only the contacts who have the search pattern
as prefix in their display name, their matrix identifiers and/or their contact methods (emails, phones).
@param searchText the search pattern (nil to reset filtering).
@param forceRefresh tell whether the previous filtered contacts list must be reinitialized before searching (use NO by default).
@param forceReset tell whether the search request must be applied by ignoring the previous search result if any (use NO by default).
*/
- (void)searchWithPattern:(NSString *)searchText forceRefresh:(BOOL)forceRefresh;
- (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceReset;

/**
Refresh the contacts table display.
*/
- (void)refreshTableView;

/**
The delegate for the view controller.
*/
@property (nonatomic) id<ContactsTableViewControllerDelegate> contactsTableViewControllerDelegate;

@end

64 changes: 59 additions & 5 deletions Vector/ViewController/ContactsTableViewController.m
Expand Up @@ -33,6 +33,9 @@ @interface ContactsTableViewController ()
id kAppDelegateDidTapStatusBarNotificationObserver;

BOOL forceSearchResultRefresh;

// This dictionary tells for each display name whether it appears several times.
NSMutableDictionary <NSString*,NSNumber*> *isMultiUseNameByDisplayName;
}

@end
Expand All @@ -59,6 +62,10 @@ - (void)finalizeInit

ignoredContactsByEmail = [NSMutableDictionary dictionary];
ignoredContactsByMatrixId = [NSMutableDictionary dictionary];

isMultiUseNameByDisplayName = [NSMutableDictionary dictionary];

_forceMatrixIdInDisplayName = NO;
}

- (void)viewDidLoad
Expand Down Expand Up @@ -93,6 +100,8 @@ - (void)destroy
searchProcessingLocalContacts = nil;
searchProcessingMatrixContacts = nil;

isMultiUseNameByDisplayName = nil;

[super destroy];
}

Expand Down Expand Up @@ -145,7 +154,20 @@ - (void)viewWillDisappear:(BOOL)animated

#pragma mark -

- (void)searchWithPattern:(NSString *)searchText forceRefresh:(BOOL)forceRefresh
- (void)setForceMatrixIdInDisplayName:(BOOL)forceMatrixIdInDisplayName
{
if (_forceMatrixIdInDisplayName != forceMatrixIdInDisplayName)
{
_forceMatrixIdInDisplayName = forceMatrixIdInDisplayName;

if (self.tableView)
{
[self refreshTableView];
}
}
}

- (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceRefresh
{
// Update search results.
searchText = [searchText stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
Expand Down Expand Up @@ -221,6 +243,15 @@ - (void)searchWithPattern:(NSString *)searchText forceRefresh:(BOOL)forceRefresh
filteredLocalContacts = searchProcessingLocalContacts;
filteredMatrixContacts = searchProcessingMatrixContacts;

if (!self.forceMatrixIdInDisplayName)
{
[isMultiUseNameByDisplayName removeAllObjects];
for (MXKContact* contact in filteredMatrixContacts)
{
isMultiUseNameByDisplayName[contact.displayName] = (isMultiUseNameByDisplayName[contact.displayName] ? @(YES) : @(NO));
}
}

// Refresh display
[self refreshTableView];

Expand All @@ -231,7 +262,7 @@ - (void)searchWithPattern:(NSString *)searchText forceRefresh:(BOOL)forceRefresh
{
// Launch a new search
forceSearchResultRefresh = NO;
[self searchWithPattern:searchProcessingText forceRefresh:YES];
[self searchWithPattern:searchProcessingText forceReset:YES];
}
}
});
Expand All @@ -256,7 +287,7 @@ - (void)onContactManagerDidUpdate:(NSNotification *)notif
}

// Refresh the search result
[self searchWithPattern:currentSearchText forceRefresh:YES];
[self searchWithPattern:currentSearchText forceReset:YES];
}

- (NSMutableArray<MXKContact*>*)unfilteredLocalContactsArray
Expand Down Expand Up @@ -432,7 +463,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
contact = filteredMatrixContacts[indexPath.row];

contactCell.selectionStyle = UITableViewCellSelectionStyleDefault;
contactCell.showMatrixIdInDisplayName = YES;
contactCell.showMatrixIdInDisplayName = self.forceMatrixIdInDisplayName ? YES : [isMultiUseNameByDisplayName[contact.displayName] isEqualToNumber:@(YES)];
}
}

Expand Down Expand Up @@ -520,7 +551,30 @@ - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPa

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// Do nothing by default - `ContactsTableViewController-inherited` instance must override this method.
if (self.contactsTableViewControllerDelegate)
{
NSInteger row = indexPath.row;
MXKContact *mxkContact;

if (indexPath.section == searchInputSection)
{
mxkContact = [[MXKContact alloc] initMatrixContactWithDisplayName:currentSearchText andMatrixID:nil];
}
else if (indexPath.section == filteredLocalContactsSection)
{
mxkContact = filteredLocalContacts[row];
}
else if (indexPath.section == filteredMatrixContactsSection)
{
mxkContact = filteredMatrixContacts[row];
}

if (mxkContact)
{
[self.contactsTableViewControllerDelegate contactsTableViewController:self didSelectContact:mxkContact];
}
}
// Else do nothing by default - `ContactsTableViewController-inherited` instance must override this method.

[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Expand Down
33 changes: 2 additions & 31 deletions Vector/ViewController/HomePeopleSearchViewController.h
Expand Up @@ -14,37 +14,12 @@
limitations under the License.
*/

#import <MatrixKit/MatrixKit.h>

@class HomePeopleSearchViewController;

/**
`HomePeopleSearchViewController` delegate.
*/
@protocol HomePeopleSearchViewControllerDelegate <NSObject>

/**
Tells the delegate that the user selected a contact.
@param homePeopleSearchViewController the `HomePeopleSearchViewController` instance.
@param contact the selected contact.
*/
- (void)homePeopleSearchViewController:(HomePeopleSearchViewController *)homePeopleSearchViewController didSelectContact:(MXKContact*)contact;

@end
#import "ContactsTableViewController.h"

/**
`HomePeopleSearchViewController` displays people search in user's rooms under a `HomeViewController` segment.
*/
@interface HomePeopleSearchViewController : MXKViewController <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic) IBOutlet UITableView *contactsTableView;
@property (weak, nonatomic) IBOutlet UILabel *noResultsLabel;

/**
The delegate for the view controller.
*/
@property (nonatomic) id<HomePeopleSearchViewControllerDelegate> delegate;
@interface HomePeopleSearchViewController : ContactsTableViewController

/**
Returns the `UINib` object initialized for a `HomePeopleSearchViewController`.
Expand All @@ -62,8 +37,4 @@
*/
+ (instancetype)homePeopleSearchViewController;

/**
*/
- (void)searchWithPattern:(NSString *)searchText;

@end

0 comments on commit da0016c

Please sign in to comment.