Skip to content

Commit

Permalink
runfix: always calculate the next fire date
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykBuniX committed May 23, 2024
1 parent 1a1cd80 commit b15d2c7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 36 deletions.
1 change: 0 additions & 1 deletion src/script/E2EIdentity/E2EIdentityEnrollment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ describe('E2EIHandler', () => {
const enrollmentStore = getEnrollmentStore(user.qualifiedId, selfClientId);

enrollmentStore.clear.deviceCreatedAt();
enrollmentStore.clear.timer();

// Mock the Config to enable e2eIdentity
(util.supportsMLS as jest.Mock).mockReturnValue(true);
Expand Down
10 changes: 1 addition & 9 deletions src/script/E2EIdentity/E2EIdentityEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,12 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
const timerKey = 'enrollmentTimer';
const identity = await getActiveWireIdentity();

const {firingDate: computedFiringDate, isSnoozable} = getEnrollmentTimer(
identity,
e2eActivatedAt,
this.config.gracePeriodInMs,
);
const {firingDate, isSnoozable} = getEnrollmentTimer(identity, e2eActivatedAt, this.config.gracePeriodInMs);

const task = async () => {
this.enrollmentStore.clear.timer();
await this.processEnrollmentUponExpiry(isSnoozable);
};

const firingDate = this.enrollmentStore.get.timer() || computedFiringDate;
this.enrollmentStore.store.timer(firingDate);

const isNotActivated = identity?.status === MLSStatuses.NOT_ACTIVATED;
const isBasicDevice = identity?.credentialType === CredentialType.Basic;

Expand Down
7 changes: 0 additions & 7 deletions src/script/E2EIdentity/Enrollment.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,16 @@ import {QualifiedId} from '@wireapp/api-client/lib/user';
import {constructFullyQualifiedClientId} from '@wireapp/core/lib/util/fullyQualifiedClientIdUtils';

const e2eActivatedAtKey = 'e2eActivatedAt';
const e2eTimer = 'e2eTimer';

interface EnrollmentStore {
store: {
e2eiActivatedAt: (time: number) => void;
timer: (time: number) => void;
};
get: {
e2eiActivatedAt: () => number;
timer: () => number;
};
clear: {
deviceCreatedAt: () => void;
timer: () => void;
};
}

Expand All @@ -45,15 +41,12 @@ export const getEnrollmentStore = ({id: userId, domain}: QualifiedId, clientId:
return {
store: {
e2eiActivatedAt: (time: number) => localStorage.setItem(constructKey(e2eActivatedAtKey), String(time)),
timer: (time: number) => localStorage.setItem(constructKey(e2eTimer), String(time)),
},
get: {
e2eiActivatedAt: () => Number(localStorage.getItem(constructKey(e2eActivatedAtKey))),
timer: () => Number(localStorage.getItem(constructKey(e2eTimer))),
},
clear: {
deviceCreatedAt: () => localStorage.removeItem(constructKey(e2eActivatedAtKey)),
timer: () => localStorage.removeItem(constructKey(e2eTimer)),
},
};
};
18 changes: 0 additions & 18 deletions src/script/hooks/useDeviceIdentities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import {useCallback, useEffect, useState} from 'react';
import {QualifiedId} from '@wireapp/api-client/lib/user';
import {stringifyQualifiedId} from '@wireapp/core/lib/util/qualifiedIdUtil';

import {TIME_IN_MILLIS} from 'Util/TimeUtil';

import {E2EIHandler, getUsersIdentities, MLSStatuses, WireIdentity} from '../E2EIdentity';

export const useUserIdentity = (userId: QualifiedId, groupId?: string, updateAfterEnrollment?: boolean) => {
Expand Down Expand Up @@ -73,19 +71,3 @@ export const useUserIdentity = (userId: QualifiedId, groupId?: string, updateAft
: undefined,
};
};

export const useIsSelfWithinGracePeriod = () => {
const [isGracePeriod, setIsGracePeriod] = useState<boolean>(false);

const refreshGracePeriod = useCallback(async () => {
return E2EIHandler.getInstance().isWithinGracePeriod().then(setIsGracePeriod);
}, []);

useEffect(() => {
void refreshGracePeriod();

setTimeout(refreshGracePeriod, TIME_IN_MILLIS.SECOND);
}, [refreshGracePeriod]);

return isGracePeriod;
};
40 changes: 40 additions & 0 deletions src/script/hooks/useIsSelfWithinGracePeriod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*
*/

import {useCallback, useEffect, useState} from 'react';

import {TIME_IN_MILLIS} from 'Util/TimeUtil';

import {E2EIHandler} from '../E2EIdentity';

export const useIsSelfWithinGracePeriod = () => {
const [isGracePeriod, setIsGracePeriod] = useState<boolean>(false);

const refreshGracePeriod = useCallback(async () => {
return E2EIHandler.getInstance().isWithinGracePeriod().then(setIsGracePeriod);
}, []);

useEffect(() => {
void refreshGracePeriod();

setTimeout(refreshGracePeriod, TIME_IN_MILLIS.SECOND);
}, [refreshGracePeriod]);

return isGracePeriod;
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {Button, ButtonVariant} from '@wireapp/react-ui-kit';

import {VerificationBadges} from 'Components/VerificationBadge';
import {E2EIHandler, MLSStatuses, WireIdentity} from 'src/script/E2EIdentity';
import {useIsSelfWithinGracePeriod} from 'src/script/hooks/useDeviceIdentities';
import {useIsSelfWithinGracePeriod} from 'src/script/hooks/useIsSelfWithinGracePeriod';
import {t} from 'Util/LocalizerUtil';
import {getLogger} from 'Util/Logger';

Expand Down

0 comments on commit b15d2c7

Please sign in to comment.