Top

iOS: Message Browser Next Page for Conversation

Kommentare

4 Kommentare

  • 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
    Aktionen für Kommentare 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
    Aktionen für Kommentare 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
    Aktionen für Kommentare 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
    Aktionen für Kommentare Permalink

Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.

Sie können immer noch nicht finden, was Sie brauchen?

  • Kontaktieren Sie uns

    Haben Sie eine Frage zu Rainbow? Hinterlassen Sie uns eine Nachricht, um weitere Informationen zu erhalten.

    Kontakt
  • Fragen Sie die Gemeinschaft

    Brauchen Sie Hilfe? Stellen Sie Ihre Fragen in der Community, um Antworten von anderen Rainbow-Benutzern zu erhalten.

    Nachricht posten