From b5aee4f4be1874fc166621b0669391a7ea95bb9d Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Fri, 23 Aug 2019 16:51:52 +1000 Subject: [PATCH] Display "Pair New Device" in menu for non-secondary devices --- js/background.js | 1 + js/views/inbox_view.js | 1 + ts/components/MainHeader.tsx | 18 ++++++++++++++++-- ts/state/ducks/user.ts | 4 ++++ ts/state/selectors/user.ts | 5 +++++ ts/state/smart/MainHeader.tsx | 8 +++++++- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/js/background.js b/js/background.js index 3cd81dcbd..29dbf195e 100644 --- a/js/background.js +++ b/js/background.js @@ -181,6 +181,7 @@ const user = { regionCode: window.storage.get('regionCode'), ourNumber: textsecure.storage.user.getNumber(), + isSecondaryDevice: !!textsecure.storage.get('isSecondaryDevice'), }; Whisper.events.trigger('userChanged', user); diff --git a/js/views/inbox_view.js b/js/views/inbox_view.js index e1bb7ef69..c4f1dc7ff 100644 --- a/js/views/inbox_view.js +++ b/js/views/inbox_view.js @@ -156,6 +156,7 @@ user: { regionCode: window.storage.get('regionCode'), ourNumber: textsecure.storage.user.getNumber(), + isSecondaryDevice: !!window.storage.get('isSecondaryDevice'), i18n: window.i18n, }, }; diff --git a/ts/components/MainHeader.tsx b/ts/components/MainHeader.tsx index 946077894..47cbac33d 100644 --- a/ts/components/MainHeader.tsx +++ b/ts/components/MainHeader.tsx @@ -37,6 +37,7 @@ export interface Props { verified: boolean; profileName?: string; avatarPath?: string; + isSecondaryDevice?: boolean; i18n: LocalizerType; updateSearchTerm: (searchTerm: string) => void; @@ -98,7 +99,10 @@ export class MainHeader extends React.Component { } public componentDidUpdate(_prevProps: Props, prevState: any) { - if (prevState.hasPass !== this.state.hasPass) { + if ( + prevState.hasPass !== this.state.hasPass || + _prevProps.isSecondaryDevice !== this.props.isSecondaryDevice + ) { this.updateMenuItems(); } } @@ -304,7 +308,7 @@ export class MainHeader extends React.Component { } private updateMenuItems() { - const { i18n, onCopyPublicKey } = this.props; + const { i18n, onCopyPublicKey, isSecondaryDevice } = this.props; const { hasPass } = this.state; const menuItems = [ @@ -351,6 +355,16 @@ export class MainHeader extends React.Component { menuItems.push(passItem('set')); } + if (!isSecondaryDevice) { + menuItems.push({ + id: 'pairNewDevice', + name: 'Pair new Device', + onClick: () => { + trigger('showDevicePairingDialog'); + }, + }); + } + this.setState({ menuItems }); } } diff --git a/ts/state/ducks/user.ts b/ts/state/ducks/user.ts index 4123170cd..c49cf6386 100644 --- a/ts/state/ducks/user.ts +++ b/ts/state/ducks/user.ts @@ -5,6 +5,7 @@ import { LocalizerType } from '../../types/Util'; export type UserStateType = { ourNumber: string; regionCode: string; + isSecondaryDevice: boolean; i18n: LocalizerType; }; @@ -15,6 +16,7 @@ type UserChangedActionType = { payload: { ourNumber: string; regionCode: string; + isSecondaryDevice: boolean; }; }; @@ -29,6 +31,7 @@ export const actions = { function userChanged(attributes: { ourNumber: string; regionCode: string; + isSecondaryDevice: boolean; }): UserChangedActionType { return { type: 'USER_CHANGED', @@ -42,6 +45,7 @@ function getEmptyState(): UserStateType { return { ourNumber: 'missing', regionCode: 'missing', + isSecondaryDevice: false, i18n: () => 'missing', }; } diff --git a/ts/state/selectors/user.ts b/ts/state/selectors/user.ts index 67478ab9f..6963ad8a3 100644 --- a/ts/state/selectors/user.ts +++ b/ts/state/selectors/user.ts @@ -21,3 +21,8 @@ export const getIntl = createSelector( getUser, (state: UserStateType): LocalizerType => state.i18n ); + +export const getIsSecondaryDevice = createSelector( + getUser, + (state: UserStateType): boolean => state.isSecondaryDevice +); diff --git a/ts/state/smart/MainHeader.tsx b/ts/state/smart/MainHeader.tsx index e9db0c481..1c3a8e8cc 100644 --- a/ts/state/smart/MainHeader.tsx +++ b/ts/state/smart/MainHeader.tsx @@ -5,7 +5,12 @@ import { MainHeader } from '../../components/MainHeader'; import { StateType } from '../reducer'; import { getQuery } from '../selectors/search'; -import { getIntl, getRegionCode, getUserNumber } from '../selectors/user'; +import { + getIntl, + getIsSecondaryDevice, + getRegionCode, + getUserNumber, +} from '../selectors/user'; import { getMe } from '../selectors/conversations'; const mapStateToProps = (state: StateType) => { @@ -13,6 +18,7 @@ const mapStateToProps = (state: StateType) => { searchTerm: getQuery(state), regionCode: getRegionCode(state), ourNumber: getUserNumber(state), + isSecondaryDevice: getIsSecondaryDevice(state), ...getMe(state), i18n: getIntl(state), };