|
|
@ -113,12 +113,11 @@ define([
|
|
|
|
return friend;
|
|
|
|
return friend;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var initRangeRequest = function (txid, chanId, sig, cb) {
|
|
|
|
var initRangeRequest = function (txid, chanId, cb) {
|
|
|
|
messenger.range_requests[txid] = {
|
|
|
|
messenger.range_requests[txid] = {
|
|
|
|
messages: [],
|
|
|
|
messages: [],
|
|
|
|
cb: cb,
|
|
|
|
cb: cb,
|
|
|
|
chanId: chanId,
|
|
|
|
chanId: chanId,
|
|
|
|
sig: sig,
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -145,7 +144,7 @@ define([
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var txid = Util.uid();
|
|
|
|
var txid = Util.uid();
|
|
|
|
initRangeRequest(txid, chanId, hash, cb);
|
|
|
|
initRangeRequest(txid, chanId, cb);
|
|
|
|
var msg = [ 'GET_HISTORY_RANGE', chan.id, {
|
|
|
|
var msg = [ 'GET_HISTORY_RANGE', chan.id, {
|
|
|
|
from: hash,
|
|
|
|
from: hash,
|
|
|
|
count: count,
|
|
|
|
count: count,
|
|
|
@ -275,7 +274,7 @@ define([
|
|
|
|
network.sendto(sender, JSON.stringify(data));
|
|
|
|
network.sendto(sender, JSON.stringify(data));
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var orderMessages = function (channel, new_messages /*, sig */) {
|
|
|
|
var orderMessages = function (channel, new_messages) {
|
|
|
|
var messages = channel.messages;
|
|
|
|
var messages = channel.messages;
|
|
|
|
|
|
|
|
|
|
|
|
// TODO improve performance, guarantee correct ordering
|
|
|
|
// TODO improve performance, guarantee correct ordering
|
|
|
@ -403,6 +402,21 @@ define([
|
|
|
|
return void console.error("received response to unknown request");
|
|
|
|
return void console.error("received response to unknown request");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!req.cb) {
|
|
|
|
|
|
|
|
// This is the initial history for a pad chat
|
|
|
|
|
|
|
|
if (type === 'HISTORY_RANGE') {
|
|
|
|
|
|
|
|
if (!getChannel(req.chanId)) { return; }
|
|
|
|
|
|
|
|
if (!Array.isArray(parsed[2])) { return; }
|
|
|
|
|
|
|
|
pushMsg(getChannel(req.chanId), parsed[2][4]);
|
|
|
|
|
|
|
|
} else if (type === 'HISTORY_RANGE_END') {
|
|
|
|
|
|
|
|
if (!getChannel(req.chanId)) { return; }
|
|
|
|
|
|
|
|
getChannel(req.chanId).ready = true;
|
|
|
|
|
|
|
|
onChannelReady(req.chanId);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (type === 'HISTORY_RANGE') {
|
|
|
|
if (type === 'HISTORY_RANGE') {
|
|
|
|
req.messages.push(parsed[2]);
|
|
|
|
req.messages.push(parsed[2]);
|
|
|
|
} else if (type === 'HISTORY_RANGE_END') {
|
|
|
|
} else if (type === 'HISTORY_RANGE_END') {
|
|
|
@ -434,7 +448,7 @@ define([
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
orderMessages(channel, decrypted, req.sig);
|
|
|
|
orderMessages(channel, decrypted);
|
|
|
|
req.cb(void 0, decrypted);
|
|
|
|
req.cb(void 0, decrypted);
|
|
|
|
return deleteRangeRequest(txid);
|
|
|
|
return deleteRangeRequest(txid);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -453,11 +467,6 @@ define([
|
|
|
|
// channel[parsed.channel].ready();
|
|
|
|
// channel[parsed.channel].ready();
|
|
|
|
channels[parsed.channel].ready = true;
|
|
|
|
channels[parsed.channel].ready = true;
|
|
|
|
onChannelReady(parsed.channel);
|
|
|
|
onChannelReady(parsed.channel);
|
|
|
|
var updateTypes = channels[parsed.channel].updateOnReady;
|
|
|
|
|
|
|
|
if (updateTypes) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//channels[parsed.channel].updateUI(updateTypes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -531,6 +540,24 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var getChannelMessagesSince = function (chan, data, keys) {
|
|
|
|
var getChannelMessagesSince = function (chan, data, keys) {
|
|
|
|
console.log('Fetching [%s] messages since [%s]', chan.id, data.lastKnownHash || '');
|
|
|
|
console.log('Fetching [%s] messages since [%s]', chan.id, data.lastKnownHash || '');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (chan.isPadChat) {
|
|
|
|
|
|
|
|
// We need to use GET_HISTORY_RANGE to make sure we won't get the full history
|
|
|
|
|
|
|
|
var txid = Util.uid();
|
|
|
|
|
|
|
|
initRangeRequest(txid, chan.id, undefined);
|
|
|
|
|
|
|
|
var msg = ['GET_HISTORY_RANGE', chan.id, {
|
|
|
|
|
|
|
|
//from: hash,
|
|
|
|
|
|
|
|
count: 10,
|
|
|
|
|
|
|
|
txid: txid,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
network.sendto(network.historyKeeper, JSON.stringify(msg)).then(function () {
|
|
|
|
|
|
|
|
}, function (err) {
|
|
|
|
|
|
|
|
throw new Error(err);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var cfg = {
|
|
|
|
var cfg = {
|
|
|
|
validateKey: keys ? keys.validateKey : undefined,
|
|
|
|
validateKey: keys ? keys.validateKey : undefined,
|
|
|
|
owners: [proxy.edPublic, data.edPublic],
|
|
|
|
owners: [proxy.edPublic, data.edPublic],
|
|
|
@ -608,7 +635,7 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// FIXME don't subscribe to the channel implicitly
|
|
|
|
// FIXME don't subscribe to the channel implicitly
|
|
|
|
getChannelMessagesSince(chan, data, keys);
|
|
|
|
getChannelMessagesSince(channel, data, keys);
|
|
|
|
}, function (err) {
|
|
|
|
}, function (err) {
|
|
|
|
console.error(err);
|
|
|
|
console.error(err);
|
|
|
|
});
|
|
|
|
});
|
|
|
|