Search code examples
chathistoryquickblox

QuickBlox history returns only first messages


QuickBlox returns only 50 chat messages and I know this is a known limit if I don't specify the extendedRequest LIMIT and SKIP, but my problem is I want the LAST 50 messages and not the first 50 messages. I tried the extendedRequest[@"sort_desc"] = @"last_message_date_sent" but QB is returning random messages, not the last and not the first.

This issue occurs in Q-Municate also. I created a chat with a friend and sent him N messages, and only first few messages are returned.

So, is there a way to return only the last 50 messages?


Solution

  • I found an answer from Igor Khomenko in this topic: Quickblox messaging fetch last n messages

    and applied. It was correct and I improved inverting the Array with the messages, to show correctly to the user:

    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"] = @(100);
    

    and when I have the Array populated, I just invert it with:

    [[self.messages reverseObjectEnumerator] allObjects];
    

    and everything was fine!

    Igor, the same issue occurs in Q-Municate, and thanks for the help.