|
|
|
@ -236,10 +236,7 @@ const computeIndex = function (Env, channelName, cb) {
|
|
|
|
|
let size = 0;
|
|
|
|
|
nThen(function (w) {
|
|
|
|
|
getMetadata(Env, channelName, w(function (err, _metadata) {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
throw new Error(err); // XXX
|
|
|
|
|
}
|
|
|
|
|
//if (err) { console.log(err); }
|
|
|
|
|
metadata = _metadata;
|
|
|
|
|
}));
|
|
|
|
|
}).nThen(function (w) {
|
|
|
|
@ -251,17 +248,14 @@ const computeIndex = function (Env, channelName, cb) {
|
|
|
|
|
let msg;
|
|
|
|
|
// keep an eye out for the metadata line if you haven't already seen it
|
|
|
|
|
// but only check for metadata on the first line
|
|
|
|
|
if (!i && msgObj.buff.indexOf('{') === 0) { // XXX RESTRICT metadata...
|
|
|
|
|
if (!i && msgObj.buff.indexOf('{') === 0) {
|
|
|
|
|
i++; // always increment the message counter
|
|
|
|
|
msg = tryParse(Env, msgObj.buff.toString('utf8'));
|
|
|
|
|
if (typeof msg === "undefined") { return readMore(); }
|
|
|
|
|
|
|
|
|
|
// validate that the current line really is metadata before storing it as such
|
|
|
|
|
if (isMetadataMessage(msg)) { // XXX RESTRICT
|
|
|
|
|
//metadata = msg; // XXX RESTRICT
|
|
|
|
|
// skip this, as you already have metadata...
|
|
|
|
|
return readMore();
|
|
|
|
|
}
|
|
|
|
|
// skip this, as you already have metadata...
|
|
|
|
|
if (isMetadataMessage(msg)) { return readMore(); }
|
|
|
|
|
}
|
|
|
|
|
i++;
|
|
|
|
|
if (msgObj.buff.indexOf('cp|') > -1) {
|
|
|
|
@ -700,7 +694,7 @@ const handleGetHistory = function (Env, Server, seq, userId, parsed) {
|
|
|
|
|
}, (err) => {
|
|
|
|
|
if (err && err.code !== 'ENOENT') {
|
|
|
|
|
if (err.message !== 'EINVAL') { Log.error("HK_GET_HISTORY", err); }
|
|
|
|
|
const parsedMsg = {error:err.message, channel: channelName, txid: txid}; // XXX history retrieval error format
|
|
|
|
|
const parsedMsg = {error:err.message, channel: channelName, txid: txid};
|
|
|
|
|
Server.send(userId, [0, HISTORY_KEEPER_ID, 'MSG', userId, JSON.stringify(parsedMsg)]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
@ -827,9 +821,9 @@ const handleGetFullHistory = function (Env, Server, seq, userId, parsed) {
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const directMessageCommands = {
|
|
|
|
|
GET_HISTORY: handleGetHistory, // XXX RESTRICT
|
|
|
|
|
GET_HISTORY_RANGE: handleGetHistoryRange, // XXX RESTRICT
|
|
|
|
|
GET_FULL_HISTORY: handleGetFullHistory, // XXX RESTRICT
|
|
|
|
|
GET_HISTORY: handleGetHistory,
|
|
|
|
|
GET_HISTORY_RANGE: handleGetHistoryRange,
|
|
|
|
|
GET_FULL_HISTORY: handleGetFullHistory,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* onDirectMessage
|
|
|
|
@ -883,7 +877,6 @@ HK.onDirectMessage = function (Env, Server, seq, userId, json) {
|
|
|
|
|
if (checkExpired(Env, Server, parsed[1])) {
|
|
|
|
|
// if the channel is expired just abort.
|
|
|
|
|
w.abort();
|
|
|
|
|
// XXX what do we tell the person who asked?
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|