问题
I'm using the Quickblox iOS SDK for instant messaging in my app. When a user logs in I retrieve the list of messages. I am trying to retrieve the last N messages. I use extended request parameters as specified in this document: http://quickblox.com/developers/SimpleSample-chat_users-ios#List_chat_messages
This call retrieves the first 100 messages, not the most recent ones. I also checked out the list of parameters to send from here: http://quickblox.com/developers/Chat#Retrieve_messages
Using a combination of the limit and sort parameters still does not give the desired result.
- How can I make a request to retrieve the last N messages in a dialog?
- How can I load last but N messages? for example, last 100 messages before the most recent 100. Similar to limit 100, but skip 100, in reverse.
回答1:
//Try this out:
NSMutableDictionary *extendedRequest = [NSMutableDictionary new];
NSDate *now = [NSDate date];
extendedRequest[@"date_sent[lte]"]= @([now timeIntervalSince1970]);
extendedRequest[@"sort_desc"]= @"date_sent";
//get the most recent 50 messages
extendedRequest[@"limit"] = @(50);
[QBChat messagesWithDialogID:self.dialog.ID extendedRequest:extendedRequest delegate:self];
回答2:
I was getting the same issue in Android .
Solved it as following . All you have to do is add a parameter in requestbuilder sortDesc("date_sent");
QBDialog dlg=new QBDialog(str_dialogid);
QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();
requestBuilder.setLimit(10);
requestBuilder.sortDesc("date_sent");
来源:https://stackoverflow.com/questions/26981259/quickblox-messaging-fetch-last-n-messages