diff --git a/customize.dist/application_config.js b/customize.dist/application_config.js index 291570ac7..63cc96f18 100644 --- a/customize.dist/application_config.js +++ b/customize.dist/application_config.js @@ -12,5 +12,24 @@ define(function() { */ config.notificationTimeout = 5000; + config.whiteboardPalette = [ + '#000000', // black + '#FFFFFF', // white + '#848484', // grey + '#8B4513', // saddlebrown + '#FF0000', // red + '#FF8080', // peach? + '#FF8000', // orange + '#FFFF00', // yellow + '#80FF80', // light green + '#00FF00', // green + '#00FFFF', // cyan + '#008B8B', // dark cyan + '#0000FF', // blue + '#FF00FF', // fuschia + '#FF00C0', // hot pink + '#800080', // purple + ]; + return config; }); diff --git a/rpc.js b/rpc.js index 705f07f8c..7ad81acb3 100644 --- a/rpc.js +++ b/rpc.js @@ -122,23 +122,6 @@ var checkSignature = function (signedMsg, signature, publicKey) { 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) { // to accumulate pinned channels var pins = {}; @@ -160,6 +143,17 @@ var getChannelList = function (store, publicKey, cb) { Object.keys(pins).forEach(function (pin) { pins[pin] = false; }); + + if (!parsed[1] || parsed[1].length) { + break; + } + else { + parsed[1].forEach(function (channel) { + pins[channel] = true; + }); + break; + } + break; default: console.error('invalid message read from store'); @@ -178,6 +172,34 @@ var getChannelList = function (store, publicKey, cb) { }); }; +var getFileSize = function (store, channel, cb) { + if (!isValidChannel(channel)) { return void cb('INVALID_CHAN'); } + + return void store.getChannelSize(channel, function (e, size) { + if (e) { return void cb(e.code); } + cb(void 0, size); + }); +}; + +var getTotalSize = function (pinStore, messageStore, publicKey, cb) { + var bytes = 0; + + return void getChannelList(pinStore, publicKey, function (channels) { + if (!channels) { cb('NO_ARRAY'); } // unexpected + + var count = channels.length; + if (!count) { cb(void 0, 0); } + + channels.forEach(function (channel) { + return messageStore.getChannelSize(channel, function (e, size) { + count--; + if (!e) { bytes += size; } + if (count === 0) { return cb(void 0, bytes); } + }); + }); + }); +}; + var hashChannelList = function (A) { var uniques = []; @@ -194,7 +216,44 @@ var hashChannelList = function (A) { var getHash = function (store, publicKey, cb) { 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) { + store.message(publicKey, JSON.stringify(['RESET', channelList]), + function (e) { + if (e) { return void cb(e); } + + getHash(store, publicKey, function (e, hash) { + cb(e, hash); + }); }); }; @@ -282,45 +341,30 @@ RPC.create = function (config, cb) { } switch (msg[0]) { - case 'COOKIE': - return void Respond(void 0); - case 'ECHO': - return void Respond(void 0, msg); - - /* TODO - reset should be atomic in case the operation is aborted */ + case 'COOKIE': return void Respond(void 0); case 'RESET': - return resetUserPins(store, safeKey, [], function (e) { - return void Respond(e); + return resetUserPins(store, safeKey, msg[1], function (e, hash) { + return void Respond(e, hash); }); - - - /* TODO - pin and unpin operations should respond with the new hash */ case 'PIN': - return pinChannel(store, safeKey, msg[1], function (e) { - Respond(e); + return pinChannel(store, safeKey, msg[1], function (e, hash) { + Respond(e, hash); }); case 'UNPIN': - return unpinChannel(store, safeKey, msg[1], function (e) { - Respond(e); + return unpinChannel(store, safeKey, msg[1], function (e, hash) { + Respond(e, hash); }); - case 'GET_HASH': - return void getHash(store, safeKey, function (hash) { - Respond(void 0, hash); + return void getHash(store, safeKey, function (e, hash) { + Respond(e, hash); }); case 'GET_TOTAL_SIZE': - return void Respond('NOT_IMPLEMENTED', msg); - case 'GET_FILE_SIZE': - if (!isValidChannel(msg[1])) { - return void Respond('INVALID_CHAN'); - } - - return void ctx.store.getChannelSize(msg[1], function (e, size) { - if (e) { return void Respond(e.code); } - Respond(void 0, size); + return getTotalSize(store, ctx.store, safeKey, function (e, size) { + if (e) { return void Respond(e); } + Respond(e, size); }); + case 'GET_FILE_SIZE': + return void getFileSize(ctx.store, msg[1], Respond); default: return void Respond('UNSUPPORTED_RPC_CALL', msg); } diff --git a/www/common/pinpad.js b/www/common/pinpad.js index f2f6bd04a..e40270311 100644 --- a/www/common/pinpad.js +++ b/www/common/pinpad.js @@ -28,34 +28,8 @@ define([ rpc.send('GET_FILE_SIZE', file, cb); }; - var getFileListSize = function (rpc, list, cb) { - var bytes = 0; - - var left = list.length; - - list.forEach(function (chan) { - getFileSize(rpc, chan, function (e, msg) { - if (e) { - if (e === 'ENOENT') { - - // these channels no longer exists on the server - console.log(e, chan); - } else { - console.error(e); - } - } else if (msg && msg[0] && typeof(msg[0]) === 'number') { - bytes += msg[0]; - //console.log(bytes); - } else { - console.log("returned message was not a number: ", msg); - } - - --left; - if (left === 0) { - cb(void 0, bytes); - } - }); - }); + var getFileListSize = function (rpc, cb) { + return rpc.send('GET_TOTAL_SIZE', undefined, cb); }; var pinChannel = function (rpc, channel, cb) { @@ -67,7 +41,8 @@ define([ }; var reset = function (rpc, cb) { - rpc.send('RESET', undefined, cb); + var list = uniqueChannelList(); + rpc.send('RESET', list, cb); }; /* @@ -80,7 +55,6 @@ define([ UNPIN all, send all */ - // Don't use create until Cryptpad is ready // (use Cryptpad.ready) var create = function (cb) { @@ -108,8 +82,8 @@ define([ exp.getFileSize = function (file, cb) { getFileSize(rpc, file, cb); }; - exp.getFileListSize = function (list, cb) { - getFileListSize(rpc, list, cb); + exp.getFileListSize = function (cb) { + getFileListSize(rpc, cb); }; exp.getServerHash = function (cb) { getServerHash(rpc, edPublic, cb); diff --git a/www/examples/pin/main.js b/www/examples/pin/main.js index 1c3df4d2f..903435d60 100644 --- a/www/examples/pin/main.js +++ b/www/examples/pin/main.js @@ -36,11 +36,6 @@ define([ console.log(msg); }); } - call.getFileListSize(list, function (e, bytes) { - if (e) { return void console.error(e); } - console.log("%s total bytes used", bytes); - }); - call.getServerHash(function (e, hash) { if (e) { return void console.error(e); } console.log("the server believes your user hash is [%s]", hash); @@ -51,6 +46,11 @@ define([ var localHash = call.localChannelsHash(); var serverHash; + call.getFileListSize(function (e, bytes) { + if (e) { return void console.error(e); } + console.log("%s total bytes used", bytes); + }); + call.getServerHash(function (e, hash) { if (e) { return void console.error(e); } serverHash = hash; @@ -61,15 +61,9 @@ define([ call.reset(function (e, response) { if (e) { return console.error(e); } - - var list = call.uniqueChannelList(); - - // now start pinning... - list.forEach(function (channel) { - call.pin(channel, function (e, out) { - if (e) { return console.error(e); } - }); - }); + else { + return console.log('reset pin list. new hash is [%s]', response); + } }); /* diff --git a/www/examples/rpc/index.html b/www/examples/rpc/index.html deleted file mode 100644 index e17a68143..000000000 --- a/www/examples/rpc/index.html +++ /dev/null @@ -1,13 +0,0 @@ - - -
-