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 @@ - - - - CryptPad - - - - -
- -
- - diff --git a/www/examples/rpc/inner.html b/www/examples/rpc/inner.html deleted file mode 100644 index 9680685b7..000000000 --- a/www/examples/rpc/inner.html +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - -

PEWPEW diff --git a/www/examples/rpc/main.js b/www/examples/rpc/main.js deleted file mode 100644 index 5ddccb2d7..000000000 --- a/www/examples/rpc/main.js +++ /dev/null @@ -1,111 +0,0 @@ -require.config({ paths: { 'json.sortify': '/bower_components/json.sortify/dist/JSON.sortify' } }); -define([ - '/common/cryptpad-common.js', - '/common/rpc.js', - '/bower_components/jquery/dist/jquery.min.js', -], function (Cryptpad, RPC) { - var $ = window.jQuery; - var APP = window.APP = { - Cryptpad: Cryptpad, - }; - - $(function () { - Cryptpad.ready(function (err, env) { - var network = Cryptpad.getNetwork(); - var proxy = Cryptpad.getStore().getProxy().proxy; - - var edPrivate = proxy.edPrivate; - var edPublic = proxy.edPublic; - - var payload = { - a: Math.floor(Math.random() * 1000), - b: 7, - }; - - RPC.create(network, edPrivate, edPublic, function (e, rpc) { - // console.log(payload); - rpc.send('ECHO', payload, function (e, msg) { - if (e) { return void console.error(e); } - console.log(msg); - }); - - // test a non-existent RPC call - rpc.send('PEWPEW', ['pew'], function (e, msg) { - if (e) { - if (e === 'UNSUPPORTED_RPC_CALL') { return; } - return void console.error(e); - } - console.log(msg); - }); - - var list = Cryptpad.getUserChannelList(); - if (list.length) { - rpc.send('GET_FILE_SIZE', list[0], function (e, msg) { - if (e) { - return void console.error(e); - } - console.log(msg); - }); - } - - rpc.send('GET_FILE_SIZE', 'pewpew', function (e, msg) { - if (e) { - if (e === 'INVALID_CHAN') { return; } - return void console.error(e); - } - console.log(msg); - }); - - rpc.send('GET_FILE_SIZE', '26f014b2ab959418605ea37a6785f317', function (e, msg) { - if (e) { - if (e === 'ENOENT') { return; } - return void console.error(e); - } - console.error("EXPECTED ENOENT"); - console.log(msg); - }); - - (function () { - // compute what you think the hash should be - - // then ask the server if what it has matches your records - rpc.send('GET_HASH', edPublic, function (e, hash) { - if (e) { return void console.error(e); } - - - console.log("user pins hash is [%s]", hash); - // if it does, awesome! - // you should be able to pin and unpin things easily - - // if it doesn't, send a reset, and start re-pinning - - - - }); - }()); - - if (false) { - (function () { - var bytes = 0; - list.forEach(function (chan) { - rpc.send('GET_FILE_SIZE', chan, function (e, msg) { - if (e) { - if (e === 'ENOENT') { - return void console.log(e, chan); - } - return void console.error(e); - } - if (msg && msg[0] && typeof(msg[0]) === 'number') { - bytes += msg[0]; - console.log(bytes); - } else { - console.log(msg); - } - }); - }); - }()); - } - }); - }); - }); -}); diff --git a/www/whiteboard/main.js b/www/whiteboard/main.js index f8e28bddc..7939658f7 100644 --- a/www/whiteboard/main.js +++ b/www/whiteboard/main.js @@ -13,10 +13,11 @@ define([ '/common/cryptpad-common.js', '/common/visible.js', '/common/notify.js', + '/customize/application_config.js', '/bower_components/secure-fabric.js/dist/fabric.min.js', '/bower_components/jquery/dist/jquery.min.js', '/bower_components/file-saver/FileSaver.min.js', -], function (Config, Realtime, Crypto, Toolbar, TextPatcher, JSONSortify, JsonOT, Cryptpad, Visible, Notify) { +], function (Config, Realtime, Crypto, Toolbar, TextPatcher, JSONSortify, JsonOT, Cryptpad, Visible, Notify, AppConfig) { var saveAs = window.saveAs; var Messages = Cryptpad.Messages; @@ -102,16 +103,12 @@ define([ $width.on('change', updateBrushWidth); var pickColor = function (current, cb) { - // TODO find out why initial color is not being set - // http://jsfiddle.net/j3hZB/ - console.log(current); var $picker = $('', { type: 'color', value: '#FFFFFF', }) .css({ visibility: 'hidden' - //display: 'none', }) .on('change', function () { var color = this.value; @@ -140,9 +137,10 @@ define([ return "#" + hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]); }; - // TODO add a better color palette - var palette = ['red', 'blue', 'green', 'white', 'black', 'purple', - 'gray', 'beige', 'brown', 'cyan', 'darkcyan', 'gold', 'yellow', 'pink']; + var palette = AppConfig.whiteboardPalette || [ + 'red', 'blue', 'green', 'white', 'black', 'purple', + 'gray', 'beige', 'brown', 'cyan', 'darkcyan', 'gold', 'yellow', 'pink' + ]; $('.palette-color').on('click', function () { var color = $(this).css('background-color');