|
|
|
@ -665,31 +665,17 @@ const handleGetHistoryRange = function (Env, Server, seq, userId, parsed) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Server.send(userId, [seq, 'ACK']);
|
|
|
|
|
Env.getOlderHistory(channelName, oldestKnownHash, function (err, messages) {
|
|
|
|
|
Env.getOlderHistory(channelName, oldestKnownHash, desiredMessages, desiredCheckpoint, function (err, toSend) {
|
|
|
|
|
if (err && err.code !== 'ENOENT') {
|
|
|
|
|
Env.Log.error("HK_GET_OLDER_HISTORY", err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(messages)) { messages = []; }
|
|
|
|
|
|
|
|
|
|
// FIXME this reduction could be done in the worker instead of the main process
|
|
|
|
|
var toSend = [];
|
|
|
|
|
if (typeof (desiredMessages) === "number") {
|
|
|
|
|
toSend = messages.slice(-desiredMessages);
|
|
|
|
|
} else {
|
|
|
|
|
let cpCount = 0;
|
|
|
|
|
for (var i = messages.length - 1; i >= 0; i--) {
|
|
|
|
|
if (/^cp\|/.test(messages[i][4]) && i !== (messages.length - 1)) {
|
|
|
|
|
cpCount++;
|
|
|
|
|
}
|
|
|
|
|
toSend.unshift(messages[i]);
|
|
|
|
|
if (cpCount >= desiredCheckpoint) { break; }
|
|
|
|
|
}
|
|
|
|
|
if (Array.isArray(toSend)) {
|
|
|
|
|
toSend.forEach(function (msg) {
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
|
JSON.stringify(['HISTORY_RANGE', txid, msg])]);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
toSend.forEach(function (msg) {
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
|
JSON.stringify(['HISTORY_RANGE', txid, msg])]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
|
JSON.stringify(['HISTORY_RANGE_END', txid, channelName])
|
|
|
|
|