Added checkpoints with the new code from ChainPad

This commit is contained in:
Caleb James DeLisle
2016-05-26 17:09:02 +02:00
parent 8885658431
commit da2bfe2de9
3 changed files with 264 additions and 164 deletions

View File

@@ -87,7 +87,27 @@ dropUser = function (ctx, user) {
};
const getHistory = function (ctx, channelName, handler, cb) {
ctx.store.getMessages(channelName, function (msgStr) { handler(JSON.parse(msgStr)); }, cb);
var messageBuf = [];
ctx.store.getMessages(channelName, function (msgStr) {
messageBuf.push(JSON.parse(msgStr));
}, function () {
var startPoint;
var cpCount = 0;
var msgBuff2 = [];
for (startPoint = messageBuf.length - 1; startPoint >= 0; startPoint--) {
var msg = messageBuf[startPoint];
msgBuff2.push(msg);
if (msg[2] === 'MSG' && msg[4].indexOf('cp|') === 0) {
cpCount++;
if (cpCount >= 2) {
for (var x = msgBuff2.pop(); x; x = msgBuff2.pop()) { handler(x); }
break;
}
}
//console.log(messageBuf[startPoint]);
}
cb();
});
};
const randName = function () { return Crypto.randomBytes(16).toString('hex'); };