From 1ad2108e71fbfd441544e0f3b39dee2288c0e493 Mon Sep 17 00:00:00 2001 From: Hexagon Date: Fri, 26 Sep 2014 18:21:27 +0200 Subject: [PATCH] Mostly done! --- public/js/cryptalk_modules/client.js | 9 ++++++++- public/js/cryptalk_modules/console.js | 14 +++++++++----- public/js/cryptalk_modules/host.js | 3 --- public/js/cryptalk_modules/room.js | 4 ++++ public/js/cryptalk_modules/settings.js | 5 +++++ public/js/cryptalk_modules/templates.js | 3 +++ 6 files changed, 29 insertions(+), 9 deletions(-) diff --git a/public/js/cryptalk_modules/client.js b/public/js/cryptalk_modules/client.js index f723e73..1ed80b1 100644 --- a/public/js/cryptalk_modules/client.js +++ b/public/js/cryptalk_modules/client.js @@ -5,6 +5,7 @@ mediator.on('command:nick', ...); mediator.on('command:key', ...); mediator.on('command:clear', ...); + mediator.on('command:title', ...); Emits: mediator.emit('nick:changed',...); @@ -53,7 +54,7 @@ define( return mediator.emit('console:info', templates.messages.key_ok ); }, - help = function (payload, done) { mediator.emit('console:motd', templates.help); }, + help = function () { mediator.emit('console:motd', templates.help); }, clear = function () { mediator.emit('console:clear'); }, @@ -75,11 +76,17 @@ define( // Inform that the nick has been set mediator.emit('console:info', $.template(templates.messages.nick_set, { nick: $.escapeHtml(nick)})); + }, + + title = function(payload) { + mediator.emit('window:title',payload); + mediator.emit('console:info', $.template(templates.messages.title_set, { title: $.escapeHtml(payload)})); }; mediator.on('command:help', help); mediator.on('command:clear', clear); mediator.on('command:nick', nick); mediator.on('command:key', setKey); + mediator.on('command:title', title); }); \ No newline at end of file diff --git a/public/js/cryptalk_modules/console.js b/public/js/cryptalk_modules/console.js index 28c315a..7e1f2e4 100644 --- a/public/js/cryptalk_modules/console.js +++ b/public/js/cryptalk_modules/console.js @@ -89,12 +89,18 @@ define( message = function (payload, done) { post('message', payload.message , payload.nick ); }, server = function (payload, done) { post('server', payload); }, - clear = function () { + clearInput = function () { fandango.subordinate(function () { components.input[0].value = ''; }); }, + clear = function () { + fandango.subordinate(function () { + components.chat[0].innerHTML='' + }); + }, + lockInput = function () { components.input[0].setAttribute('disabled', 'disabled'); components.inputWrapper[0].className = 'loading'; @@ -140,7 +146,7 @@ define( if(recipients == 0) { return post('error', $.template(templates.messages.unrecognized_command, { commandName: command })); } else { - clear(); + clearInput(); } } ); @@ -151,8 +157,6 @@ define( // Make sure that the user has joined a room and the key is set return (!parameters.room) ? post('error', templates.messages.msg_no_room) : post('error', templates.messages.msg_no_key); } - - console.log(parameters.room); // Before sending the message. // Encrypt message using room UUID as salt and key as pepper. @@ -169,7 +173,7 @@ define( ); // And clear the the buffer - clear(); + clearInput(); } }; diff --git a/public/js/cryptalk_modules/host.js b/public/js/cryptalk_modules/host.js index 2df3fc3..cadc642 100644 --- a/public/js/cryptalk_modules/host.js +++ b/public/js/cryptalk_modules/host.js @@ -34,7 +34,6 @@ define( emit = function(payload) { // Route message from mediator to socket - console.log('EMIT:',payload.data,payload.payload); if(socket) socket.emit(payload.data,payload.payload); }, @@ -252,8 +251,6 @@ define( param = function (p) { parameters = fandango.merge({}, parameters, p ); - console.log(p); - console.log(parameters); }; mediator.on('command:host', host); diff --git a/public/js/cryptalk_modules/room.js b/public/js/cryptalk_modules/room.js index 9c5421a..790e6cf 100644 --- a/public/js/cryptalk_modules/room.js +++ b/public/js/cryptalk_modules/room.js @@ -31,6 +31,10 @@ define( join = function(payload) { if (room !== false) { mediator.emit('console:error',$.template(templates.messages.already_in_room, { room: room })); + } else if (payload.length >= settings.room.maxLen) { + mediator.emit('console:error',$.template(templates.messages.room_name_too_long)); + } else if (payload.length < settings.room.minLen) { + mediator.emit('console:error',$.template(templates.messages.room_name_too_short)); } else { room = payload; mediator.emit('room:changed', room ); diff --git a/public/js/cryptalk_modules/settings.js b/public/js/cryptalk_modules/settings.js index dfe07cf..efe2bac 100644 --- a/public/js/cryptalk_modules/settings.js +++ b/public/js/cryptalk_modules/settings.js @@ -29,6 +29,11 @@ define({ minLen: 8, }, + room: { + minLen: 1, + maxLen: 64 + }, + notifications: { maxOnePerMs: 3000 }, diff --git a/public/js/cryptalk_modules/templates.js b/public/js/cryptalk_modules/templates.js index 17ac774..55b0dfc 100644 --- a/public/js/cryptalk_modules/templates.js +++ b/public/js/cryptalk_modules/templates.js @@ -75,6 +75,9 @@ define({ unrecognized_command: 'Unrecognized command: "{commandName}"', + room_name_too_long: 'Isn\'t that a bit long?', + room_name_too_short: 'Nah, too short.', + joined_room: 'Joined room {roomName}.', left_room: 'Left room {roomName}.', already_in_room: 'You are already in a room ({room}), stoopid.',