|
|
@ -61,13 +61,13 @@ module.exports.create = function (cfg) {
|
|
|
|
const cpIndex = [];
|
|
|
|
const cpIndex = [];
|
|
|
|
let messageBuf = [];
|
|
|
|
let messageBuf = [];
|
|
|
|
let validateKey;
|
|
|
|
let validateKey;
|
|
|
|
let metadata;
|
|
|
|
let metadata; // FIXME METADATA
|
|
|
|
let i = 0;
|
|
|
|
let i = 0;
|
|
|
|
store.readMessagesBin(channelName, 0, (msgObj, rmcb) => {
|
|
|
|
store.readMessagesBin(channelName, 0, (msgObj, rmcb) => {
|
|
|
|
let msg;
|
|
|
|
let msg;
|
|
|
|
i++;
|
|
|
|
i++;
|
|
|
|
if (!validateKey && msgObj.buff.indexOf('validateKey') > -1) {
|
|
|
|
if (!validateKey && msgObj.buff.indexOf('validateKey') > -1) {
|
|
|
|
metadata = msg = tryParse(msgObj.buff.toString('utf8'));
|
|
|
|
metadata = msg = tryParse(msgObj.buff.toString('utf8')); // FIXME METADATA
|
|
|
|
if (typeof msg === "undefined") { return rmcb(); }
|
|
|
|
if (typeof msg === "undefined") { return rmcb(); }
|
|
|
|
if (msg.validateKey) {
|
|
|
|
if (msg.validateKey) {
|
|
|
|
validateKey = historyKeeperKeys[channelName] = msg;
|
|
|
|
validateKey = historyKeeperKeys[channelName] = msg;
|
|
|
@ -105,7 +105,7 @@ module.exports.create = function (cfg) {
|
|
|
|
cpIndex: sliceCpIndex(cpIndex, i),
|
|
|
|
cpIndex: sliceCpIndex(cpIndex, i),
|
|
|
|
offsetByHash: offsetByHash,
|
|
|
|
offsetByHash: offsetByHash,
|
|
|
|
size: size,
|
|
|
|
size: size,
|
|
|
|
metadata: metadata,
|
|
|
|
metadata: metadata, // FIXME METADATA
|
|
|
|
line: i
|
|
|
|
line: i
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -438,16 +438,16 @@ module.exports.create = function (cfg) {
|
|
|
|
so, let's just fall through...
|
|
|
|
so, let's just fall through...
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if (err) { return w(); }
|
|
|
|
if (err) { return w(); }
|
|
|
|
if (!index || !index.metadata) { return void w(); }
|
|
|
|
if (!index || !index.metadata) { return void w(); } // FIXME METADATA
|
|
|
|
// Store the metadata if we don't have it in memory
|
|
|
|
// Store the metadata if we don't have it in memory
|
|
|
|
if (!historyKeeperKeys[channelName]) {
|
|
|
|
if (!historyKeeperKeys[channelName]) {
|
|
|
|
historyKeeperKeys[channelName] = index.metadata;
|
|
|
|
historyKeeperKeys[channelName] = index.metadata; // FIXME METADATA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// And then check if the channel is expired. If it is, send the error and abort
|
|
|
|
// And then check if the channel is expired. If it is, send the error and abort
|
|
|
|
if (checkExpired(ctx, channelName)) { return void waitFor.abort(); }
|
|
|
|
if (checkExpired(ctx, channelName)) { return void waitFor.abort(); }
|
|
|
|
// Send the metadata to the user
|
|
|
|
// Send the metadata to the user
|
|
|
|
if (!lastKnownHash && index.cpIndex.length > 1) {
|
|
|
|
if (!lastKnownHash && index.cpIndex.length > 1) {
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(index.metadata)], w);
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(index.metadata)], w); // FIXME METADATA
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
w();
|
|
|
|
w();
|
|
|
@ -494,8 +494,8 @@ module.exports.create = function (cfg) {
|
|
|
|
key.expire = expire;
|
|
|
|
key.expire = expire;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
historyKeeperKeys[channelName] = key;
|
|
|
|
historyKeeperKeys[channelName] = key;
|
|
|
|
storeMessage(ctx, chan, JSON.stringify(key), false, undefined);
|
|
|
|
storeMessage(ctx, chan, JSON.stringify(key), false, undefined); // FIXME METADATA
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(key)]);
|
|
|
|
sendMsg(ctx, user, [0, HISTORY_KEEPER_ID, 'MSG', user.id, JSON.stringify(key)]); // FIXME METADATA
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// End of history message:
|
|
|
|
// End of history message:
|
|
|
|