meses-messaging
Version:
Meses messaging SDK in JavaScript
70 lines (54 loc) • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var PreviousConversationListQuery = function () {
function PreviousConversationListQuery(service, username, next) {
_classCallCheck(this, PreviousConversationListQuery);
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.
*/
_createClass(PreviousConversationListQuery, [{
key: "load",
value: function load(items) {
if (this._reachEnd) return new Promise(function (resolve, reject) {
resolve([]);
});
var service = this._service;
var username = this._username;
var next = this._next;
return new Promise(function (resolve, reject) {
var _this = this;
service.getConversations(username, next, items).then(function (result) {
if (result.nextConversationTime == null) _this._reachEnd = true;
_this._next = result.nextConversationTime;
resolve(result.conversationList);
}).catch(function (err) {
return reject(err);
});
}.bind(this));
}
/**
* Predicate for checking whether the query can load more conversation
*
* @return {Boolean} TRUE if query can load more conversation
*/
}, {
key: "hasMore",
value: function hasMore() {
return !this._reachEnd;
}
}]);
return PreviousConversationListQuery;
}();
exports.default = PreviousConversationListQuery;