Get matched contacts by accountId.

Signed-off-by: Ivan Sein <ivan@nextcloud.com>
This commit is contained in:
Ivan Sein 2020-12-18 16:48:01 +01:00
Родитель afc68b25ad
Коммит 410d4b0c39
6 изменённых файлов: 20 добавлений и 14 удалений

Просмотреть файл

@ -260,9 +260,10 @@
- (void)getPossibleParticipants
{
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:_room.token groupRoom:YES withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
[[NCAPIController sharedInstance] getContactsForAccount:activeAccount forRoom:_room.token groupRoom:YES withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *storedContacts = [NCContact contactsThatContain:nil];
NSMutableArray *storedContacts = [NCContact contactsForAccountId:activeAccount.accountId contains:nil];
NSMutableArray *combinedContactList = [NCUser combineUsersArray:storedContacts withUsersArray:contactList];
NSMutableArray *filteredParticipants = [self filterContacts:combinedContactList];
NSMutableDictionary *participants = [NCUser indexedUsersFromUsersArray:filteredParticipants];
@ -281,9 +282,10 @@
- (void)searchForParticipantsWithString:(NSString *)searchString
{
[_searchParticipantsTask cancel];
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:_room.token groupRoom:YES withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *storedContacts = [NCContact contactsThatContain:searchString];
NSMutableArray *storedContacts = [NCContact contactsForAccountId:activeAccount.accountId contains:searchString];
NSMutableArray *combinedContactList = [NCUser combineUsersArray:storedContacts withUsersArray:contactList];
NSMutableArray *filteredParticipants = [self filterContacts:combinedContactList];
NSMutableDictionary *participants = [NCUser indexedUsersFromUsersArray:filteredParticipants];

Просмотреть файл

@ -34,7 +34,7 @@
+ (instancetype)contactWithIdentifier:(NSString *)identifier cloudId:(NSString *)cloudId lastUpdate:(NSInteger)lastUpdate andAccountId:(NSString *)accountId;
+ (void)updateContact:(NCContact *)managedContact withContact:(NCContact *)contact;
+ (NSMutableArray *)contactsThatContain:(NSString *)searchString;
+ (NSMutableArray *)contactsForAccountId:(NSString *)accountId contains:(NSString *)searchString;
- (NSString *)userId;
- (NSString *)name;

Просмотреть файл

@ -79,9 +79,9 @@
return nil;
}
+ (NSMutableArray *)contactsThatContain:(NSString *)searchString
+ (NSMutableArray *)contactsForAccountId:(NSString *)accountId contains:(NSString *)searchString
{
RLMResults *managedContacts = [NCContact allObjects];
RLMResults *managedContacts = [NCContact objectsWhere:@"accountId = %@", accountId];
NSMutableArray *filteredContacts = nil;
// Create an unmanaged copy of the stored contacts
NSMutableArray *contacts = [NSMutableArray new];

Просмотреть файл

@ -173,7 +173,7 @@ NSString * const NCContactsManagerContactsAccessUpdatedNotification = @"NCContac
}
}
// Delete old contacts
NSPredicate *query = [NSPredicate predicateWithFormat:@"lastUpdate != %ld", (long)updateTimestamp];
NSPredicate *query = [NSPredicate predicateWithFormat:@"accountId = %@ AND lastUpdate != %ld", account.accountId, (long)updateTimestamp];
RLMResults *managedNCContactsToBeDeleted = [NCContact objectsWithPredicate:query];
[realm deleteObjects:managedNCContactsToBeDeleted];
// Update last sync for account

Просмотреть файл

@ -295,9 +295,10 @@ NSString * const NCSelectedContactForChatNotification = @"NCSelectedContactForCh
- (void)searchForContactsWithString:(NSString *)searchString
{
[_searchContactsTask cancel];
_searchContactsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:NO withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
_searchContactsTask = [[NCAPIController sharedInstance] getContactsForAccount:activeAccount forRoom:nil groupRoom:NO withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *storedContacts = [NCContact contactsThatContain:searchString];
NSMutableArray *storedContacts = [NCContact contactsForAccountId:activeAccount.accountId contains:searchString];
NSMutableArray *combinedContactList = [NCUser combineUsersArray:storedContacts withUsersArray:contactList];
NSMutableDictionary *combinedContacts = [NCUser indexedUsersFromUsersArray:combinedContactList];
NSMutableArray *combinedIndexes = [NSMutableArray arrayWithArray:[[combinedContacts allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];
@ -311,7 +312,8 @@ NSString * const NCSelectedContactForChatNotification = @"NCSelectedContactForCh
- (void)getAddressBookContacts
{
// Get all stored address book contacts that matched users in nextcloud
_addressBookContactList = [NCContact contactsThatContain:nil];
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
_addressBookContactList = [NCContact contactsForAccountId:activeAccount.accountId contains:nil];
// Show directly address book contacts if there are already some stored
if (_addressBookContactList.count > 0) {

Просмотреть файл

@ -243,9 +243,10 @@
- (void)getPossibleParticipants
{
[[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:YES withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
[[NCAPIController sharedInstance] getContactsForAccount:activeAccount forRoom:nil groupRoom:YES withSearchParam:nil andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *storedContacts = [NCContact contactsThatContain:nil];
NSMutableArray *storedContacts = [NCContact contactsForAccountId:activeAccount.accountId contains:nil];
NSMutableArray *combinedContactList = [NCUser combineUsersArray:storedContacts withUsersArray:contactList];
NSMutableDictionary *participants = [NCUser indexedUsersFromUsersArray:combinedContactList];
self->_participants = participants;
@ -263,9 +264,10 @@
- (void)searchForParticipantsWithString:(NSString *)searchString
{
[_searchParticipantsTask cancel];
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:[[NCDatabaseManager sharedInstance] activeAccount] forRoom:nil groupRoom:YES withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
TalkAccount *activeAccount = [[NCDatabaseManager sharedInstance] activeAccount];
_searchParticipantsTask = [[NCAPIController sharedInstance] getContactsForAccount:activeAccount forRoom:nil groupRoom:YES withSearchParam:searchString andCompletionBlock:^(NSArray *indexes, NSMutableDictionary *contacts, NSMutableArray *contactList, NSError *error) {
if (!error) {
NSMutableArray *storedContacts = [NCContact contactsThatContain:searchString];
NSMutableArray *storedContacts = [NCContact contactsForAccountId:activeAccount.accountId contains:searchString];
NSMutableArray *combinedContactList = [NCUser combineUsersArray:storedContacts withUsersArray:contactList];
NSMutableDictionary *combinedContacts = [NCUser indexedUsersFromUsersArray:combinedContactList];
NSMutableArray *combinedIndexes = [NSMutableArray arrayWithArray:[[combinedContacts allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]];