2020-01-14 03:28:31 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import { SettingsHeader } from './SessionSettingsHeader';
|
|
|
|
import { SessionSettingListItem } from './SessionSettingListItem';
|
2021-04-22 10:03:58 +02:00
|
|
|
import { SessionButton, SessionButtonColor, SessionButtonType } from '../SessionButton';
|
2021-01-22 06:29:02 +01:00
|
|
|
import { BlockedNumberController, PasswordUtil } from '../../../util';
|
2021-01-21 03:46:01 +01:00
|
|
|
import { ConversationLookupType } from '../../../state/ducks/conversations';
|
2020-11-19 04:57:26 +01:00
|
|
|
import { StateType } from '../../../state/reducer';
|
2021-06-24 07:10:38 +02:00
|
|
|
import { getConversationController } from '../../../session/conversations';
|
2021-06-16 02:14:09 +02:00
|
|
|
import { getConversationLookup } from '../../../state/selectors/conversations';
|
2021-08-06 03:09:14 +02:00
|
|
|
import { connect } from 'react-redux';
|
2021-07-02 06:59:09 +02:00
|
|
|
import {
|
|
|
|
createOrUpdateItem,
|
|
|
|
getPasswordHash,
|
|
|
|
hasLinkPreviewPopupBeenDisplayed,
|
|
|
|
} from '../../../../ts/data/data';
|
2021-06-16 02:14:09 +02:00
|
|
|
import { shell } from 'electron';
|
2021-06-11 09:02:02 +02:00
|
|
|
import { mapDispatchToProps } from '../../../state/actions';
|
2021-06-18 06:20:36 +02:00
|
|
|
import { unblockConvoById } from '../../../interactions/conversationInteractions';
|
2021-06-24 05:43:52 +02:00
|
|
|
import { toggleAudioAutoplay } from '../../../state/ducks/userConfig';
|
2021-08-12 08:17:10 +02:00
|
|
|
import { sessionPassword, updateConfirmModal } from '../../../state/ducks/modalDialog';
|
2021-08-06 03:09:14 +02:00
|
|
|
import { PasswordAction } from '../../dialog/SessionPasswordDialog';
|
2021-08-30 09:57:31 +02:00
|
|
|
import { SessionIconButton } from '../icon';
|
2021-08-13 07:44:32 +02:00
|
|
|
import { ToastUtils } from '../../../session/utils';
|
2021-10-20 05:18:57 +02:00
|
|
|
import autoBind from 'auto-bind';
|
2020-01-14 07:42:04 +01:00
|
|
|
|
2020-01-14 03:28:31 +01:00
|
|
|
export enum SessionSettingCategory {
|
2020-02-04 01:55:01 +01:00
|
|
|
Appearance = 'appearance',
|
2020-01-14 03:28:31 +01:00
|
|
|
Account = 'account',
|
|
|
|
Privacy = 'privacy',
|
2020-01-15 02:26:14 +01:00
|
|
|
Permissions = 'permissions',
|
2020-01-14 03:28:31 +01:00
|
|
|
Notifications = 'notifications',
|
2020-01-24 07:10:42 +01:00
|
|
|
Blocked = 'blocked',
|
2020-01-14 03:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export enum SessionSettingType {
|
|
|
|
Toggle = 'toggle',
|
|
|
|
Options = 'options',
|
|
|
|
Button = 'button',
|
2020-01-14 07:42:04 +01:00
|
|
|
Slider = 'slider',
|
2020-01-14 03:28:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface SettingsViewProps {
|
|
|
|
category: SessionSettingCategory;
|
2020-11-19 04:57:26 +01:00
|
|
|
// pass the conversation as props, so our render is called everytime they change.
|
|
|
|
// we have to do this to make the list refresh on unblock()
|
|
|
|
conversations?: ConversationLookupType;
|
2020-01-14 03:28:31 +01:00
|
|
|
}
|
|
|
|
|
2020-01-20 04:10:28 +01:00
|
|
|
interface State {
|
|
|
|
hasPassword: boolean | null;
|
2020-01-21 02:58:49 +01:00
|
|
|
pwdLockError: string | null;
|
2020-02-27 23:49:03 +01:00
|
|
|
mediaSetting: boolean | null;
|
2020-01-21 03:35:47 +01:00
|
|
|
shouldLockSettings: boolean | null;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface LocalSettingType {
|
|
|
|
category: SessionSettingCategory;
|
|
|
|
description: string | undefined;
|
|
|
|
comparisonValue: string | undefined;
|
|
|
|
id: any;
|
2020-02-27 23:49:03 +01:00
|
|
|
value?: any;
|
2020-01-21 03:35:47 +01:00
|
|
|
content: any | undefined;
|
|
|
|
hidden: any;
|
2020-10-15 07:43:51 +02:00
|
|
|
title?: string;
|
2020-01-21 03:35:47 +01:00
|
|
|
type: SessionSettingType | undefined;
|
|
|
|
setFn: any;
|
|
|
|
onClick: any;
|
2020-01-20 04:10:28 +01:00
|
|
|
}
|
|
|
|
|
2020-11-19 04:57:26 +01:00
|
|
|
class SettingsViewInner extends React.Component<SettingsViewProps, State> {
|
2020-01-14 03:28:31 +01:00
|
|
|
public settingsViewRef: React.RefObject<HTMLDivElement>;
|
|
|
|
|
|
|
|
public constructor(props: any) {
|
|
|
|
super(props);
|
2020-01-20 04:10:28 +01:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
hasPassword: null,
|
2020-01-21 02:58:49 +01:00
|
|
|
pwdLockError: null,
|
2020-02-27 23:49:03 +01:00
|
|
|
mediaSetting: null,
|
2020-01-21 02:58:49 +01:00
|
|
|
shouldLockSettings: true,
|
2020-01-20 04:36:46 +01:00
|
|
|
};
|
|
|
|
|
2020-01-14 03:28:31 +01:00
|
|
|
this.settingsViewRef = React.createRef();
|
2021-10-20 05:18:57 +02:00
|
|
|
autoBind(this);
|
2020-01-20 04:10:28 +01:00
|
|
|
|
2021-02-09 05:54:34 +01:00
|
|
|
void this.hasPassword();
|
2020-01-21 03:35:47 +01:00
|
|
|
}
|
|
|
|
|
2021-08-06 02:05:29 +02:00
|
|
|
public componentDidMount() {
|
2021-08-26 08:17:37 +02:00
|
|
|
window.addEventListener('keyup', this.onKeyUp);
|
|
|
|
|
2021-08-06 02:05:29 +02:00
|
|
|
const mediaSetting = window.getSettingValue('media-permissions');
|
2020-03-13 01:10:27 +01:00
|
|
|
this.setState({ mediaSetting });
|
2020-02-27 23:49:03 +01:00
|
|
|
|
2020-07-28 02:57:59 +02:00
|
|
|
setTimeout(() => ($('#password-lock-input') as any).focus(), 100);
|
2020-01-14 03:28:31 +01:00
|
|
|
}
|
|
|
|
|
2021-08-26 08:17:37 +02:00
|
|
|
public componentWillUnmount() {
|
|
|
|
window.removeEventListener('keyup', this.onKeyUp);
|
|
|
|
}
|
|
|
|
|
2020-01-20 04:36:46 +01:00
|
|
|
/* tslint:disable-next-line:max-func-body-length */
|
2020-02-27 23:49:03 +01:00
|
|
|
public renderSettingInCategory() {
|
2020-01-21 03:35:47 +01:00
|
|
|
const { category } = this.props;
|
|
|
|
|
|
|
|
let settings: Array<LocalSettingType>;
|
2021-01-21 03:46:01 +01:00
|
|
|
|
2021-01-20 06:58:59 +01:00
|
|
|
if (category === SessionSettingCategory.Blocked) {
|
2020-07-30 16:49:11 +02:00
|
|
|
// special case for blocked user
|
|
|
|
settings = this.getBlockedUserSettings();
|
2020-01-21 03:35:47 +01:00
|
|
|
} else {
|
|
|
|
// Grab initial values from database on startup
|
|
|
|
// ID corresponds to installGetter parameters in preload.js
|
|
|
|
// They are NOT arbitrary; add with caution
|
|
|
|
|
|
|
|
settings = this.getLocalSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{this.state.hasPassword !== null &&
|
|
|
|
settings.map(setting => {
|
|
|
|
const content = setting.content || undefined;
|
|
|
|
const shouldRenderSettings = setting.category === category;
|
|
|
|
const description = setting.description || '';
|
|
|
|
|
|
|
|
const comparisonValue = setting.comparisonValue || null;
|
2021-04-22 10:03:58 +02:00
|
|
|
const storedSetting = window.getSettingValue(setting.id, comparisonValue);
|
2020-03-30 06:42:52 +02:00
|
|
|
const value =
|
|
|
|
storedSetting !== undefined
|
|
|
|
? storedSetting
|
|
|
|
: setting.content && setting.content.defaultValue;
|
2020-01-21 03:35:47 +01:00
|
|
|
|
|
|
|
const sliderFn =
|
|
|
|
setting.type === SessionSettingType.Slider
|
2021-04-22 10:03:58 +02:00
|
|
|
? (settingValue: any) => window.setSettingValue(setting.id, settingValue)
|
2020-01-21 03:35:47 +01:00
|
|
|
: () => null;
|
|
|
|
|
|
|
|
const onClickFn =
|
|
|
|
setting.onClick ||
|
2021-03-04 01:41:15 +01:00
|
|
|
((settingValue?: string) => {
|
|
|
|
this.updateSetting(setting, settingValue);
|
2020-01-21 03:35:47 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div key={setting.id}>
|
2020-05-29 08:25:15 +02:00
|
|
|
{shouldRenderSettings && !setting.hidden && (
|
|
|
|
<SessionSettingListItem
|
|
|
|
title={setting.title}
|
|
|
|
description={description}
|
|
|
|
type={setting.type}
|
|
|
|
value={value}
|
|
|
|
onClick={onClickFn}
|
|
|
|
onSliderChange={sliderFn}
|
|
|
|
content={content}
|
|
|
|
/>
|
|
|
|
)}
|
2020-01-21 03:35:47 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|
2020-01-21 03:39:34 +01:00
|
|
|
|
2020-01-21 03:35:47 +01:00
|
|
|
public renderPasswordLock() {
|
|
|
|
return (
|
|
|
|
<div className="session-settings__password-lock">
|
|
|
|
<div className="session-settings__password-lock-box">
|
|
|
|
<h3>{window.i18n('password')}</h3>
|
2021-04-22 10:03:58 +02:00
|
|
|
<input type="password" id="password-lock-input" defaultValue="" placeholder="Password" />
|
2020-01-21 04:59:18 +01:00
|
|
|
|
2020-01-21 03:35:47 +01:00
|
|
|
{this.state.pwdLockError && (
|
2021-06-24 02:50:35 +02:00
|
|
|
<div className="session-label warning">{this.state.pwdLockError}</div>
|
2020-01-21 03:35:47 +01:00
|
|
|
)}
|
|
|
|
|
|
|
|
<SessionButton
|
|
|
|
buttonType={SessionButtonType.BrandOutline}
|
|
|
|
buttonColor={SessionButtonColor.Green}
|
2020-08-17 03:21:57 +02:00
|
|
|
text={window.i18n('ok')}
|
2020-01-21 03:35:47 +01:00
|
|
|
onClick={this.validatePasswordLock}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public async validatePasswordLock() {
|
2020-08-12 02:05:18 +02:00
|
|
|
const enteredPassword = String(jQuery('#password-lock-input').val());
|
2020-01-21 03:35:47 +01:00
|
|
|
|
|
|
|
if (!enteredPassword) {
|
|
|
|
this.setState({
|
|
|
|
pwdLockError: window.i18n('noGivenPassword'),
|
|
|
|
});
|
2020-01-21 04:59:18 +01:00
|
|
|
|
2020-01-21 03:35:47 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if the password matches the hash we have stored
|
2021-02-09 05:54:34 +01:00
|
|
|
const hash = await getPasswordHash();
|
2021-01-22 06:29:02 +01:00
|
|
|
if (hash && !PasswordUtil.matchesHash(enteredPassword, hash)) {
|
2020-01-21 03:35:47 +01:00
|
|
|
this.setState({
|
|
|
|
pwdLockError: window.i18n('invalidPassword'),
|
|
|
|
});
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unlocked settings
|
|
|
|
this.setState({
|
|
|
|
shouldLockSettings: false,
|
|
|
|
pwdLockError: null,
|
|
|
|
});
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public render() {
|
2021-01-20 06:58:59 +01:00
|
|
|
const { category } = this.props;
|
2021-04-22 10:03:58 +02:00
|
|
|
const shouldRenderPasswordLock = this.state.shouldLockSettings && this.state.hasPassword;
|
2020-01-21 03:35:47 +01:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="session-settings">
|
2020-01-22 04:28:29 +01:00
|
|
|
<SettingsHeader
|
|
|
|
category={category}
|
2020-08-05 08:57:21 +02:00
|
|
|
categoryTitle={window.i18n(`${category}SettingsTitle`)}
|
2020-01-22 04:28:29 +01:00
|
|
|
/>
|
2020-02-19 10:47:37 +01:00
|
|
|
|
2020-01-22 05:57:58 +01:00
|
|
|
<div className="session-settings-view">
|
|
|
|
{shouldRenderPasswordLock ? (
|
|
|
|
this.renderPasswordLock()
|
|
|
|
) : (
|
|
|
|
<div ref={this.settingsViewRef} className="session-settings-list">
|
|
|
|
{this.renderSettingInCategory()}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
{this.renderSessionInfo()}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public renderSessionInfo(): JSX.Element {
|
2021-07-28 07:19:07 +02:00
|
|
|
const openOxenWebsite = () => {
|
|
|
|
void shell.openExternal('https://oxen.io/');
|
|
|
|
};
|
2020-01-22 05:57:58 +01:00
|
|
|
return (
|
|
|
|
<div className="session-settings__version-info">
|
2020-04-15 01:59:33 +02:00
|
|
|
<span className="text-selectable">v{window.versionInfo.version}</span>
|
2021-07-30 08:31:35 +02:00
|
|
|
<span>
|
2021-08-30 09:57:31 +02:00
|
|
|
<SessionIconButton iconSize={'medium'} iconType="oxen" onClick={openOxenWebsite} />
|
2021-07-30 08:31:35 +02:00
|
|
|
</span>
|
2020-04-15 01:59:33 +02:00
|
|
|
<span className="text-selectable">{window.versionInfo.commitHash}</span>
|
2020-01-21 03:35:47 +01:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-02 05:25:38 +01:00
|
|
|
public setOptionsSetting(settingID: string, selectedValue: string) {
|
2020-01-21 03:35:47 +01:00
|
|
|
window.setSettingValue(settingID, selectedValue);
|
|
|
|
}
|
|
|
|
|
2021-02-09 05:54:34 +01:00
|
|
|
public async hasPassword() {
|
|
|
|
const hash = await getPasswordHash();
|
2020-01-21 03:35:47 +01:00
|
|
|
|
2021-02-09 05:54:34 +01:00
|
|
|
this.setState({
|
|
|
|
hasPassword: !!hash,
|
2020-01-21 03:35:47 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-06-22 09:04:57 +02:00
|
|
|
/**
|
|
|
|
* If there's a custom afterClick function, execute it instead of automatically updating settings
|
|
|
|
* @param item setting item
|
|
|
|
* @param value new value to set
|
|
|
|
*/
|
2021-03-02 05:25:38 +01:00
|
|
|
public updateSetting(item: any, value?: string) {
|
2020-01-21 03:35:47 +01:00
|
|
|
if (item.setFn) {
|
2021-03-02 05:25:38 +01:00
|
|
|
if (value) {
|
|
|
|
item.setFn(value);
|
|
|
|
} else {
|
|
|
|
item.setFn();
|
|
|
|
}
|
2020-01-21 03:35:47 +01:00
|
|
|
} else {
|
|
|
|
if (item.type === SessionSettingType.Toggle) {
|
|
|
|
// If no custom afterClick function given, alter values in storage here
|
2020-02-03 04:19:37 +01:00
|
|
|
|
2020-01-21 03:35:47 +01:00
|
|
|
// Switch to opposite state
|
|
|
|
const newValue = !window.getSettingValue(item.id);
|
|
|
|
window.setSettingValue(item.id, newValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public onPasswordUpdated(action: string) {
|
|
|
|
if (action === 'set' || action === 'change') {
|
|
|
|
this.setState({
|
|
|
|
hasPassword: true,
|
|
|
|
shouldLockSettings: true,
|
|
|
|
pwdLockError: null,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (action === 'remove') {
|
|
|
|
this.setState({
|
|
|
|
hasPassword: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable-next-line: max-func-body-length
|
|
|
|
private getLocalSettings(): Array<LocalSettingType> {
|
2020-01-14 05:37:52 +01:00
|
|
|
const { Settings } = window.Signal.Types;
|
2020-01-14 07:42:04 +01:00
|
|
|
|
2020-01-21 03:35:47 +01:00
|
|
|
return [
|
2020-01-15 03:49:07 +01:00
|
|
|
{
|
|
|
|
id: 'hide-menu-bar',
|
|
|
|
title: window.i18n('hideMenuBarTitle'),
|
|
|
|
description: window.i18n('hideMenuBarDescription'),
|
|
|
|
hidden: !Settings.isHideMenuBarSupported(),
|
|
|
|
type: SessionSettingType.Toggle,
|
2020-02-04 01:55:01 +01:00
|
|
|
category: SessionSettingCategory.Appearance,
|
2020-01-15 03:49:07 +01:00
|
|
|
setFn: window.toggleMenuBar,
|
2020-01-22 05:25:21 +01:00
|
|
|
content: { defaultValue: true },
|
2020-01-21 03:35:47 +01:00
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
2020-01-15 03:49:07 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'spell-check',
|
|
|
|
title: window.i18n('spellCheckTitle'),
|
|
|
|
description: window.i18n('spellCheckDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
2020-02-04 01:55:01 +01:00
|
|
|
category: SessionSettingCategory.Appearance,
|
2020-01-15 03:49:07 +01:00
|
|
|
setFn: window.toggleSpellCheck,
|
2020-03-30 03:38:26 +02:00
|
|
|
content: { defaultValue: true },
|
2020-01-21 03:35:47 +01:00
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
2020-01-15 03:49:07 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'link-preview-setting',
|
|
|
|
title: window.i18n('linkPreviewsTitle'),
|
|
|
|
description: window.i18n('linkPreviewDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
2020-02-04 01:55:01 +01:00
|
|
|
category: SessionSettingCategory.Appearance,
|
2021-07-02 06:59:09 +02:00
|
|
|
setFn: async () => {
|
2021-07-02 06:35:28 +02:00
|
|
|
const newValue = !window.getSettingValue('link-preview-setting');
|
|
|
|
window.setSettingValue('link-preview-setting', newValue);
|
|
|
|
if (!newValue) {
|
2021-07-02 06:59:09 +02:00
|
|
|
await createOrUpdateItem({ id: hasLinkPreviewPopupBeenDisplayed, value: false });
|
2021-08-12 08:17:10 +02:00
|
|
|
} else {
|
|
|
|
window.inboxStore?.dispatch(
|
|
|
|
updateConfirmModal({
|
|
|
|
title: window.i18n('linkPreviewsTitle'),
|
|
|
|
message: window.i18n('linkPreviewsConfirmMessage'),
|
|
|
|
okTheme: SessionButtonColor.Danger,
|
2021-08-24 05:23:23 +02:00
|
|
|
// onClickOk:
|
2021-08-12 08:17:10 +02:00
|
|
|
})
|
|
|
|
);
|
2021-07-02 06:35:28 +02:00
|
|
|
}
|
|
|
|
},
|
2020-01-21 03:35:47 +01:00
|
|
|
content: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
2020-01-15 03:49:07 +01:00
|
|
|
},
|
2021-08-10 03:57:27 +02:00
|
|
|
|
|
|
|
{
|
|
|
|
id: 'start-in-tray-setting',
|
|
|
|
title: window.i18n('startInTrayTitle'),
|
|
|
|
description: window.i18n('startInTrayDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
|
|
|
category: SessionSettingCategory.Appearance,
|
|
|
|
setFn: async () => {
|
2021-08-13 07:44:32 +02:00
|
|
|
try {
|
|
|
|
const newValue = !(await window.getStartInTray());
|
|
|
|
|
|
|
|
// make sure to write it here too, as this is the value used on the UI to mark the toggle as true/false
|
|
|
|
window.setSettingValue('start-in-tray-setting', newValue);
|
|
|
|
await window.setStartInTray(newValue);
|
|
|
|
if (!newValue) {
|
|
|
|
ToastUtils.pushRestartNeeded();
|
|
|
|
}
|
|
|
|
} catch (e) {
|
|
|
|
window.log.warn('start in tray change error:', e);
|
|
|
|
}
|
2021-08-10 03:57:27 +02:00
|
|
|
},
|
|
|
|
content: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
},
|
2021-06-22 09:04:57 +02:00
|
|
|
{
|
|
|
|
id: 'audio-message-autoplay-setting',
|
|
|
|
title: window.i18n('audioMessageAutoplayTitle'),
|
|
|
|
description: window.i18n('audioMessageAutoplayDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
|
|
|
category: SessionSettingCategory.Appearance,
|
|
|
|
setFn: () => {
|
|
|
|
window.inboxStore?.dispatch(toggleAudioAutoplay());
|
|
|
|
},
|
2021-06-24 07:31:20 +02:00
|
|
|
content: {
|
2021-06-24 09:06:21 +02:00
|
|
|
defaultValue: window.inboxStore?.getState().userConfig.audioAutoplay,
|
2021-06-24 07:31:20 +02:00
|
|
|
},
|
2021-06-22 09:04:57 +02:00
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
},
|
2021-08-10 03:57:27 +02:00
|
|
|
|
2020-01-15 03:49:07 +01:00
|
|
|
{
|
|
|
|
id: 'notification-setting',
|
|
|
|
title: window.i18n('notificationSettingsDialog'),
|
|
|
|
type: SessionSettingType.Options,
|
|
|
|
category: SessionSettingCategory.Notifications,
|
2020-01-21 03:35:47 +01:00
|
|
|
comparisonValue: undefined,
|
|
|
|
description: undefined,
|
|
|
|
hidden: undefined,
|
|
|
|
onClick: undefined,
|
2021-03-02 05:25:38 +01:00
|
|
|
setFn: (selectedValue: string) => {
|
|
|
|
this.setOptionsSetting('notification-setting', selectedValue);
|
2020-01-16 02:05:09 +01:00
|
|
|
},
|
2020-01-15 03:49:07 +01:00
|
|
|
content: {
|
|
|
|
options: {
|
|
|
|
group: 'notification-setting',
|
2021-08-10 03:57:27 +02:00
|
|
|
initialItem: window.getSettingValue('notification-setting') || 'message',
|
2020-01-15 03:49:07 +01:00
|
|
|
items: [
|
|
|
|
{
|
|
|
|
label: window.i18n('nameAndMessage'),
|
|
|
|
value: 'message',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: window.i18n('nameOnly'),
|
|
|
|
value: 'name',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: window.i18n('noNameOrMessage'),
|
|
|
|
value: 'count',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: window.i18n('disableNotifications'),
|
|
|
|
value: 'off',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2020-01-14 07:42:04 +01:00
|
|
|
},
|
2020-01-15 02:26:14 +01:00
|
|
|
},
|
2020-02-19 14:08:47 +01:00
|
|
|
{
|
|
|
|
id: 'zoom-factor-setting',
|
|
|
|
title: window.i18n('zoomFactorSettingTitle'),
|
2020-02-21 00:53:57 +01:00
|
|
|
description: undefined,
|
2020-02-19 14:08:47 +01:00
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Slider,
|
|
|
|
category: SessionSettingCategory.Appearance,
|
|
|
|
setFn: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
content: {
|
2020-02-28 00:20:56 +01:00
|
|
|
dotsEnabled: true,
|
|
|
|
step: 20,
|
|
|
|
min: 60,
|
|
|
|
max: 200,
|
|
|
|
defaultValue: 100,
|
2020-03-02 01:35:42 +01:00
|
|
|
info: (value: number) => `${value}%`,
|
2020-01-20 04:10:28 +01:00
|
|
|
},
|
2020-01-16 02:08:31 +01:00
|
|
|
},
|
2021-09-20 07:44:19 +02:00
|
|
|
{
|
|
|
|
id: 'session-survey',
|
|
|
|
title: window.i18n('surveyTitle'),
|
|
|
|
description: undefined,
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Button,
|
|
|
|
category: SessionSettingCategory.Appearance,
|
|
|
|
setFn: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: () => {
|
|
|
|
void shell.openExternal('https://getsession.org/survey');
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
buttonText: window.i18n('goToOurSurvey'),
|
|
|
|
buttonColor: SessionButtonColor.Primary,
|
|
|
|
},
|
|
|
|
},
|
2021-06-16 02:14:09 +02:00
|
|
|
{
|
|
|
|
id: 'help-translation',
|
|
|
|
title: window.i18n('translation'),
|
|
|
|
description: undefined,
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Button,
|
|
|
|
category: SessionSettingCategory.Appearance,
|
|
|
|
setFn: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: () => {
|
|
|
|
void shell.openExternal('https://crowdin.com/project/session-desktop/');
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
buttonText: window.i18n('helpUsTranslateSession'),
|
|
|
|
buttonColor: SessionButtonColor.Primary,
|
|
|
|
},
|
|
|
|
},
|
2020-02-27 23:49:03 +01:00
|
|
|
{
|
|
|
|
id: 'media-permissions',
|
|
|
|
title: window.i18n('mediaPermissionsTitle'),
|
|
|
|
description: window.i18n('mediaPermissionsDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: window.toggleMediaPermissions,
|
|
|
|
content: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
},
|
2020-01-28 05:41:36 +01:00
|
|
|
{
|
|
|
|
id: 'read-receipt-setting',
|
|
|
|
title: window.i18n('readReceiptSettingTitle'),
|
|
|
|
description: window.i18n('readReceiptSettingDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
content: {},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'typing-indicators-setting',
|
|
|
|
title: window.i18n('typingIndicatorsSettingTitle'),
|
|
|
|
description: window.i18n('typingIndicatorsSettingDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
content: {},
|
|
|
|
},
|
2020-03-09 23:55:29 +01:00
|
|
|
{
|
|
|
|
id: 'auto-update',
|
|
|
|
title: window.i18n('autoUpdateSettingTitle'),
|
|
|
|
description: window.i18n('autoUpdateSettingDescription'),
|
|
|
|
hidden: false,
|
|
|
|
type: SessionSettingType.Toggle,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
onClick: undefined,
|
|
|
|
content: {},
|
|
|
|
},
|
2020-01-20 04:10:22 +01:00
|
|
|
{
|
|
|
|
id: 'set-password',
|
|
|
|
title: window.i18n('setAccountPasswordTitle'),
|
|
|
|
description: window.i18n('setAccountPasswordDescription'),
|
2020-01-20 04:10:28 +01:00
|
|
|
hidden: this.state.hasPassword,
|
2020-01-20 04:10:22 +01:00
|
|
|
type: SessionSettingType.Button,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: undefined,
|
2020-01-21 03:35:47 +01:00
|
|
|
comparisonValue: undefined,
|
2020-01-20 04:10:22 +01:00
|
|
|
content: {
|
|
|
|
buttonText: window.i18n('setPassword'),
|
|
|
|
buttonColor: SessionButtonColor.Primary,
|
|
|
|
},
|
2020-11-19 03:49:53 +01:00
|
|
|
onClick: () => {
|
2021-06-24 02:50:35 +02:00
|
|
|
this.displayPasswordModal('set');
|
2020-11-19 03:49:53 +01:00
|
|
|
},
|
2020-01-20 04:10:22 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'change-password',
|
|
|
|
title: window.i18n('changeAccountPasswordTitle'),
|
|
|
|
description: window.i18n('changeAccountPasswordDescription'),
|
2020-01-20 04:10:28 +01:00
|
|
|
hidden: !this.state.hasPassword,
|
2020-01-20 04:10:22 +01:00
|
|
|
type: SessionSettingType.Button,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: undefined,
|
2020-01-21 03:35:47 +01:00
|
|
|
comparisonValue: undefined,
|
2020-01-20 04:10:22 +01:00
|
|
|
content: {
|
2020-01-20 04:36:46 +01:00
|
|
|
buttonText: window.i18n('changePassword'),
|
2020-01-20 04:10:22 +01:00
|
|
|
buttonColor: SessionButtonColor.Primary,
|
|
|
|
},
|
2020-11-19 03:49:53 +01:00
|
|
|
onClick: () => {
|
2021-06-24 02:50:35 +02:00
|
|
|
this.displayPasswordModal('change');
|
2020-11-19 03:49:53 +01:00
|
|
|
},
|
2020-01-20 04:10:22 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 'remove-password',
|
|
|
|
title: window.i18n('removeAccountPasswordTitle'),
|
|
|
|
description: window.i18n('removeAccountPasswordDescription'),
|
2020-01-20 04:10:28 +01:00
|
|
|
hidden: !this.state.hasPassword,
|
2020-01-20 04:10:22 +01:00
|
|
|
type: SessionSettingType.Button,
|
|
|
|
category: SessionSettingCategory.Privacy,
|
|
|
|
setFn: undefined,
|
2020-01-21 03:35:47 +01:00
|
|
|
comparisonValue: undefined,
|
2020-01-20 04:10:22 +01:00
|
|
|
content: {
|
|
|
|
buttonText: window.i18n('removePassword'),
|
|
|
|
buttonColor: SessionButtonColor.Danger,
|
|
|
|
},
|
2020-11-19 03:49:53 +01:00
|
|
|
onClick: () => {
|
2021-06-24 02:50:35 +02:00
|
|
|
this.displayPasswordModal('remove');
|
2020-11-19 03:55:01 +01:00
|
|
|
},
|
2020-01-20 04:10:22 +01:00
|
|
|
},
|
2020-01-14 07:42:04 +01:00
|
|
|
];
|
2020-01-14 03:28:31 +01:00
|
|
|
}
|
2020-01-21 03:17:38 +01:00
|
|
|
|
2021-06-07 12:27:54 +02:00
|
|
|
private displayPasswordModal(passwordAction: PasswordAction) {
|
2021-06-24 02:50:35 +02:00
|
|
|
window.inboxStore?.dispatch(
|
|
|
|
sessionPassword({
|
|
|
|
passwordAction,
|
|
|
|
onOk: () => {
|
|
|
|
this.onPasswordUpdated(passwordAction);
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2021-06-07 12:27:54 +02:00
|
|
|
}
|
|
|
|
|
2020-07-30 16:49:11 +02:00
|
|
|
private getBlockedUserSettings(): Array<LocalSettingType> {
|
|
|
|
const results: Array<LocalSettingType> = [];
|
2020-08-06 09:08:18 +02:00
|
|
|
const blockedNumbers = BlockedNumberController.getBlockedNumbers();
|
|
|
|
|
|
|
|
for (const blockedNumber of blockedNumbers) {
|
2020-08-14 02:56:44 +02:00
|
|
|
let title: string;
|
2020-08-06 09:08:18 +02:00
|
|
|
|
2021-06-24 07:10:38 +02:00
|
|
|
const currentModel = getConversationController().get(blockedNumber);
|
2020-08-15 13:21:35 +02:00
|
|
|
if (currentModel) {
|
2021-04-22 10:03:58 +02:00
|
|
|
title = currentModel.getProfileName() || currentModel.getName() || window.i18n('anonymous');
|
2020-08-15 13:21:35 +02:00
|
|
|
} else {
|
|
|
|
title = window.i18n('anonymous');
|
|
|
|
}
|
2020-08-15 13:58:24 +02:00
|
|
|
|
2020-08-06 09:08:18 +02:00
|
|
|
results.push({
|
|
|
|
id: blockedNumber,
|
2020-08-14 02:56:44 +02:00
|
|
|
title,
|
|
|
|
description: '',
|
2020-08-06 09:08:18 +02:00
|
|
|
type: SessionSettingType.Button,
|
|
|
|
category: SessionSettingCategory.Blocked,
|
|
|
|
content: {
|
|
|
|
buttonColor: SessionButtonColor.Danger,
|
|
|
|
buttonText: window.i18n('unblockUser'),
|
|
|
|
},
|
|
|
|
comparisonValue: undefined,
|
2020-08-06 10:30:22 +02:00
|
|
|
setFn: async () => {
|
2021-06-18 06:20:36 +02:00
|
|
|
await unblockConvoById(blockedNumber);
|
|
|
|
|
|
|
|
this.forceUpdate();
|
2020-08-06 09:08:18 +02:00
|
|
|
},
|
|
|
|
hidden: false,
|
|
|
|
onClick: undefined,
|
|
|
|
});
|
|
|
|
}
|
2020-09-02 07:24:50 +02:00
|
|
|
|
|
|
|
if (blockedNumbers.length === 0) {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
id: 'noBlockedContacts',
|
|
|
|
title: '',
|
|
|
|
description: window.i18n('noBlockedContacts'),
|
|
|
|
type: undefined,
|
|
|
|
category: SessionSettingCategory.Blocked,
|
|
|
|
content: undefined,
|
|
|
|
comparisonValue: undefined,
|
|
|
|
setFn: undefined,
|
|
|
|
hidden: false,
|
|
|
|
onClick: undefined,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-07-30 16:49:11 +02:00
|
|
|
return results;
|
|
|
|
}
|
|
|
|
|
2020-01-29 23:34:24 +01:00
|
|
|
private async onKeyUp(event: any) {
|
2021-04-22 10:03:58 +02:00
|
|
|
const lockPasswordFocussed = ($('#password-lock-input') as any).is(':focus');
|
2020-01-29 23:34:24 +01:00
|
|
|
|
|
|
|
if (event.key === 'Enter' && lockPasswordFocussed) {
|
|
|
|
await this.validatePasswordLock();
|
|
|
|
}
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2020-01-21 03:39:34 +01:00
|
|
|
}
|
2020-11-19 04:57:26 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state: StateType) => {
|
|
|
|
return {
|
2021-01-19 03:57:05 +01:00
|
|
|
conversations: getConversationLookup(state),
|
2020-11-19 04:57:26 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-06-11 09:02:02 +02:00
|
|
|
const smart = connect(mapStateToProps, mapDispatchToProps);
|
2020-11-19 04:57:26 +01:00
|
|
|
export const SmartSettingsView = smart(SettingsViewInner);
|