Skip to content

Commit

Permalink
runfix: Allow opening device preferences after enrollment
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Jan 17, 2024
1 parent ce1997e commit 2c48aaa
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/script/E2EIdentity/DelayTimer/delay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function getDelayTime(gracePeriodInMs: number): number {
}

export function shouldEnableSoftLock(enrollmentConfig: EnrollmentConfig, identity?: WireIdentity): boolean {
if (!enrollmentConfig.timer.isSnoozeTimeAvailable() || enrollmentConfig.isFreshMLSSelfClient) {
if (!enrollmentConfig.timer.isSnoozeTimeAvailable()) {
// The user has used up the entire grace period or has a fresh new client, he now needs to enroll
return true;
}
Expand Down
108 changes: 56 additions & 52 deletions src/script/E2EIdentity/E2EIdentityEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
getActiveWireIdentity,
MLSStatuses,
WireIdentity,
isFreshMLSSelfClient,
} from './E2EIdentityVerification';
import {getModalOptions, ModalType} from './Modals';
import {OIDCService} from './OIDCService';
Expand Down Expand Up @@ -72,7 +73,6 @@ export type EnrollmentConfig = {
timer: DelayTimerService;
discoveryUrl: string;
gracePeriodInMs: number;
isFreshMLSSelfClient?: boolean;
};

const historyTimeMS = 28 * TimeInMillis.DAY; //HT
Expand Down Expand Up @@ -122,7 +122,7 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
E2EIHandler.instance = null;
}

public async initialize({discoveryUrl, gracePeriodInSeconds, isFreshMLSSelfClient = false}: E2EIHandlerParams) {
public async initialize({discoveryUrl, gracePeriodInSeconds}: E2EIHandlerParams) {
if (isE2EIEnabled()) {
const gracePeriodInMs = gracePeriodInSeconds * TIME_IN_MILLIS.SECOND;
this.config = {
Expand All @@ -133,7 +133,6 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
gracePeriodExpiredCallback: () => null,
delayPeriodExpiredCallback: () => null,
}),
isFreshMLSSelfClient,
};
}
return this;
Expand All @@ -145,14 +144,8 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
// If the client already has a certificate, we don't need to start the enrollment
return;
}
this.showE2EINotificationMessage();
return new Promise<void>(resolve => {
const handleSuccess = () => {
this.off('identityUpdated', handleSuccess);
resolve();
};
this.on('identityUpdated', handleSuccess);
});
const isFreshDevice = await isFreshMLSSelfClient();
return this.showE2EINotificationMessage(ModalType.ENROLL, isFreshDevice);
}

public async attemptRenewal(): Promise<void> {
Expand Down Expand Up @@ -312,10 +305,10 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
setTimeout(removeCurrentModal, 0);

this.currentStep = E2EIHandlerStep.SUCCESS;
this.showSuccessMessage(isCertificateRenewal);

// clear the oidc service progress/data and successful enrolment
await this.cleanUp(false);

return this.showSuccessMessage(isCertificateRenewal);
} catch (error) {
this.currentStep = E2EIHandlerStep.ERROR;

Expand Down Expand Up @@ -344,19 +337,22 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
return;
}

const {modalOptions, modalType} = getModalOptions({
type: ModalType.SUCCESS,
hideSecondary: false,
hideClose: false,
extraParams: {
isRenewal: isCertificateRenewal,
},
primaryActionFn: () => this.emit('identityUpdated', {enrollmentConfig: this.config!}),
secondaryActionFn: () => {
amplify.publish(WebAppEvents.PREFERENCES.MANAGE_DEVICES);
},
return new Promise<void>(resolve => {
const {modalOptions, modalType} = getModalOptions({
type: ModalType.SUCCESS,
hideSecondary: false,
hideClose: false,
extraParams: {
isRenewal: isCertificateRenewal,
},
primaryActionFn: resolve,
secondaryActionFn: () => {
amplify.publish(WebAppEvents.PREFERENCES.MANAGE_DEVICES);
resolve();
},
});
PrimaryModal.show(modalType, modalOptions);
});
PrimaryModal.show(modalType, modalOptions);
}

private async showErrorMessage(): Promise<void> {
Expand All @@ -382,7 +378,7 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
void this.enroll();
},
secondaryActionFn: () => {
this.showE2EINotificationMessage();
this.showE2EINotificationMessage(ModalType.ENROLL);
},
});

Expand All @@ -403,35 +399,45 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
this.config?.timer.updateParams({
gracePeriodInMS: this.config.gracePeriodInMs,
gracePeriodExpiredCallback: () => {
this.showE2EINotificationMessage();
this.showE2EINotificationMessage(ModalType.ENROLL);
},
delayPeriodExpiredCallback: () => {
this.showE2EINotificationMessage();
this.showE2EINotificationMessage(ModalType.ENROLL);
},
});
this.currentStep = E2EIHandlerStep.INITIALIZED;
}
}

private async showModal(modalType: ModalType = ModalType.ENROLL, hideSecondary = false): Promise<void> {
// Check if config is defined and timer is available
const isSoftLockEnabled = shouldEnableSoftLock(this.config!);
private async showEnrollmentModal(
modalType: ModalType.ENROLL | ModalType.CERTIFICATE_RENEWAL,
disableSnooze: boolean,
): Promise<void> {
// Show the modal with the provided modal type
return new Promise<void>(resolve => {
const {modalOptions, modalType: determinedModalType} = getModalOptions({
hideSecondary: disableSnooze,
primaryActionFn: async () => {
await this.enroll();
resolve();
},
secondaryActionFn: () => {
this.currentStep = E2EIHandlerStep.SNOOZE;
this.config?.timer.delayPrompt();
this.showSnoozeModal();
resolve();
},
type: modalType,
hideClose: true,
});
PrimaryModal.show(determinedModalType, modalOptions);
});
}

private showSnoozeModal() {
// Show the modal with the provided modal type
const {modalOptions, modalType: determinedModalType} = getModalOptions({
hideSecondary: isSoftLockEnabled || hideSecondary,
primaryActionFn: () => {
if (modalType === ModalType.SNOOZE_REMINDER) {
return undefined;
}
return this.enroll();
},
secondaryActionFn: () => {
this.currentStep = E2EIHandlerStep.SNOOZE;
this.config?.timer.delayPrompt();
this.handleE2EIReminderSnooze();
},
type: modalType,
type: ModalType.SNOOZE_REMINDER,
hideClose: true,
extraParams: {
delayTime: formatDelayTime(getDelayTime(this.config!.gracePeriodInMs)),
Expand All @@ -440,16 +446,14 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
PrimaryModal.show(determinedModalType, modalOptions);
}

private handleE2EIReminderSnooze(): void {
void this.showModal(ModalType.SNOOZE_REMINDER, true);
}

public showE2EINotificationMessage(modalType: ModalType = ModalType.ENROLL): void {
public async showE2EINotificationMessage(
modalType: ModalType.CERTIFICATE_RENEWAL | ModalType.ENROLL,
disableSnooze: boolean = false,
): Promise<void> {
// If the user has already started enrolment, don't show the notification. Instead, show the loading modal
// This will occur after the redirect from the oauth provider
if (this.coreE2EIService.isEnrollmentInProgress()) {
void this.enroll();
return;
return this.enroll();
}

// Early return if we shouldn't show the notification
Expand All @@ -461,7 +465,7 @@ export class E2EIHandler extends TypedEventEmitter<Events> {

// If the timer is not active, show the notification modal
if (this.config && !this.config.timer.isDelayTimerActive()) {
void this.showModal(modalType);
return this.showEnrollmentModal(modalType, disableSnooze);
}
}
}
7 changes: 1 addition & 6 deletions src/script/components/AppContainer/AppContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {StyledApp, THEME_ID} from '@wireapp/react-ui-kit';

import {PrimaryModalComponent} from 'Components/Modals/PrimaryModal/PrimaryModal';
import {SIGN_OUT_REASON} from 'src/script/auth/SignOutReason';
import {useAppSoftLock} from 'src/script/hooks/useAppSoftLock';
import {useSingleInstance} from 'src/script/hooks/useSingleInstance';
import {PROPERTIES_TYPE} from 'src/script/properties/PropertiesType';

Expand Down Expand Up @@ -76,10 +75,6 @@ export const AppContainer: FC<AppProps> = ({config, clientType}) => {
return () => document.removeEventListener('scroll', resetWindowScroll);
}, []);

const {repository: repositories} = app;

const {softLockEnabled} = useAppSoftLock(repositories.calling, repositories.notification);

if (hasOtherInstance) {
app.redirectToLogin(SIGN_OUT_REASON.MULTIPLE_TABS);
return null;
Expand All @@ -89,7 +84,7 @@ export const AppContainer: FC<AppProps> = ({config, clientType}) => {
<>
<AppLoader init={onProgress => app.initApp(clientType, onProgress)}>
{selfUser => {
return <AppMain app={app} selfUser={selfUser} mainView={mainView} locked={softLockEnabled} />;
return <AppMain app={app} selfUser={selfUser} mainView={mainView} />;
}}
</AppLoader>
<StyledApp themeId={THEME_ID.DEFAULT} css={{backgroundColor: 'unset', height: '100%'}}>
Expand Down
5 changes: 3 additions & 2 deletions src/script/hooks/useAppSoftLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export function useAppSoftLock(callingRepository: CallingRepository, notificatio
if (!e2eiEnabled) {
return () => {};
}
const e2eiHandler = E2EIHandler.getInstance();

E2EIHandler.getInstance().on('identityUpdated', handleSoftLockActivation);
e2eiHandler.on('identityUpdated', handleSoftLockActivation);
return () => {
E2EIHandler.getInstance().off('identityUpdated', handleSoftLockActivation);
e2eiHandler.off('identityUpdated', handleSoftLockActivation);
};
}, [e2eiEnabled, handleSoftLockActivation]);

Expand Down
6 changes: 3 additions & 3 deletions src/script/page/AppMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {useAppState, ContentState} from './useAppState';

import {ConversationState} from '../conversation/ConversationState';
import {User} from '../entity/User';
import {useAppSoftLock} from '../hooks/useAppSoftLock';
import {useInitializeRootFontSize} from '../hooks/useRootFontSize';
import {App} from '../main/app';
import {initialiseMLSMigrationFlow} from '../mls/MLSMigration';
Expand All @@ -69,16 +70,13 @@ interface AppMainProps {
selfUser: User;
mainView: MainViewModel;
conversationState?: ConversationState;
/** will block the user from being able to interact with the application (no notifications and no messages will be shown) */
locked: boolean;
}

export const AppMain: FC<AppMainProps> = ({
app,
mainView,
selfUser,
conversationState = container.resolve(ConversationState),
locked,
}) => {
const apiContext = app.getAPIContext();

Expand All @@ -92,6 +90,8 @@ export const AppMain: FC<AppMainProps> = ({

const {repository: repositories} = app;

const {softLockEnabled: locked} = useAppSoftLock(repositories.calling, repositories.notification);

const {availability: userAvailability, isActivatedAccount} = useKoSubscribableChildren(selfUser, [
'availability',
'isActivatedAccount',
Expand Down

0 comments on commit 2c48aaa

Please sign in to comment.