UNPKG

meses-messaging

Version:

Meses messaging SDK in JavaScript

44 lines (38 loc) 1.23 kB
class PreviousConversationListQuery { constructor(service, username, next) { this._service = service this._username = username this._next = next this._reachEnd = false } /** * Load some conversation items ordered by lastMessageTime * * @param {Number} items - number of items to load * @return {Promise} array of conversations if fulfilled. */ load(items) { if (this._reachEnd) return new Promise(function(resolve, reject) { resolve([]) }) const service = this._service const username = this._username const next = this._next return new Promise(function(resolve, reject) { service.getConversations(username, next, items) .then(result => { if (result.nextConversationTime == null) this._reachEnd = true this._next = result.nextConversationTime resolve(result.conversationList) }) .catch(err => reject(err)) }.bind(this)) } /** * Predicate for checking whether the query can load more conversation * * @return {Boolean} TRUE if query can load more conversation */ hasMore() { return !this._reachEnd } } export default PreviousConversationListQuery