Add mailbox history

This commit is contained in:
yflory
2019-06-27 18:21:54 +02:00
parent 93b4dac8bb
commit 75e0b68f51
3 changed files with 97 additions and 5 deletions

View File

@@ -172,6 +172,38 @@ define([
});
};
var historyState = false;
var onHistory = function () {};
mailbox.getMoreHistory = function (type, count, lastKnownHash, cb) {
if (historyState) { return void cb("ALREADY_CALLED"); }
historyState = true;
var txid = Util.uid();
execCommand('LOAD_HISTORY', {
type: type,
count: count,
txid: txid,
lastKnownHash: lastKnownHash
}, function (err, obj) {
if (obj && obj.error) { console.error(obj.error); }
});
var messages = [];
onHistory = function (data) {
if (data.txid !== txid) { return; }
if (data.complete) {
onHistory = function () {};
cb(null, messages);
historyState = false;
return;
}
messages.push({
type: type,
content: {
msg: data.message,
hash: data.hash
}
});
};
};
// CHANNEL WITH WORKER
@@ -179,6 +211,9 @@ define([
// obj = { ev: 'type', data: obj }
var ev = obj.ev;
var data = obj.data;
if (ev === 'HISTORY') {
return void onHistory(data);
}
if (ev === 'MESSAGE') {
return void onMessage(data);
}