|
|
|
@ -367,8 +367,8 @@ const storeMessage = function (Env, channel, msg, isCp, optionalMessageHash, cb)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// call back with the offset of the message we just stored
|
|
|
|
|
cb(void 0, index.size);
|
|
|
|
|
// Message stored, call back
|
|
|
|
|
cb();
|
|
|
|
|
|
|
|
|
|
index.size += msgBin.length;
|
|
|
|
|
|
|
|
|
@ -508,22 +508,9 @@ const getHistoryAsync = (Env, channelName, lastKnownHash, beforeHash, handler, c
|
|
|
|
|
return void cb(new Error('EUNKNOWN'));
|
|
|
|
|
}
|
|
|
|
|
const start = (beforeHash) ? 0 : offset;
|
|
|
|
|
let msgOffset = start;
|
|
|
|
|
store.readMessagesBin(channelName, start, (msgObj, readMore, abort) => {
|
|
|
|
|
if (beforeHash && msgObj.offset >= offset) { return void abort(); }
|
|
|
|
|
const str = msgObj.buff.toString('utf8');
|
|
|
|
|
var parsed = tryParse(Env, str);
|
|
|
|
|
|
|
|
|
|
// Extract the time and put it in the new opts object
|
|
|
|
|
let time;
|
|
|
|
|
if (Array.isArray(parsed)) {
|
|
|
|
|
if (typeof(parsed[parsed.length - 1]) === "number") { time = parsed.pop(); }
|
|
|
|
|
parsed.push({
|
|
|
|
|
time: time,
|
|
|
|
|
offset: msgObj.offset
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const parsed = tryParse(Env, msgObj.buff.toString('utf8'));
|
|
|
|
|
if (!parsed) { return void readMore(); }
|
|
|
|
|
handler(parsed, readMore);
|
|
|
|
|
}, waitFor(function (err) {
|
|
|
|
@ -718,20 +705,7 @@ const handleGetHistoryRange = function (Env, Server, seq, userId, parsed) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Array.isArray(toSend)) {
|
|
|
|
|
// toSend: array of objects {msg, hash, offset}
|
|
|
|
|
toSend.forEach(function (obj) {
|
|
|
|
|
let msg = obj.msg;
|
|
|
|
|
|
|
|
|
|
// Extract the time and put it in the new opts object
|
|
|
|
|
let time;
|
|
|
|
|
if (Array.isArray(msg)) {
|
|
|
|
|
if (typeof(msg[msg.length - 1]) === "number") { time = msg.pop(); }
|
|
|
|
|
msg.push({
|
|
|
|
|
time: time,
|
|
|
|
|
offset: obj.offset
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toSend.forEach(function (msg) {
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId,
|
|
|
|
|
JSON.stringify(['HISTORY_RANGE', txid, msg])]);
|
|
|
|
|
});
|
|
|
|
|