ConnectyCube / connectycube-js-sdk-releases

Releases materials for ConnectyCube JS SDK platform https://connectycube.com
9 stars 2 forks source link

How to implement pagination for chat messages? #100

Closed UmerQur3shi closed 2 years ago

UmerQur3shi commented 2 years ago

I want to implement pagination in my app e.g I want to get last 100 messages in a connectycube dialog but when I scroll up and move to the first message of those 100 messages, I want the earlier messages to be loaded, how can I get the other 100 messages which were sent right before the first message I have right now in the dialog and then the earlier 100 after moving to it's first message and so on, hope to get a response soon, thanks.

ccvlad commented 2 years ago

Read the guide - https://developers.connectycube.com/js/messaging?id=chat-history Find more filters here - https://developers.connectycube.com/server/chat?id=retrieve-messages

Exaple:

  syncPrevMessagesFromServer = (dialogId, lastMessageDate) => {
    const filter = {
      chat_dialog_id: dialogId,
      date_sent: {lt: lastMessageDate},
      limit: 100,
      sort_desc: 'date_sent',
    };

    return ConnectyCube.chat.message.list(filter);
  }

Call the function above after your scroll reaches top/bottom (by event).

UmerQur3shi commented 2 years ago

Read the guide - https://developers.connectycube.com/js/messaging?id=chat-history Find more filters here - https://developers.connectycube.com/server/chat?id=retrieve-messages

Exaple:

  syncPrevMessagesFromServer = (dialogId, lastMessageDate) => {
    const filter = {
      chat_dialog_id: dialogId,
      date_sent: {lt: lastMessageDate},
      limit: 100,
      sort_desc: 'date_sent',
    };

    return ConnectyCube.chat.message.list(filter);
  }

Call the function above after your scroll reaches top/bottom (by event).

Thanks man, appreciated.