检索存储在自定义表quickblox中的聊天消息

时间:2014-01-29 14:17:45

标签: chat quickblox

我在自定义表格中存储用户聊天消息。我希望在两个用户之间检索消息。现在我正在使用以下代码

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];

但这会检索一些奇怪的结果。在SQL中我会尝试

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

但我不明白如何从QuickBlox中提出同样的问题。

1 个答案:

答案 0 :(得分:1)

你可以尝试下一个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];

在这种情况下,我获得id为2000和1992的用户之间的所有消息

UPD:现在看来是正确的。 (尝试在getRequest中传递相同的用户&#id; id数组)