Search code examples
iossearchquickblox

Quickblox user search from multiple sources


I have a requirement to search QuickBlox users whose IDs match their

  • Facebook IDs OR
  • Twitter IDs OR
  • Login IDs

So I am firing multiple QBUser queries at once, using following code:

[QBUsers usersWithLogins:[NSArray arrayWithObject:m_searchString] delegate:self];
[QBUsers usersWithFacebookIDs:[NSArray arrayWithObject:m_searchString] delegate:self];
[QBUsers usersWithTwitterIDs:[NSArray arrayWithObject:m_searchString] delegate:self];

So for example, if I give search string as "Testuser" - it should search all users having login = Testuser, FB login = Testuser, and Twitter login = Testuser.

Based on source of request (FB/Twitter/My own app), I need to put results in different UI parts.

The problem is, I can't differentiate which result comes back for which request.

-(void)completedWithResult:(Result*)result
{
    [self showActivityIndicator:NO];
    // QuickBlox User creation result
    if([result isKindOfClass:[QBUUserPagedResult class]])
    {
        // Success result
        if(result.success)
        {
        }
    }
}

I can see that above code is hit 3 times. But I don't see anything in QBUUserPagedResult class that tells me from which request this result has come.

Something like a tag for request should suffice, but I am not sure what thing it is, looking at the documentation.

  • Is there anything I can use?

  • Alternately, is there another approach to what I am trying to achieve (instead of multiple requests)?


Solution

  • I figured it out that context option which is an NSString works like a tag for each Quickblox request:

    [QBUsers usersWithLogins:[NSArray arrayWithObject:m_searchString] delegate:self context:MY_STRING_CONSTANT];
    

    Then in delegate function:

    - (void)completedWithResult:(Result *)result context:(void *)contextInfo
    {  
        if(result.success && [result isKindOfClass:QBUUserPagedResult.class])
        {                
            NSString * _context = (__bridge NSString *) contextInfo;            
            if([_context isEqualToString:MY_STRING_CONSTANT])
            {
            }
        }
    }
    

    As simple as that, but the documentation doesn't say much about it, or it's not visible as it should be. I had to dig into their forums to figure it out.