diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e8ab82436..bacb6883e 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1006,6 +1006,9 @@ "noPairedDevices": { "message": "No paired devices" }, + "deviceIsSecondaryNoPairing": { + "message": "This device is a secondary device and so cannot be paired." + }, "allowPairing": { "message": "Allow Pairing" }, diff --git a/ts/components/MainViewController.tsx b/ts/components/MainViewController.tsx index 2641081fa..e344920c2 100644 --- a/ts/components/MainViewController.tsx +++ b/ts/components/MainViewController.tsx @@ -14,9 +14,16 @@ export const MainViewController = { }, renderSettingsView: (category: SessionSettingCategory) => { + // tslint:disable-next-line: no-backbone-get-set-outside-model + const isSecondaryDevice = !!window.textsecure.storage.get( + 'isSecondaryDevice' + ); if (document.getElementById('main-view')) { ReactDOM.render( - , + , document.getElementById('main-view') ); } diff --git a/ts/components/session/settings/SessionSettings.tsx b/ts/components/session/settings/SessionSettings.tsx index 01ab4dd16..b83188def 100644 --- a/ts/components/session/settings/SessionSettings.tsx +++ b/ts/components/session/settings/SessionSettings.tsx @@ -27,6 +27,7 @@ export enum SessionSettingType { export interface SettingsViewProps { category: SessionSettingCategory; + isSecondaryDevice: boolean; } interface State { @@ -221,7 +222,7 @@ export class SettingsView extends React.Component { } public render() { - const { category } = this.props; + const { category, isSecondaryDevice } = this.props; const shouldRenderPasswordLock = this.state.shouldLockSettings && this.state.hasPassword; @@ -230,6 +231,7 @@ export class SettingsView extends React.Component {
@@ -574,6 +576,10 @@ export class SettingsView extends React.Component { private getLinkedDeviceSettings(): Array { const { linkedPubKeys } = this.state; + const { isSecondaryDevice } = this.props; + const noPairedDeviceText = isSecondaryDevice + ? window.i18n('deviceIsSecondaryNoPairing') + : window.i18n('noPairedDevices'); if (linkedPubKeys && linkedPubKeys.length > 0) { return linkedPubKeys.map((pubkey: any) => { @@ -621,7 +627,7 @@ export class SettingsView extends React.Component { return [ { id: 'no-linked-device', - title: window.i18n('noPairedDevices'), + title: noPairedDeviceText, type: undefined, description: '', category: SessionSettingCategory.Devices, diff --git a/ts/components/session/settings/SessionSettingsHeader.tsx b/ts/components/session/settings/SessionSettingsHeader.tsx index b5dc93df0..2c14e0dbf 100644 --- a/ts/components/session/settings/SessionSettingsHeader.tsx +++ b/ts/components/session/settings/SessionSettingsHeader.tsx @@ -5,20 +5,23 @@ import { SessionSettingCategory, SettingsViewProps } from './SessionSettings'; import { SessionButton } from '../SessionButton'; interface Props extends SettingsViewProps { + // showLinkDeviceButton is used to completely hide the button while the settings password lock is displayed showLinkDeviceButton: boolean | null; - disableLinkDeviceButton: boolean | null; + // isSecondaryDevice is used to just disable the linkDeviceButton when we are already a secondary device + isSecondaryDevice: boolean; } export class SettingsHeader extends React.Component { public static defaultProps = { showLinkDeviceButton: false, - disableLinkDeviceButton: true, }; public constructor(props: any) { super(props); + // mark the linkDeviceButton as disabled by default. + // it will be enabled if needed during componentDidMount(). this.state = { - disableLinkDeviceButton: this.props.disableLinkDeviceButton, + disableLinkDeviceButton: true, }; this.showAddLinkedDeviceModal = this.showAddLinkedDeviceModal.bind(this); } @@ -32,10 +35,12 @@ export class SettingsHeader extends React.Component { } public componentDidMount() { - window.Whisper.events.on('refreshLinkedDeviceList', async () => { + if (!this.props.isSecondaryDevice) { + window.Whisper.events.on('refreshLinkedDeviceList', async () => { + this.refreshLinkedDevice(); + }); this.refreshLinkedDevice(); - }); - this.refreshLinkedDevice(); + } } public refreshLinkedDevice() { @@ -51,7 +56,9 @@ export class SettingsHeader extends React.Component { } public componentWillUnmount() { - window.Whisper.events.off('refreshLinkedDeviceList'); + if (!this.props.isSecondaryDevice) { + window.Whisper.events.off('refreshLinkedDeviceList'); + } } public render() {