return new hash when pinning a channel

pull/1/head
ansuz 8 years ago
parent 3380cf0348
commit 7acf52405d

@ -122,23 +122,6 @@ var checkSignature = function (signedMsg, signature, publicKey) {
return Nacl.sign.detached.verify(signedBuffer, signatureBuffer, pubBuffer); return Nacl.sign.detached.verify(signedBuffer, signatureBuffer, pubBuffer);
}; };
var storeMessage = function (store, publicKey, msg, cb) {
store.message(publicKey, JSON.stringify(msg), cb);
};
var pinChannel = function (store, publicKey, channel, cb) {
store.message(publicKey, JSON.stringify(['PIN', channel]), cb);
};
var unpinChannel = function (store, publicKey, channel, cb) {
store.message(publicKey, JSON.stringify(['UNPIN', channel]), cb);
};
var resetUserPins = function (store, publicKey, channelList, cb) {
// TODO make this atomic
store.message(publicKey, JSON.stringify(['RESET']), cb);
};
var getChannelList = function (store, publicKey, cb) { var getChannelList = function (store, publicKey, cb) {
// to accumulate pinned channels // to accumulate pinned channels
var pins = {}; var pins = {};
@ -226,10 +209,41 @@ var hashChannelList = function (A) {
var getHash = function (store, publicKey, cb) { var getHash = function (store, publicKey, cb) {
getChannelList(store, publicKey, function (channels) { getChannelList(store, publicKey, function (channels) {
cb(hashChannelList(channels)); cb(void 0, hashChannelList(channels));
});
};
var storeMessage = function (store, publicKey, msg, cb) {
store.message(publicKey, JSON.stringify(msg), cb);
};
var pinChannel = function (store, publicKey, channel, cb) {
store.message(publicKey, JSON.stringify(['PIN', channel]),
function (e) {
if (e) { return void cb(e); }
getHash(store, publicKey, function (e, hash) {
cb(e, hash);
});
}); });
}; };
var unpinChannel = function (store, publicKey, channel, cb) {
store.message(publicKey, JSON.stringify(['UNPIN', channel]),
function (e) {
if (e) { return void cb(e); }
getHash(store, publicKey, function (e, hash) {
cb(e, hash);
});
});
};
var resetUserPins = function (store, publicKey, channelList, cb) {
// TODO make this atomic
store.message(publicKey, JSON.stringify(['RESET']), cb);
};
var expireSessions = function (Cookies) { var expireSessions = function (Cookies) {
var now = +new Date(); var now = +new Date();
Object.keys(Cookies).forEach(function (key) { Object.keys(Cookies).forEach(function (key) {
@ -326,20 +340,17 @@ RPC.create = function (config, cb) {
return void Respond(e); return void Respond(e);
}); });
/* TODO
pin and unpin operations should respond with the new hash */
case 'PIN': case 'PIN':
return pinChannel(store, safeKey, msg[1], function (e) { return pinChannel(store, safeKey, msg[1], function (e, hash) {
Respond(e); Respond(e, hash);
}); });
case 'UNPIN': case 'UNPIN':
return unpinChannel(store, safeKey, msg[1], function (e) { return unpinChannel(store, safeKey, msg[1], function (e, hash) {
Respond(e); Respond(e, hash);
}); });
case 'GET_HASH': case 'GET_HASH':
return void getHash(store, safeKey, function (hash) { return void getHash(store, safeKey, function (e, hash) {
Respond(void 0, hash); Respond(e, hash);
}); });
case 'GET_TOTAL_SIZE': case 'GET_TOTAL_SIZE':
return getTotalSize(store, ctx.store, safeKey, function (e, size) { return getTotalSize(store, ctx.store, safeKey, function (e, size) {

Loading…
Cancel
Save