From 9c0e924b13308e3c504c448001495b3508792a54 Mon Sep 17 00:00:00 2001 From: Yana Stamcheva Date: Mon, 23 Dec 2013 17:10:07 +0100 Subject: [PATCH] Improves password required interface and disables the padlock for participants. --- app.js | 130 ++++++++++++++++++++++++++++++++++++++++++--------------- muc.js | 12 ------ 2 files changed, 96 insertions(+), 46 deletions(-) diff --git a/app.js b/app.js index b63ad3c28..60213a54e 100644 --- a/app.js +++ b/app.js @@ -188,6 +188,9 @@ $(document).bind('entered.muc', function (event, jid, info) { focus.addNewParticipant(jid); } } + else if (sharedKey) { + updateLockButton(); + } }); $(document).bind('left.muc', function (event, jid) { @@ -208,6 +211,33 @@ $(document).bind('left.muc', function (event, jid) { } }); +$(document).bind('passwordrequired.muc', function (event, jid) { + console.log('on password required', jid); + + $.prompt('

Password required

' + + '', + { + persistent: true, + buttons: { "Ok": true , "Cancel": false}, + defaultButton: 1, + loaded: function(event) { + document.getElementById('lockKey').focus(); + }, + submit: function(e,v,m,f){ + if(v) + { + var lockKey = document.getElementById('lockKey'); + + if (lockKey.value != null) + { + setSharedKey(lockKey); + connection.emuc.doJoin(jid, lockKey.value); + } + } + } + }); +}); + function toggleVideo() { if (!(connection && connection.jingle.localStream)) return; for (var idx = 0; idx < connection.jingle.localStream.getVideoTracks().length; idx++) { @@ -357,44 +387,62 @@ function buttonClick(id, classname) { * Opens the lock room dialog. */ function openLockDialog() { - if (sharedKey) - $.prompt("Are you sure you would like to remove your secret key?", - { - title: "Remove secrect key", - persistent: false, - buttons: { "Remove": true, "Cancel": false}, - defaultButton: 1, - submit: function(e,v,m,f){ - if(v) - { - sharedKey = ''; - lockRoom(); - } - } - }); - else - $.prompt('

Set a secrect key to lock your room

' + - '', - { - persistent: false, - buttons: { "Save": true , "Cancel": false}, - defaultButton: 1, - loaded: function(event) { - document.getElementById('lockKey').focus(); - }, - submit: function(e,v,m,f){ - if(v) - { - var lockKey = document.getElementById('lockKey'); - - if (lockKey.value != null) - { - sharedKey = lockKey.value; + // Only the focus is able to set a shared key. + if (focus == null) { + if (sharedKey) + $.prompt("This conversation is currently protected by a shared secret key.", + { + title: "Secrect key", + persistent: false + }); + else + $.prompt("This conversation isn't currently protected by a secret key. Only the owner of the conference could set a shared key.", + { + title: "Secrect key", + persistent: false + }); + } + else { + if (sharedKey) + $.prompt("Are you sure you would like to remove your secret key?", + { + title: "Remove secrect key", + persistent: false, + buttons: { "Remove": true, "Cancel": false}, + defaultButton: 1, + submit: function(e,v,m,f){ + if(v) + { + setSharedKey(''); + lockRoom(); + } + } + }); + else + $.prompt('

Set a secrect key to lock your room

' + + '', + { + persistent: false, + buttons: { "Save": true , "Cancel": false}, + defaultButton: 1, + loaded: function(event) { + document.getElementById('lockKey').focus(); + }, + submit: function(e,v,m,f){ + if(v) + { + var lockKey = document.getElementById('lockKey'); + + if (lockKey.value) + { + console.log("LOCK KEY", lockKey.value); + setSharedKey(lockKey.value); lockRoom(true); - } + } } } }); + } } /* @@ -418,6 +466,20 @@ function openLinkDialog() { function lockRoom(lock) { connection.emuc.lockRoom(sharedKey); + updateLockButton(); +} + +/* + * Sets the shared key. + */ +function setSharedKey(sKey) { + sharedKey = sKey; +} + +/* + * Updates the lock button state. + */ +function updateLockButton() { buttonClick("#lockIcon", "fa fa-unlock fa-lg fa fa-lock fa-lg"); } diff --git a/muc.js b/muc.js index ccb55dfff..86048f670 100644 --- a/muc.js +++ b/muc.js @@ -75,18 +75,6 @@ Strophe.addConnectionPlugin('emuc', { var from = pres.getAttribute('from'); if ($(pres).find('>error[type="auth"]>not-authorized[xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"]').length) { $(document).trigger('passwordrequired.muc', [from]); - - // FIXME: remove once moved to passwordrequired which should reuse dojoin - var ob = this; - window.setTimeout(function () { - var given = window.prompt('Password required'); - if (given != null) { - // FIXME: reuse doJoin? - ob.connection.send($pres({to: ob.myroomjid }).c('x', {xmlns: 'http://jabber.org/protocol/muc'}).c('password').t(given)); - } else { - // user aborted - } - }, 50); } else { console.warn('onPresError ', pres); }