diff --git a/src/js/main.js b/src/js/main.js index 9fdb1cf..0e9ced9 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -2,7 +2,6 @@ var fs = window.RequestFileSystem || window.webkitRequestFileSystem; $(function() { var isActive = false; - var encryptionEnabled = false; var newMessages = 0; var FADE_TIME = 150; // ms var TYPING_TIMER_LENGTH = 400; // ms @@ -22,15 +21,13 @@ $(function() { var $usernameInput = $('.usernameInput'); // Input for username var $messages = $('.messages'); // Messages area var $inputMessage = $('.inputMessage'); // Input message input box - var $key = $('#key'); + var $key = $('.key'); var $genKey = $('.new_key'); var $removeKey = $('#remove_key'); + var encryptionEnabled; var $chatPage = $('.chat.page'); // The chatroom page - var key = CryptoJS.SHA3(Math.random().toString(36).substring(7)).toString(); - $key.val(key); - // Prompt for setting a username var username; var connected = false; @@ -98,13 +95,11 @@ $(function() { } function encrypt(text) { - var key = encryptionEnabled ? $key.val() : roomId; - return CryptoJS.AES.encrypt(text, key).toString(); + return CryptoJS.AES.encrypt(text, $key.val()).toString(); } function decrypt(text) { - var key = encryptionEnabled ? $key.val() : roomId; - return CryptoJS.AES.decrypt(text, key).toString(CryptoJS.enc.Utf8) || text; + return CryptoJS.AES.decrypt(text, $key.val()).toString(CryptoJS.enc.Utf8) || text; } // Log a message @@ -274,6 +269,19 @@ $(function() { socket.on('login', function (data) { connected = true; addParticipantsMessage(data); + + var key = CryptoJS.SHA3(Math.random().toString(36).substring(7)).toString(); + + if (data.numUsers > 1) { + $('#join-modal').modal('show'); + key = ''; + encryptionEnabled = false; + $('.chat .warning-sign').show(); + } else { + encryptionEnabled = true; + $('.chat .warning-sign').hide(); + } + $key.val(key); }); // Whenever the server emits 'new message', update the chat body @@ -309,6 +317,10 @@ $(function() { removeChatTyping(data); }); + socket.on('first', function() { + $('#first-modal').modal('show'); + }); + setUsername(); $('span.key-btn').click(function() { @@ -362,30 +374,39 @@ $(function() { $('.room-url').text('https://fatty.chat' + roomId); $('.room-id').text(roomId.replace('/', '')); - $('#disable-encryption').hide(); - - $('.encryption-status').text('OFF'); - - $('.encryption-settings').hide(); - - $('#disable-encryption').click(function() { - encryptionEnabled = false; - $('.encryption-settings,#disable-encryption').hide(); - $('#enable-encryption').show(); - $('.encryption-status').text('OFF'); - $('.key-btn.inactive').show(); - $('.key-btn.active').hide(); - }); - - $('#enable-encryption').click(function() { - encryptionEnabled = true; - $('.encryption-settings,#disable-encryption').show(); - $('#enable-encryption').hide(); - $('.encryption-status').text('ON'); - $('.key-btn.inactive').hide(); - $('.key-btn.active').show(); - }); - $('[data-toggle="tooltip"]').tooltip(); + $('.key').on('input', function() { + var val = $(this).val(); + $('.key').val(val); + + if (!val.trim().length) { + encryptionEnabled = false; + $('.modal-footer button.encryption-inactive').show(); + $('.modal-footer button.encryption-active').hide(); + $('.chat .warning-sign').show(); + } else { + encryptionEnabled = true; + $('.modal-footer button.encryption-active').show(); + $('.modal-footer button.encryption-inactive').hide(); + $('.chat .warning-sign').hide(); + } + }); + + $('.modal-footer button.encryption-inactive').click(function() { + var n = noty({ + text: 'Encryption is OFF. Anyone with this URL can read your messages. Turn encryption on in Settings.', + theme: 'relax', + type: 'error' + }); + }); + + $('.chat .warning-sign').click(function() { + var n = noty({ + text: 'Encryption is OFF. Anyone with this URL can read your messages. Turn encryption on in Settings.', + theme: 'relax', + type: 'error' + }); + }); + }); diff --git a/src/public/style.css b/src/public/style.css index 8dae6ce..a4f5cb2 100644 --- a/src/public/style.css +++ b/src/public/style.css @@ -155,32 +155,28 @@ input { left: 0; outline: none; padding-left: 10px; - padding-right: 70px; position: absolute; right: 0; width: 100%; } -span.key-btn { - position: absolute; - right: 7px; - bottom: 8px; - cursor: pointer; -} - -span.key-btn img { - width: 35px; - top: -3px; - position: relative; -} - -span.key-btn.active { +#first-modal .modal-footer button.encryption-inactive { display: none; } -#key-modal input{ - width: 100%; - height: 50px; - padding: 0px 15px; -} +#join-modal .modal-footer button.encryption-active { + display: none; } + +.chat #input-icons { + position: absolute; + bottom: 15px; + right: 15px; +} + +.chat .warning-sign { + display: none; + cursor: pointer; + color: red; + font-size: 24px; +} \ No newline at end of file diff --git a/src/public/vendor/jquery.noty.packaged.min.js b/src/public/vendor/jquery.noty.packaged.min.js new file mode 100755 index 0000000..31059d7 --- /dev/null +++ b/src/public/vendor/jquery.noty.packaged.min.js @@ -0,0 +1 @@ +!function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof exports?module.exports=b(require("jquery")):b(a.jQuery)}(this,function(a){"function"!=typeof Object.create&&(Object.create=function(a){function b(){}return b.prototype=a,new b});var b={init:function(b){return this.options=a.extend({},a.noty.defaults,b),this.options.layout=this.options.custom?a.noty.layouts.inline:a.noty.layouts[this.options.layout],a.noty.themes[this.options.theme]?this.options.theme=a.noty.themes[this.options.theme]:this.options.themeClassName=this.options.theme,this.options=a.extend({},this.options,this.options.layout.options),this.options.id="noty_"+(new Date).getTime()*Math.floor(1e6*Math.random()),this._build(),this},_build:function(){var b=a('
').attr("id",this.options.id);if(b.append(this.options.template).find(".noty_text").html(this.options.text),this.$bar=null!==this.options.layout.parent.object?a(this.options.layout.parent.object).css(this.options.layout.parent.css).append(b):b,this.options.themeClassName&&this.$bar.addClass(this.options.themeClassName).addClass("noty_container_type_"+this.options.type),this.options.buttons){this.options.closeWith=[],this.options.timeout=!1;var c=a("
").addClass("noty_buttons");null!==this.options.layout.parent.object?this.$bar.find(".noty_bar").append(c):this.$bar.append(c);var d=this;a.each(this.options.buttons,function(b,c){var e=a("

- - +
+ +
@@ -84,27 +84,80 @@ + + + + + +