Top

iOS: Message Browser Next Page for Conversation

Comments

4 comments

  • Vladimir VYSKOCIL

    The general pattern to browse messages from a conversation is :

    -(void) loadMessages {

    if (self.conversation.isSynchronized  && ![self.messagesBrowser hasMorePages]){
    NSLog(@"This conversation is already synchronized and we are not loading a new page");

    BOOL hasPage = [_messagesBrowser hasMorePages];
    // show that there are more pages to load if hasPage is true or use pull to refresh...

    } else if(!_conversation.isSynchronized){
    NSLog (@"loadMessages : start resync");
    self.isRetrievingNextPage = YES;

    [self.messagesBrowser resyncBrowsingCacheWithCompletionHandler:^(NSArray *addedCacheItems, NSArray *removedCacheItems, NSArray *updatedCacheItems, NSError *error) {
    NSLog(@"Messages resync done");

    BOOL hasPage = [self.messagesBrowser hasMorePages];
    self.isRetrievingNextPage = NO;

    if (hasPage && ...) { // check for example pull to refresh
    [self loadMessages];
    }
    }];

    } else {
    OTCLog(@"We have scrolled so load next page");
    self.isRetrievingNextPage = YES;
    [self.messagesBrowser nextPageWithCompletionHandler:^(NSArray *addedCacheItems, NSArray *removedCacheItems, NSArray *updatedCacheItems, NSError *error) {
    if(!error){
    BOOL hasPage = [_messagesBrowser hasMorePages];
    self.isRetrievingNextPage = NO;
    }];
    }

    }
    0
    Comment actions Permalink
  • Rick LUPPINO

    Hi Vladimir,

    Thank you for your reply and sample code. I am using Swift and the Conversation object has no property called 'isSynchronised'.

    What I see is that when I call the resyncBrowsingCache method, it returns an error saying "Conversation is already synchronized", but I have no way of knowing this without calling that method first. If I then call nextPage, there is no error but the cached item arrays are all empty (which I guess is expected if the conversation is synchronised).

    My flow is: If message browser has more pages, call resyncBrowsingCache followed by nextPage. 

    The hasMorePages property of my message browser is always true and resyncBrowsingCache always returns the error saying that the conversation is already synchronised. I am using a page size of 20 and there are a lot more messages in the conversation so it seems strange that the SDK is always reporting the conversation to be synchronised.

    If I call the nextPage method first and then resyncBrowsingCache, I get the same behaviour. If I use a page size greater than the total number of messages in the conversation, I still get the same behaviour.

    0
    Comment actions Permalink
  • Vladimir VYSKOCIL

    Hi Rick,

    I just added a "load more" button in the ChatViewController in the Swift demo app :

    https://github.com/Rainbow-CPaaS/Rainbow-iOS-SDK-Samples/tree/master/Rainbow-iOS-SDK-Sample-Swift

    You should see if the way it is working could solve your issue.

    0
    Comment actions Permalink
  • Rick LUPPINO

    Hi Vladimir,

    Thank you for the update to the sample code. At first glance, my code matched yours so I was still confused as to why it wasn't working. Then I discovered that the issue was caused by the fact that I was recreating the message browser rather than instantiating it once and using that same reference to retrieve subsequent pages of the conversation.

    So, issue solved. Thank you for your help, it's much appreciated.

    Rick

    0
    Comment actions Permalink

Please sign in to leave a comment.

Still can't find what you need?

  • Contact Us

    Do you have any question about Rainbow? Leave us a message to get more information.

    Contact
  • Ask the Community

    Do you need help? Ask your questions in the Community to get answers from other Rainbow users.

    Post message