Got rid of direct usage of room locker

This commit is contained in:
Ilya Daynatovich 2016-10-21 18:03:25 +03:00
parent 257bb49c52
commit d4df6f2dda
3 changed files with 16 additions and 48 deletions

View File

@ -1,31 +0,0 @@
/* global APP, $ */
import UIUtil from '../util/UIUtil';
/**
* Show dialog which asks for required conference password.
* @returns {Promise<string>} password or nothing if user canceled
*/
export default function askForPassword () {
let titleKey = "dialog.passwordRequired";
let msgString = `
<input name="lockKey" type="text"
data-i18n="[placeholder]dialog.password"
autofocus>`;
return new Promise(function (resolve, reject) {
APP.UI.messageHandler.openTwoButtonDialog({
titleKey,
msgString,
leftButtonKey: "dialog.Ok",
submitFunction: $.noop,
closeFunction: function (e, v, m, f) {
if (v && f.lockKey) {
resolve(UIUtil.escapeHtml(f.lockKey));
} else {
reject(APP.UI.messageHandler.CANCEL);
}
},
focus: ':input:first'
});
});
}

View File

@ -32,7 +32,7 @@ class Invite {
error); error);
if (!locked) { if (!locked) {
this.roomLocker.resetPassword(); this.getRoomLocker().resetPassword();
} }
this.setLockedFromElsewhere(locked); this.setLockedFromElsewhere(locked);
@ -56,9 +56,10 @@ class Invite {
APP.UI.addListener( UIEvents.PASSWORD_REQUIRED, APP.UI.addListener( UIEvents.PASSWORD_REQUIRED,
() => { () => {
let roomLocker = this.getRoomLocker();
this.setLockedFromElsewhere(true); this.setLockedFromElsewhere(true);
this.roomLocker.requirePassword().then(() => { roomLocker.requirePassword().then(() => {
let pass = this.roomLocker.password; let pass = roomLocker.password;
// we received that password is required, but user is trying // we received that password is required, but user is trying
// anyway to login without a password, mark room as not // anyway to login without a password, mark room as not
// locked in case he succeeds (maybe someone removed the // locked in case he succeeds (maybe someone removed the
@ -67,7 +68,7 @@ class Invite {
// will be marked as locked. // will be marked as locked.
if (!pass) if (!pass)
this.setLockedFromElsewhere(false); this.setLockedFromElsewhere(false);
this.conference.join(this.roomLocker.password); this.conference.join(roomLocker.password);
}); });
}); });
} }
@ -129,7 +130,7 @@ class Invite {
* @returns {String} password * @returns {String} password
*/ */
getPassword() { getPassword() {
return this.roomLocker.password; return this.getRoomLocker().password;
} }
/** /**
@ -149,7 +150,7 @@ class Invite {
*/ */
setRoomUnlocked() { setRoomUnlocked() {
if (this.isModerator) { if (this.isModerator) {
this.roomLocker.lock().then(() => { this.getRoomLocker().lock().then(() => {
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK); APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
this.updateView(); this.updateView();
}); });
@ -164,8 +165,8 @@ class Invite {
*/ */
setRoomLocked(newPass) { setRoomLocked(newPass) {
let isModerator = this.isModerator; let isModerator = this.isModerator;
if (isModerator && (newPass || !this.roomLocker.isLocked)) { if (isModerator && (newPass || !this.getRoomLocker().isLocked)) {
this.roomLocker.lock(newPass).then(() => { this.getRoomLocker().lock(newPass).then(() => {
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK); APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
this.updateView(); this.updateView();
}); });
@ -187,7 +188,7 @@ class Invite {
* @returns {Boolean} isLocked * @returns {Boolean} isLocked
*/ */
isLocked() { isLocked() {
return this.roomLocker.isLocked; return this.getRoomLocker().isLocked;
} }
/** /**
@ -195,9 +196,10 @@ class Invite {
* @param isLocked * @param isLocked
*/ */
setLockedFromElsewhere(isLocked) { setLockedFromElsewhere(isLocked) {
let oldLockState = this.roomLocker.isLocked; let roomLocker = this.getRoomLocker();
let oldLockState = roomLocker.isLocked;
if (oldLockState !== isLocked) { if (oldLockState !== isLocked) {
this.roomLocker.lockedElsewhere = isLocked; roomLocker.lockedElsewhere = isLocked;
APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK); APP.UI.emitEvent(UIEvents.TOGGLE_ROOM_LOCK);
this.updateView(); this.updateView();
} }

View File

@ -23,19 +23,16 @@ export default class RequirePasswordDialog {
} }
_getBodyMessage() { _getBodyMessage() {
let passMsg = APP.translation.translateString("dialog.password");
let label = APP.translation.translateString(this.labelKey);
let error = APP.translation.translateString(this.errorKey);
return ( return (
`<div class="input-control"> `<div class="input-control">
<label class="input-control__label" <label class="input-control__label"
data-i18n="${this.labelKey}">${label}</label> data-i18n="${this.labelKey}"></label>
<input class="input-control__input" name="lockKey" type="text" <input class="input-control__input" name="lockKey" type="text"
data-i18n="[placeholder]dialog.password" data-i18n="[placeholder]dialog.password"
placeholder="${passMsg}" autofocus id="${this.inputId}"> autofocus id="${this.inputId}">
<p class="input-control__hint input-control__hint_error hide" <p class="input-control__hint input-control__hint_error hide"
id="${this.errorId}" id="${this.errorId}"
data-i18n="${this.errorKey}">${error}</p> data-i18n="${this.errorKey}"></p>
</div>` </div>`
); );
} }