|
|
@ -665,31 +665,17 @@ const handleGetHistoryRange = function (Env, Server, seq, userId, parsed) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Server.send(userId, [seq, 'ACK']);
|
|
|
|
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') {
|
|
|
|
if (err && err.code !== 'ENOENT') {
|
|
|
|
Env.Log.error("HK_GET_OLDER_HISTORY", err);
|
|
|
|
Env.Log.error("HK_GET_OLDER_HISTORY", err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!Array.isArray(messages)) { messages = []; }
|
|
|
|
if (Array.isArray(toSend)) {
|
|
|
|
|
|
|
|
|
|
|
|
// 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; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
toSend.forEach(function (msg) {
|
|
|
|
toSend.forEach(function (msg) {
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
JSON.stringify(['HISTORY_RANGE', txid, msg])]);
|
|
|
|
JSON.stringify(['HISTORY_RANGE', txid, msg])]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
JSON.stringify(['HISTORY_RANGE_END', txid, channelName])
|
|
|
|
JSON.stringify(['HISTORY_RANGE_END', txid, channelName])
|
|
|
|