Skip to content

Commit

Permalink
Improve the people invite screens
Browse files Browse the repository at this point in the history
 #904.

Remove a contact from the "Known Contacts" section if a local contact matches with his Matrix identifier.
  • Loading branch information
giomfo committed Jan 13, 2017
1 parent 131ac0e commit 464d103
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion Vector/ViewController/ContactsTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ @interface ContactsTableViewController ()

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

// Report all the contacts by matrix id
NSMutableDictionary <NSString*, MXKContact*> *contactsByMatrixId;
}

@end
Expand Down Expand Up @@ -80,6 +83,7 @@ - (void)finalizeInit
_ignoredContactsByMatrixId = [NSMutableDictionary dictionary];

isMultiUseNameByDisplayName = [NSMutableDictionary dictionary];
contactsByMatrixId = [NSMutableDictionary dictionary];

_forceMatrixIdInDisplayName = NO;
}
Expand Down Expand Up @@ -121,6 +125,7 @@ - (void)destroy
searchProcessingMatrixContacts = nil;

isMultiUseNameByDisplayName = nil;
contactsByMatrixId = nil;

_contactCellAccessoryImage = nil;

Expand Down Expand Up @@ -224,6 +229,10 @@ - (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceRefresh
searchProcessingMatrixContacts = [self unfilteredMatrixContactsArray];
}

// List all the filtered local Matrix-enabled contacts by their matrix id to remove a contact
// from the "Known Contacts" section if a local contact matches with his Matrix identifier.
[contactsByMatrixId removeAllObjects];

for (NSUInteger index = 0; index < searchProcessingLocalContacts.count;)
{
MXKContact* contact = searchProcessingLocalContacts[index];
Expand All @@ -234,6 +243,13 @@ - (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceRefresh
}
else
{
NSArray *identifiers = contact.matrixIdentifiers;
if (identifiers.count)
{
// Here the contact can only have one identifier
contactsByMatrixId[identifiers.firstObject] = contact;
}

// Next
index++;
}
Expand Down Expand Up @@ -274,7 +290,33 @@ - (void)searchWithPattern:(NSString *)searchText forceReset:(BOOL)forceRefresh
// Update the filtered contacts.
currentSearchText = searchProcessingText;
filteredLocalContacts = searchProcessingLocalContacts;
filteredMatrixContacts = searchProcessingMatrixContacts;

// Check whether some Matrix-enabled contacts are listed in the local contact.
if (contactsByMatrixId.count)
{
// Remove a contact from the "Known Contacts" section if a local contact matches with his Matrix identifier.
filteredMatrixContacts = [NSMutableArray arrayWithArray:searchProcessingMatrixContacts];
for (NSUInteger index = 0; index < filteredMatrixContacts.count;)
{
MXKContact* contact = filteredMatrixContacts[index];

// Here the contact can only have one identifier
NSArray *identifiers = contact.matrixIdentifiers;
if (identifiers.count && contactsByMatrixId[identifiers.firstObject])
{
[filteredMatrixContacts removeObjectAtIndex:index];
}
else
{
// Next
index++;
}
}
}
else
{
filteredMatrixContacts = searchProcessingMatrixContacts;
}

if (!self.forceMatrixIdInDisplayName)
{
Expand Down

0 comments on commit 464d103

Please sign in to comment.