optimisation of ternary & binary expr.

pull/726/head
Vincent 5 years ago
parent e065cc404f
commit 010cf045cb

@ -1204,7 +1204,8 @@
"description": "Subtitle for beta disclaimer modal" "description": "Subtitle for beta disclaimer modal"
}, },
"betaDisclaimerDescription": { "betaDisclaimerDescription": {
"message": "While your messages are secured with end-to-end encryption, third parties like your ISP can see who you're talking to while in the beta version. It is also possible that third parties could correlate your public key to your IP address and real identity if they learn your public key.", "message":
"While your messages are secured with end-to-end encryption, third parties like your ISP can see who you're talking to while in the beta version. It is also possible that third parties could correlate your public key to your IP address and real identity if they learn your public key.",
"description": "Description for beta disclaimer modal" "description": "Description for beta disclaimer modal"
}, },
"quoteThumbnailAlt": { "quoteThumbnailAlt": {
@ -2153,33 +2154,27 @@
}, },
"setAccountPasswordTitle": { "setAccountPasswordTitle": {
"message": "Set Account Password", "message": "Set Account Password",
"description": "description": "Prompt for user to set account password in settings view"
"Prompt for user to set account password in settings view"
}, },
"setAccountPasswordDescription": { "setAccountPasswordDescription": {
"message": "Secure your account and public key with a password", "message": "Secure your account and public key with a password",
"description": "description": "Description for set account password setting view"
"Description for set account password setting view"
}, },
"changeAccountPasswordTitle": { "changeAccountPasswordTitle": {
"message": "Change Account Password", "message": "Change Account Password",
"description": "description": "Prompt for user to change account password in settings view"
"Prompt for user to change account password in settings view"
}, },
"changeAccountPasswordDescription": { "changeAccountPasswordDescription": {
"message": "Change your password", "message": "Change your password",
"description": "description": "Description for change account password setting view"
"Description for change account password setting view"
}, },
"removeAccountPasswordTitle": { "removeAccountPasswordTitle": {
"message": "Remove Account Password", "message": "Remove Account Password",
"description": "description": "Prompt for user to remove account password in settings view"
"Prompt for user to remove account password in settings view"
}, },
"removeAccountPasswordDescription": { "removeAccountPasswordDescription": {
"message": "Remove the password associated with your account", "message": "Remove the password associated with your account",
"description": "description": "Description for remove account password setting view"
"Description for remove account password setting view"
}, },
"enterPassword": { "enterPassword": {
"message": "Please enter your password" "message": "Please enter your password"

@ -71,7 +71,8 @@ const {
SessionSeedModal, SessionSeedModal,
} = require('../../ts/components/session/SessionSeedModal'); } = require('../../ts/components/session/SessionSeedModal');
const { SessionPasswordModal, const {
SessionPasswordModal,
} = require('../../ts/components/session/SessionPasswordModal'); } = require('../../ts/components/session/SessionPasswordModal');
const { const {

@ -30,10 +30,9 @@
return this; return this;
}, },
close () { close() {
window.storage.put('betaReleaseDisclaimerAccepted', true); window.storage.put('betaReleaseDisclaimerAccepted', true);
this.remove(); this.remove();
}, },
}); });
})(); })();

@ -1,228 +0,0 @@
/* global Whisper, i18n, _, Signal, passwordUtil */
// eslint-disable-next-line func-names
(function() {
'use strict';
window.Whisper = window.Whisper || {};
const PasswordDialogView = Whisper.View.extend({
className: 'loki-dialog password-dialog modal',
templateName: 'password-dialog',
initialize(options) {
this.type = options.type;
this.resolve = options.resolve;
this.okText = options.okText || i18n('ok');
this.reject = options.reject;
this.cancelText = options.cancelText || i18n('cancel');
this.title = options.title;
this.render();
this.updateUI();
},
events: {
keyup: 'onKeyup',
'click .ok': 'ok',
'click .cancel': 'cancel',
},
render_attributes() {
return {
showCancel: !this.hideCancel,
cancel: this.cancelText,
ok: this.okText,
title: this.title,
};
},
async updateUI() {
if (this.disableOkButton()) {
this.$('.ok').prop('disabled', true);
} else {
this.$('.ok').prop('disabled', false);
}
},
disableOkButton() {
const password = this.$('#password').val();
return _.isEmpty(password);
},
async validate() {
const password = this.$('#password').val();
const passwordConfirmation = this.$('#password-confirmation').val();
const pairValidation = this.validatePasswordPair(
password,
passwordConfirmation
);
const hashValidation = await this.validatePasswordHash(password);
return pairValidation || hashValidation;
},
async validatePasswordHash(password) {
// Check if the password matches the hash we have stored
const hash = await Signal.Data.getPasswordHash();
if (hash && !passwordUtil.matchesHash(password, hash)) {
return i18n('invalidPassword');
}
return null;
},
validatePasswordPair(password, passwordConfirmation) {
if (!_.isEmpty(password)) {
// Check if the password is first valid
const passwordValidation = passwordUtil.validatePassword(
password,
i18n
);
if (passwordValidation) {
return passwordValidation;
}
// Check if the confirmation password is the same
if (
!passwordConfirmation ||
password.trim() !== passwordConfirmation.trim()
) {
return i18n('passwordsDoNotMatch');
}
}
return null;
},
okPressed() {
const password = this.$('#password').val();
if (this.type === 'set') {
window.setPassword(password.trim());
} else if (this.type === 'remove') {
window.setPassword(null, password.trim());
}
},
okErrored() {
if (this.type === 'set') {
this.showError(i18n('setPasswordFail'));
} else if (this.type === 'remove') {
this.showError(i18n('removePasswordFail'));
}
},
async ok() {
const error = await this.validate();
if (error) {
this.showError(error);
return;
}
// Clear any errors
this.showError(null);
try {
this.okPressed();
this.remove();
if (this.resolve) {
this.resolve();
}
} catch (e) {
this.okErrored();
}
},
cancel() {
this.remove();
if (this.reject) {
this.reject();
}
},
onKeyup(event) {
this.updateUI();
switch (event.key) {
case 'Enter':
this.ok();
break;
case 'Escape':
case 'Esc':
this.cancel();
break;
default:
return;
}
event.preventDefault();
},
focusCancel() {
this.$('.cancel').focus();
},
showError(message) {
if (_.isEmpty(message)) {
this.$('.error').text('');
this.$('.error').hide();
} else {
this.$('.error').text(`Error: ${message}`);
this.$('.error').show();
}
},
});
const ChangePasswordDialogView = PasswordDialogView.extend({
templateName: 'password-change-dialog',
disableOkButton() {
const oldPassword = this.$('#old-password').val();
const newPassword = this.$('#new-password').val();
return _.isEmpty(oldPassword) || _.isEmpty(newPassword);
},
async validate() {
const oldPassword = this.$('#old-password').val();
// Validate the old password
if (!_.isEmpty(oldPassword)) {
const oldPasswordValidation = passwordUtil.validatePassword(
oldPassword,
i18n
);
if (oldPasswordValidation) {
return oldPasswordValidation;
}
} else {
return i18n('typeInOldPassword');
}
const password = this.$('#new-password').val();
const passwordConfirmation = this.$('#new-password-confirmation').val();
const pairValidation = this.validatePasswordPair(
password,
passwordConfirmation
);
const hashValidation = await this.validatePasswordHash(oldPassword);
return pairValidation || hashValidation;
},
okPressed() {
const oldPassword = this.$('#old-password').val();
const newPassword = this.$('#new-password').val();
window.setPassword(newPassword.trim(), oldPassword.trim());
},
okErrored() {
this.showError(i18n('changePasswordFail'));
},
});
Whisper.getPasswordDialogView = (type, resolve, reject) => {
// This is a differently styled dialog
if (type === 'change') {
return new ChangePasswordDialogView({
title: i18n('changePassword'),
okTitle: i18n('change'),
resolve,
reject,
});
}
// Set and Remove is basically the same UI
const title =
type === 'remove' ? i18n('removePassword') : i18n('setPassword');
const okTitle = type === 'remove' ? i18n('remove') : i18n('set');
return new PasswordDialogView({
title,
okTitle,
type,
resolve,
reject,
});
};
})();

@ -17,7 +17,6 @@
}, },
render() { render() {
this.dialogView = new Whisper.ReactWrapperView({ this.dialogView = new Whisper.ReactWrapperView({
className: 'password-dialog-wrapper', className: 'password-dialog-wrapper',
Component: window.Signal.Components.SessionPasswordModal, Component: window.Signal.Components.SessionPasswordModal,
@ -28,7 +27,6 @@
}, },
}); });
this.$el.append(this.dialogView.el); this.$el.append(this.dialogView.el);
return this; return this;
}, },
@ -42,7 +40,5 @@
close() { close() {
this.remove(); this.remove();
}, },
}); });
})(); })();

@ -53,7 +53,6 @@ const config = require('./app/config');
const userConfig = require('./app/user_config'); const userConfig = require('./app/user_config');
const passwordUtil = require('./app/password_util'); const passwordUtil = require('./app/password_util');
const importMode = const importMode =
process.argv.some(arg => arg === '--import') || config.get('import'); process.argv.some(arg => arg === '--import') || config.get('import');

@ -26,7 +26,6 @@ window.Signal = Signal.setup({
window.passwordUtil = require('./app/password_util'); window.passwordUtil = require('./app/password_util');
window.resetDatabase = () => { window.resetDatabase = () => {
window.log.info('reset database'); window.log.info('reset database');
ipcRenderer.send('resetDatabase'); ipcRenderer.send('resetDatabase');

@ -467,11 +467,6 @@ contextMenu({
}, },
}); });
// User config for managing password DB entries etc.
const thisfaw = require('./app/password_util');
console.log(thisfaw);
// We pull this in last, because the native module involved appears to be sensitive to // We pull this in last, because the native module involved appears to be sensitive to
// /tmp mounted as noexec on Linux. // /tmp mounted as noexec on Linux.
require('./js/spell_check'); require('./js/spell_check');

@ -170,7 +170,6 @@
background-color: rgba(255, 197, 50, 0.2); background-color: rgba(255, 197, 50, 0.2);
} }
.module-conversation-list-item--mentioned-us { .module-conversation-list-item--mentioned-us {
border-left: 4px solid #ffb000 !important; border-left: 4px solid #ffb000 !important;
} }

@ -340,7 +340,7 @@ $session_message-container-border-radius: 5px;
border-radius: 0px; border-radius: 0px;
} }
& > *:not(svg):hover{ & > *:not(svg):hover {
filter: brightness(80%); filter: brightness(80%);
} }
} }
@ -494,7 +494,7 @@ label {
.module-conversation-header { .module-conversation-header {
position: relative; position: relative;
padding: 0px $session-margin-lg 0px $session-margin-sm padding: 0px $session-margin-lg 0px $session-margin-sm;
} }
.title-wrapper { .title-wrapper {
@ -1121,9 +1121,7 @@ input {
width: 40vh; width: 40vh;
} }
.session-beta-disclaimer { .session-beta-disclaimer {
.session-modal { .session-modal {
width: 600px; width: 600px;
@ -1131,7 +1129,7 @@ input {
font-size: 17px; font-size: 17px;
} }
&__body > div:first-child{ &__body > div:first-child {
padding: $session-margin-lg; padding: $session-margin-lg;
} }
@ -1151,7 +1149,7 @@ button.module-scroll-down {
background-color: $session-shade-6; background-color: $session-shade-6;
} }
&__button:hover{ &__button:hover {
&__icon { &__icon {
transition: $session-transition-duration; transition: $session-transition-duration;
@include color-svg('../images/down.svg', $session-color-white); @include color-svg('../images/down.svg', $session-color-white);
@ -1161,13 +1159,11 @@ button.module-scroll-down {
&__icon { &__icon {
@include color-svg('../images/down.svg', rgba($session-color-white, 0.6)); @include color-svg('../images/down.svg', rgba($session-color-white, 0.6));
} }
} }
/* Memberlist */ /* Memberlist */
.member-list-container .member { .member-list-container .member {
&-item {
&-item{
padding: $session-margin-sm; padding: $session-margin-sm;
background-color: $session-shade-5; background-color: $session-shade-5;
@ -1180,4 +1176,3 @@ button.module-scroll-down {
background-color: $session-shade-8; background-color: $session-shade-8;
} }
} }

@ -381,7 +381,6 @@ $session-compose-margin: 20px;
border: 1px solid $session-shade-7; border: 1px solid $session-shade-7;
} }
} }
} }
.contacts-dropdown { .contacts-dropdown {

@ -8,7 +8,7 @@ import {
export const MainViewController = { export const MainViewController = {
renderMessageView: () => { renderMessageView: () => {
if(document.getElementById('main-view')) { if (document.getElementById('main-view')) {
ReactDOM.render(<MessageView />, document.getElementById('main-view')); ReactDOM.render(<MessageView />, document.getElementById('main-view'));
} }
}, },
@ -29,7 +29,11 @@ export class MessageView extends React.Component {
<div className="conversation-header" /> <div className="conversation-header" />
<div className="container"> <div className="container">
<div className="content"> <div className="content">
<img src="images/session/full-logo.svg" className="session-full-logo" alt="full-brand-logo"/> <img
src="images/session/full-logo.svg"
className="session-full-logo"
alt="full-brand-logo"
/>
</div> </div>
</div> </div>
</div> </div>

@ -2,7 +2,12 @@ import React from 'react';
import { Avatar } from '../Avatar'; import { Avatar } from '../Avatar';
import { Colors, LocalizerType } from '../../types/Util'; import { Colors, LocalizerType } from '../../types/Util';
import { ContextMenu, ContextMenuTrigger, MenuItem, SubMenu } from 'react-contextmenu'; import {
ContextMenu,
ContextMenuTrigger,
MenuItem,
SubMenu,
} from 'react-contextmenu';
import { import {
SessionIconButton, SessionIconButton,
@ -251,12 +256,16 @@ export class ConversationHeader extends React.Component<Props> {
} }
return ( return (
<ContextMenuTrigger id={triggerId} ref={this.menuTriggerRef} holdToDisplay={1}> <ContextMenuTrigger
<SessionIconButton id={triggerId}
iconType={SessionIconType.Ellipses} ref={this.menuTriggerRef}
iconSize={SessionIconSize.Large} holdToDisplay={1}
onClick={this.showMenuBound} >
/> <SessionIconButton
iconType={SessionIconType.Ellipses}
iconSize={SessionIconSize.Large}
onClick={this.showMenuBound}
/>
</ContextMenuTrigger> </ContextMenuTrigger>
); );
} }

@ -73,7 +73,9 @@ export class LeftPaneSettingSection extends React.Component<any, State> {
item.id === this.state.settingCategory ? 'active' : '' item.id === this.state.settingCategory ? 'active' : ''
)} )}
role="link" role="link"
onClick={(): void => this.setCategory(item.id)} onClick={() => {
this.setCategory(item.id);
}}
> >
<div> <div>
<strong>{item.title}</strong> <strong>{item.title}</strong>

@ -1,12 +1,12 @@
import React from 'react'; import React from 'react';
import { SessionModal } from './SessionModal'; import { SessionModal } from './SessionModal';
import { SessionButton, SessionButtonType, SessionButtonColor } from './SessionButton'; import { SessionButton, SessionButtonColor } from './SessionButton';
export enum PasswordAction { export enum PasswordAction {
Set = 'set', Set = 'set',
Change = 'change', Change = 'change',
Remove = 'remove' Remove = 'remove',
} }
interface Props { interface Props {
@ -25,7 +25,7 @@ export class SessionPasswordModal extends React.Component<Props, State> {
this.state = { this.state = {
error: null, error: null,
} };
this.showError = this.showError.bind(this); this.showError = this.showError.bind(this);
@ -36,63 +36,95 @@ export class SessionPasswordModal extends React.Component<Props, State> {
public render() { public render() {
const { action, onOk } = this.props; const { action, onOk } = this.props;
const placeholders = this.props.action === PasswordAction.Change const placeholders =
? [window.i18n('typeInOldPassword'), window.i18n('enterPassword')] this.props.action === PasswordAction.Change
: [window.i18n('enterPassword'), window.i18n('confirmPassword')] ? [window.i18n('typeInOldPassword'), window.i18n('enterPassword')]
: [window.i18n('enterPassword'), window.i18n('confirmPassword')];
const confirmButtonColor = this.props.action === PasswordAction.Remove const confirmButtonColor =
? SessionButtonColor.Danger this.props.action === PasswordAction.Remove
: SessionButtonColor.Primary ? SessionButtonColor.Danger
: SessionButtonColor.Primary;
return ( return (
<SessionModal <SessionModal
title={window.i18n(`${action}Password`)} title={window.i18n(`${action}Password`)}
onOk={() => null} onOk={() => null}
onClose={this.closeDialog} onClose={this.closeDialog}
> >
<div className="spacer-sm"></div> <div className="spacer-sm" />
<div className="session-modal__input-group"> <div className="session-modal__input-group">
<input
type="password"
id="password-modal-input"
placeholder={placeholders[0]}
/>
{action !== PasswordAction.Remove && (
<input <input
type="password" type="password"
id="password-modal-input" id="password-modal-input-confirm"
placeholder={placeholders[0]} placeholder={placeholders[1]}
/>
{ action !== PasswordAction.Remove && (
<input
type="password"
id="password-modal-input-confirm"
placeholder={placeholders[1]}
/>
)}
</div>
<div className="spacer-sm" />
{this.showError()}
<div className="session-modal__button-group">
<SessionButton
text={window.i18n('ok')}
buttonColor={confirmButtonColor}
onClick={() => this.setPassword(onOk)}
/> />
)}
</div>
<div className="spacer-sm" />
{this.showError()}
<div className="session-modal__button-group">
<SessionButton
text={window.i18n('ok')}
buttonColor={confirmButtonColor}
onClick={async () => this.setPassword(onOk)}
/>
<SessionButton
text={window.i18n('cancel')}
onClick={this.closeDialog}
/>
</div>
</SessionModal>
);
}
<SessionButton text={window.i18n('cancel')} onClick={this.closeDialog} /> public async validatePasswordHash(password: string | null) {
</div> // Check if the password matches the hash we have stored
const hash = await window.Signal.Data.getPasswordHash();
if (hash && !window.passwordUtil.matchesHash(password, hash)) {
return false;
}
</SessionModal> return true;
); }
private showError() {
const message = this.state.error;
return (
<>
{message && (
<>
<div className="session-label warning">{message}</div>
<div className="spacer-lg" />
</>
)}
</>
);
} }
private async setPassword(onSuccess: any) { private async setPassword(onSuccess: any) {
const enteredPassword = String($('#password-modal-input').val()); const enteredPassword = String($('#password-modal-input').val());
const enteredPasswordConfirm = String($('#password-modal-input-confirm').val()); const enteredPasswordConfirm = String(
$('#password-modal-input-confirm').val()
);
// Check passwords enntered // Check passwords enntered
if ((enteredPassword.length === 0) || if (
((this.props.action === PasswordAction.Change) && enteredPassword.length === 0 ||
(enteredPasswordConfirm.length === 0))){ (this.props.action === PasswordAction.Change &&
enteredPasswordConfirm.length === 0)
) {
this.setState({ this.setState({
error: window.i18n('noGivenPassword'), error: window.i18n('noGivenPassword'),
}); });
@ -101,20 +133,20 @@ export class SessionPasswordModal extends React.Component<Props, State> {
} }
// Passwords match or remove password successful // Passwords match or remove password successful
const newPassword = this.props.action === PasswordAction.Remove const newPassword =
? null this.props.action === PasswordAction.Remove
: enteredPasswordConfirm; ? null
const oldPassword = this.props.action === PasswordAction.Set : enteredPasswordConfirm;
? null const oldPassword =
: enteredPassword; this.props.action === PasswordAction.Set ? null : enteredPassword;
// Check if password match, when setting, changing or removing // Check if password match, when setting, changing or removing
const valid = this.props.action !== PasswordAction.Set const valid =
? !! await this.validatePasswordHash(oldPassword) this.props.action !== PasswordAction.Set
: (enteredPassword === enteredPasswordConfirm); ? !!await this.validatePasswordHash(oldPassword)
: enteredPassword === enteredPasswordConfirm;
if (!valid){ if (!valid) {
this.setState({ this.setState({
error: window.i18n(`${this.props.action}PasswordInvalid`), error: window.i18n(`${this.props.action}PasswordInvalid`),
}); });
@ -124,60 +156,35 @@ export class SessionPasswordModal extends React.Component<Props, State> {
await window.setPassword(newPassword, oldPassword); await window.setPassword(newPassword, oldPassword);
const toastParams = { const toastParams = {
title: window.i18n(`${this.props.action}PasswordTitle`), title: window.i18n(`${this.props.action}PasswordTitle`),
description: window.i18n(`${this.props.action}PasswordToastDescription`), description: window.i18n(`${this.props.action}PasswordToastDescription`),
type: this.props.action !== PasswordAction.Remove ? 'success' : 'warning', type: this.props.action !== PasswordAction.Remove ? 'success' : 'warning',
icon: this.props.action !== PasswordAction.Remove ? 'lock' : undefined, icon: this.props.action !== PasswordAction.Remove ? 'lock' : undefined,
} };
window.pushToast({ window.pushToast({
id: "set-password-success-toast", id: 'set-password-success-toast',
...toastParams ...toastParams,
}); });
onSuccess(this.props.action); onSuccess(this.props.action);
this.closeDialog(); this.closeDialog();
}
public async validatePasswordHash(password: string | null) {
// Check if the password matches the hash we have stored
const hash = await window.Signal.Data.getPasswordHash();
if (hash && !window.passwordUtil.matchesHash(password, hash)) {
return false;
}
return true;
}
private showError() {
const message = this.state.error;
return (
<>
{message && (
<>
<div className="session-label warning">{message}</div>
<div className="spacer-lg" />
</>
)}
</>
);
} }
private onEnter(event: any) { private onEnter(event: any) {
if (event.key === 'Enter') { if (event.key === 'Enter') {
//if ($('#server-url').is(':focus')) { //if ($('#server-url').is(':focus')) {
//this.showView('connecting'); //this.showView('connecting');
//} //}
} }
} }
private closeDialog() { private closeDialog() {
window.removeEventListener('keyup', this.onEnter); window.removeEventListener('keyup', this.onEnter);
this.props.onClose && this.props.onClose();
}
if (this.props.onClose) {
this.props.onClose();
}
}
} }

@ -38,10 +38,9 @@ export class SessionToast extends React.PureComponent<Props> {
? SessionIconSize.Large ? SessionIconSize.Large
: SessionIconSize.Medium; : SessionIconSize.Medium;
// Set a custom icon or allow the theme to define the icon // Set a custom icon or allow the theme to define the icon
let toastIcon = icon || undefined; let toastIcon = icon || undefined;
if (! toastIcon ){ if (!toastIcon) {
switch (type) { switch (type) {
case SessionToastType.Info: case SessionToastType.Info:
toastIcon = SessionIconType.Info; toastIcon = SessionIconType.Info;
@ -58,7 +57,7 @@ export class SessionToast extends React.PureComponent<Props> {
default: default:
toastIcon = SessionIconType.Info; toastIcon = SessionIconType.Info;
} }
} }
return ( return (
<div className={classNames('session-toast', toastType)}> <div className={classNames('session-toast', toastType)}>

@ -90,12 +90,14 @@ export class SessionSettingListItem extends React.Component<Props, State> {
{type === SessionSettingType.Slider && ( {type === SessionSettingType.Slider && (
<div className="slider-wrapper"> <div className="slider-wrapper">
<Slider <Slider
dots dots={true}
step={6} step={6}
min={12} min={12}
max={96} max={96}
defaultValue={currentSliderValue} defaultValue={currentSliderValue}
onAfterChange={value => this.handleSlider(value)} onAfterChange={sliderValue => {
this.handleSlider(sliderValue);
}}
/> />
<div className="slider-info"> <div className="slider-info">
<p>{`${currentSliderValue} Hours`}</p> <p>{`${currentSliderValue} Hours`}</p>
@ -114,7 +116,9 @@ export class SessionSettingListItem extends React.Component<Props, State> {
} }
private handleSlider(value: any) { private handleSlider(value: any) {
this.props.onSliderChange && this.props.onSliderChange(value); if (this.props.onSliderChange) {
this.props.onSliderChange(value);
}
this.setState({ this.setState({
sliderValue: value, sliderValue: value,

@ -26,8 +26,6 @@ export interface SettingsViewProps {
interface State { interface State {
hasPassword: boolean | null; hasPassword: boolean | null;
changedPassword: boolean | null;
removedPassword:
} }
export class SettingsView extends React.Component<SettingsViewProps, State> { export class SettingsView extends React.Component<SettingsViewProps, State> {
@ -38,7 +36,7 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
this.state = { this.state = {
hasPassword: null, hasPassword: null,
} };
this.settingsViewRef = React.createRef(); this.settingsViewRef = React.createRef();
this.onPasswordUpdated = this.onPasswordUpdated.bind(this); this.onPasswordUpdated = this.onPasswordUpdated.bind(this);
@ -46,6 +44,7 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
this.hasPassword(); this.hasPassword();
} }
/* tslint:disable-next-line:max-func-body-length */
public renderSettingInCategory() { public renderSettingInCategory() {
const { Settings } = window.Signal.Types; const { Settings } = window.Signal.Types;
@ -137,7 +136,6 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
setFn: window.toggleMediaPermissions, setFn: window.toggleMediaPermissions,
content: {}, content: {},
}, },
{ {
id: 'message-ttl', id: 'message-ttl',
title: window.i18n('messageTTL'), title: window.i18n('messageTTL'),
@ -147,7 +145,7 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
category: SessionSettingCategory.Privacy, category: SessionSettingCategory.Privacy,
setFn: undefined, setFn: undefined,
content: { content: {
defaultValue: 24 defaultValue: 24,
}, },
}, },
{ {
@ -162,10 +160,11 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
buttonText: window.i18n('setPassword'), buttonText: window.i18n('setPassword'),
buttonColor: SessionButtonColor.Primary, buttonColor: SessionButtonColor.Primary,
}, },
onClick: () => window.showPasswordDialog({ onClick: () =>
action: 'set', window.showPasswordDialog({
onSuccess: this.onPasswordUpdated, action: 'set',
}), onSuccess: this.onPasswordUpdated,
}),
}, },
{ {
id: 'change-password', id: 'change-password',
@ -176,13 +175,14 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
category: SessionSettingCategory.Privacy, category: SessionSettingCategory.Privacy,
setFn: undefined, setFn: undefined,
content: { content: {
buttonText: window.i18n('changePassword'), buttonText: window.i18n('changePassword'),
buttonColor: SessionButtonColor.Primary, buttonColor: SessionButtonColor.Primary,
}, },
onClick: () => window.showPasswordDialog({ onClick: () =>
action: 'change', window.showPasswordDialog({
onSuccess: this.onPasswordUpdated, action: 'change',
}), onSuccess: this.onPasswordUpdated,
}),
}, },
{ {
id: 'remove-password', id: 'remove-password',
@ -196,47 +196,57 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
buttonText: window.i18n('removePassword'), buttonText: window.i18n('removePassword'),
buttonColor: SessionButtonColor.Danger, buttonColor: SessionButtonColor.Danger,
}, },
onClick: () => window.showPasswordDialog({ onClick: () =>
action: 'remove', window.showPasswordDialog({
onSuccess: this.onPasswordUpdated, action: 'remove',
}), onSuccess: this.onPasswordUpdated,
}),
}, },
]; ];
return ( return (
<> <>
{(this.state.hasPassword !== null) && localSettings.map(setting => { {this.state.hasPassword !== null &&
const { category } = this.props; localSettings.map(setting => {
const shouldRenderSettings = setting.category === category; const { category } = this.props;
const description = setting.description || ''; const content = setting.content || undefined;
const shouldRenderSettings = setting.category === category;
const description = setting.description || '';
const comparisonValue = setting.comparisonValue || null; const comparisonValue = setting.comparisonValue || null;
const value = window.getSettingValue(setting.id, comparisonValue) || setting.content.defaultValue; const value =
window.getSettingValue(setting.id, comparisonValue) ||
setting.content.defaultValue;
const sliderFn = const sliderFn =
setting.type === SessionSettingType.Slider setting.type === SessionSettingType.Slider
? (value: any) => window.setSettingValue(setting.id, value) ? (settingValue: any) =>
: () => null; window.setSettingValue(setting.id, settingValue)
: () => null;
const onClickFn = setting.onClick || (() => this.updateSetting(setting)); const onClickFn =
setting.onClick ||
(() => {
this.updateSetting(setting);
});
return ( return (
<div key={setting.id}> <div key={setting.id}>
{shouldRenderSettings && {shouldRenderSettings &&
!setting.hidden && ( !setting.hidden && (
<SessionSettingListItem <SessionSettingListItem
title={setting.title} title={setting.title}
description={description} description={description}
type={setting.type} type={setting.type}
value={value} value={value}
onClick={onClickFn} onClick={onClickFn}
onSliderChange={sliderFn} onSliderChange={sliderFn}
content={setting.content || undefined} content={content}
/> />
)} )}
</div> </div>
); );
})} })}
</> </>
); );
} }
@ -285,14 +295,13 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
} }
public onPasswordUpdated(action: string) { public onPasswordUpdated(action: string) {
if (action === 'set') {
if (action === 'set'){
this.setState({ this.setState({
hasPassword: true, hasPassword: true,
}); });
} }
if (action === 'remove'){ if (action === 'remove') {
this.setState({ this.setState({
hasPassword: false, hasPassword: false,
}); });

Loading…
Cancel
Save