How can I retrieve more than 50 historical messages between two users using stanza.js?

303 views Asked by At

I'm currently building a chat application using React and Stanza.js. I'm able to query messages between two users using:

client.searchHistory([self@hostname], {with: [target@hostname]})

However, this will only give me the 50 most earliest messages between these two users, and the options to this client method only have parameters for "with: string, start: date, and end: date", and regardless of what these are set to will only return 50 messages.

Is there a different client method that I could be using to query messages between two users that would support paginated requests?

Is this the correct client method that I should be using to allow users to retrieve historical texts by scrolling up in the chat timeline?

1

There are 1 answers

0
mcmcphillips On

I unfortunately missed a telling interface that described MAM options as extending MAM query.

In order to do paginated requests for all messages exchanged between two users you can do.. client.searchHistory([self@hostname], {with: [target@hostname], pagination: {[before]: lastQueryId, max: 25}});

Where [before] will be a string that is initialized at "" and on all subsequent requests is replaced by the stanza query id of the first element returned in the list.

The results of the query will also return a value for "complete" which will be a bool that lets you know if you've reached the first message.