Merge pull request #432 from sachaaaaa/pair_device_menu_item

[multi-device] Display "Pair New Device" in menu
pull/438/head
sachaaaaa 6 years ago committed by GitHub
commit 1ced8e348b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -181,6 +181,7 @@
const user = { const user = {
regionCode: window.storage.get('regionCode'), regionCode: window.storage.get('regionCode'),
ourNumber: textsecure.storage.user.getNumber(), ourNumber: textsecure.storage.user.getNumber(),
isSecondaryDevice: !!textsecure.storage.get('isSecondaryDevice'),
}; };
Whisper.events.trigger('userChanged', user); Whisper.events.trigger('userChanged', user);

@ -156,6 +156,7 @@
user: { user: {
regionCode: window.storage.get('regionCode'), regionCode: window.storage.get('regionCode'),
ourNumber: textsecure.storage.user.getNumber(), ourNumber: textsecure.storage.user.getNumber(),
isSecondaryDevice: !!window.storage.get('isSecondaryDevice'),
i18n: window.i18n, i18n: window.i18n,
}, },
}; };

@ -37,6 +37,7 @@ export interface Props {
verified: boolean; verified: boolean;
profileName?: string; profileName?: string;
avatarPath?: string; avatarPath?: string;
isSecondaryDevice?: boolean;
i18n: LocalizerType; i18n: LocalizerType;
updateSearchTerm: (searchTerm: string) => void; updateSearchTerm: (searchTerm: string) => void;
@ -98,7 +99,10 @@ export class MainHeader extends React.Component<Props, any> {
} }
public componentDidUpdate(_prevProps: Props, prevState: any) { 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(); this.updateMenuItems();
} }
} }
@ -304,7 +308,7 @@ export class MainHeader extends React.Component<Props, any> {
} }
private updateMenuItems() { private updateMenuItems() {
const { i18n, onCopyPublicKey } = this.props; const { i18n, onCopyPublicKey, isSecondaryDevice } = this.props;
const { hasPass } = this.state; const { hasPass } = this.state;
const menuItems = [ const menuItems = [
@ -351,6 +355,16 @@ export class MainHeader extends React.Component<Props, any> {
menuItems.push(passItem('set')); menuItems.push(passItem('set'));
} }
if (!isSecondaryDevice) {
menuItems.push({
id: 'pairNewDevice',
name: 'Pair new Device',
onClick: () => {
trigger('showDevicePairingDialog');
},
});
}
this.setState({ menuItems }); this.setState({ menuItems });
} }
} }

@ -5,6 +5,7 @@ import { LocalizerType } from '../../types/Util';
export type UserStateType = { export type UserStateType = {
ourNumber: string; ourNumber: string;
regionCode: string; regionCode: string;
isSecondaryDevice: boolean;
i18n: LocalizerType; i18n: LocalizerType;
}; };
@ -15,6 +16,7 @@ type UserChangedActionType = {
payload: { payload: {
ourNumber: string; ourNumber: string;
regionCode: string; regionCode: string;
isSecondaryDevice: boolean;
}; };
}; };
@ -29,6 +31,7 @@ export const actions = {
function userChanged(attributes: { function userChanged(attributes: {
ourNumber: string; ourNumber: string;
regionCode: string; regionCode: string;
isSecondaryDevice: boolean;
}): UserChangedActionType { }): UserChangedActionType {
return { return {
type: 'USER_CHANGED', type: 'USER_CHANGED',
@ -42,6 +45,7 @@ function getEmptyState(): UserStateType {
return { return {
ourNumber: 'missing', ourNumber: 'missing',
regionCode: 'missing', regionCode: 'missing',
isSecondaryDevice: false,
i18n: () => 'missing', i18n: () => 'missing',
}; };
} }

@ -21,3 +21,8 @@ export const getIntl = createSelector(
getUser, getUser,
(state: UserStateType): LocalizerType => state.i18n (state: UserStateType): LocalizerType => state.i18n
); );
export const getIsSecondaryDevice = createSelector(
getUser,
(state: UserStateType): boolean => state.isSecondaryDevice
);

@ -5,7 +5,12 @@ import { MainHeader } from '../../components/MainHeader';
import { StateType } from '../reducer'; import { StateType } from '../reducer';
import { getQuery } from '../selectors/search'; 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'; import { getMe } from '../selectors/conversations';
const mapStateToProps = (state: StateType) => { const mapStateToProps = (state: StateType) => {
@ -13,6 +18,7 @@ const mapStateToProps = (state: StateType) => {
searchTerm: getQuery(state), searchTerm: getQuery(state),
regionCode: getRegionCode(state), regionCode: getRegionCode(state),
ourNumber: getUserNumber(state), ourNumber: getUserNumber(state),
isSecondaryDevice: getIsSecondaryDevice(state),
...getMe(state), ...getMe(state),
i18n: getIntl(state), i18n: getIntl(state),
}; };

Loading…
Cancel
Save