diff --git a/README.md b/README.md index 78f0bdc..94c2fdd 100644 --- a/README.md +++ b/README.md @@ -53,4 +53,10 @@ Available commands: /clear Clear on-screen buffer /mute Toggle notification sounds /help This + + You can select any of the five last commands/messages with up/down key. + + Due to security reasons, /key command is not saved, and command + history is automatically cleared after one minute of inactivity. + ``` diff --git a/public/js/cryptalk_modules/cryptalk.js b/public/js/cryptalk_modules/cryptalk.js index 21094e2..ff26b18 100644 --- a/public/js/cryptalk_modules/cryptalk.js +++ b/public/js/cryptalk_modules/cryptalk.js @@ -16,6 +16,7 @@ define('cryptalk', { history = [], history_pos = -1, history_keep = 4, + history_timer, // Collection of DOM components components = { @@ -54,7 +55,7 @@ define('cryptalk', { components.chat.html(''); // Clear command history on clearing buffer - history = []; history_pos = -1; + clearHistory(); }, leave: function () { @@ -129,13 +130,19 @@ define('cryptalk', { } }, - // Push input buffer to command history + // Push input buffer to history pushHistory = function (b) { history.push(b); // Shift oldest buffer if we have more than we should keep if( history.length > history_keep ) history.shift(); }, + + // Clear input buffer history + clearHistory = function() { + history = []; + history_pos = -1; + }, // Handler for the document`s keyDown-event. onKeyDown = function (e) { @@ -151,6 +158,10 @@ define('cryptalk', { return components.input.focus(); } + // Reset command history clear timer + clearTimeout(history_timer); + history_timer = setTimeout(function(){clearHistory()}, 60000); + // Check for escape key, this does nothing but clear the input buffer and reset history position if ( e.keyCode == 27 ) { history_pos = -1; @@ -252,7 +263,7 @@ define('cryptalk', { post('info', $.template(templates.messages.left_room, { roomName: room })); // Clear history on leaving room - history = []; history_pos = -1; + clearHistory(); room = false; }) diff --git a/public/js/cryptalk_modules/templates.js b/public/js/cryptalk_modules/templates.js index 8535a5a..3c6cb6a 100644 --- a/public/js/cryptalk_modules/templates.js +++ b/public/js/cryptalk_modules/templates.js @@ -28,13 +28,18 @@ define({ ' /join RoomId Join a room \n' + ' /count Count participants of room \n' + ' /nick NickName Sets an optional nick \n' + - ' /mute Toggle notification sounds \n' + + ' /mute Toggle notification sounds \n' + ' /key OurStrongPassphrase Sets encryption key \n' + ' /leave Leave the room \n' + ' /clear Clear on-screen buffer \n' + ' /help This \n' + ' \n' + ' \n' + + 'You can select any of the five last commands/messages with up/down key.\n' + + ' \n' + + 'Due to security reasons, /key command is not saved, and command \n' + + 'history is automatically cleared after one minute of inactivity. \n' + + ' \n' + 'It is highly recommended to use incognito mode while chatting, \n' + 'to prevent browsers from keeping history or cache. \n' + ' \n' +