0

I'm storing user chat messages in custom table. And I wish to retrieve messages between two users. For now I'm using the following code

NSNumber *user_id, *user2_id;
...
//chatMessages = [dict valueForKey:@"items"];
NSMutableDictionary *getRequest = [NSMutableDictionary dictionary];
[getRequest setObject:@"created_at" forKey:@"sort_asc"];
[getRequest setObject:[NSArray arrayWithObjects:user_id,user2_id, nil] forKey:@"user_id[in]"];
[getRequest setObject:[NSArray arrayWithObjects:user2_id,user_id, nil] forKey:@"receiver_id[in]"];

[QBCustomObjects objectsWithClassName:@"Chat" extendedRequest:getRequest delegate:self];

but this retrieves some strange result. In SQL I would try

WHERE (user_id='firstUser' AND receiver_id='anotherUser') or (user_id='anotherUser' AND receiver_id='firstUser')

but I do not understand how can I ask the same thing from QuickBlox.

yakki
  • 23
  • 5

1 Answers1

1

You can you try next getRequest:

 NSMutableDictionary *getRequest = [NSMutableDictionary dictionary];  
 [getRequest setObject:@"created_at" forKey:@"sort_asc"];
 NSArray *users = @[@(2000), @(1992)];
 [getRequest setObject:users forKey:@"receiver[in]"];  
 [getRequest setObject:users forKey:@"sender[in]"];
 [QBCustomObjects objectsWithClassName:@"Chat" extendedRequest:getRequest delegate:self];

In this case I get all messages between users with id 2000 and 1992

UPD: now it seems correct. (Try pass same users' id array in getRequest)

frankWhite
  • 1,523
  • 15
  • 21
  • This results in **getRequest** with following contents: `{ "receiver_id[or]" = 797975; "sort_asc" = "created_at"; "user_id[or]" = 797975; }` and the query returns all messages send by user 797975 or received by him. – yakki Jan 30 '14 at 05:22
  • Sorry, I mistakes with overriding dictionary keys and search operators. Update answer – frankWhite Jan 30 '14 at 09:27
  • This is exactly the thing I wrote from the beginning. And it is working. Seems that there were some problems with data stored in Chat table. Thank you for your answer) – yakki Jan 30 '14 at 09:42