Skip to content

Commit

Permalink
runfix: Show enrollment modal the first time e2ei is enabled (#17049)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc committed Mar 11, 2024
1 parent 07499d1 commit 3f2d532
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/script/E2EIdentity/E2EIdentityEnrollment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {UserState} from 'src/script/user/UserState';
import * as util from 'Util/util';

import {E2EIHandler} from './E2EIdentityEnrollment';
import {EnrollmentStore} from './Enrollment.store';
import {OIDCServiceStore} from './OIDCService/OIDCServiceStorage';

import {ConversationState} from '../conversation/ConversationState';
Expand Down Expand Up @@ -69,6 +70,8 @@ describe('E2EIHandler', () => {
E2EIHandler.resetInstance();
// Clear all mocks before each test
jest.clearAllMocks();
EnrollmentStore.clear.deviceCreatedAt();
EnrollmentStore.clear.timer();

// Mock the Config to enable e2eIdentity
(util.supportsMLS as jest.Mock).mockReturnValue(true);
Expand Down Expand Up @@ -160,6 +163,7 @@ describe('E2EIHandler', () => {
const conversationState = container.resolve(ConversationState);
jest.spyOn(conversationState, 'getSelfMLSConversation').mockReturnValue(new Conversation() as any);

EnrollmentStore.store.e2eiActivatedAt(Date.now());
jest.spyOn(coreMock.service!.e2eIdentity!, 'isEnrollmentInProgress').mockResolvedValue(false);
jest.spyOn(coreMock.service!.e2eIdentity!, 'isFreshMLSSelfClient').mockResolvedValue(false);
jest
Expand Down
8 changes: 6 additions & 2 deletions src/script/E2EIdentity/E2EIdentityEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
*/
public async startTimers() {
// We store the first time the user was prompted with the enrollment modal
const e2eActivatedAt = EnrollmentStore.get.e2eiActivatedAt() || Date.now();
const storedE2eActivatedAt = EnrollmentStore.get.e2eiActivatedAt();
const e2eActivatedAt = storedE2eActivatedAt || Date.now();
EnrollmentStore.store.e2eiActivatedAt(e2eActivatedAt);

const timerKey = 'enrollmentTimer';
Expand All @@ -160,7 +161,10 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
const firingDate = EnrollmentStore.get.timer() || computedFiringDate;
EnrollmentStore.store.timer(firingDate);

if (firingDate <= Date.now()) {
const isFirstE2EIActivation = !storedE2eActivatedAt;
if (isFirstE2EIActivation || firingDate <= Date.now()) {
// We want to automatically trigger the enrollment modal if it's a devices in team that just activated e2eidentity
// Or if the timer is supposed to fire now
void task();
} else {
LowPrecisionTaskScheduler.addTask({
Expand Down

0 comments on commit 3f2d532

Please sign in to comment.