Skip to content

Commit

Permalink
perf: Init e2ei enrollment process as early as possible (#16671)
Browse files Browse the repository at this point in the history
  • Loading branch information
atomrc authored Jan 29, 2024
1 parent 1d3a180 commit a200b22
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
30 changes: 18 additions & 12 deletions src/script/main/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import {Runtime} from '@wireapp/commons';
import {WebAppEvents} from '@wireapp/webapp-events';

import {PrimaryModal} from 'Components/Modals/PrimaryModal';
import {E2EIHandler} from 'src/script/E2EIdentity';
import {initializeDataDog} from 'Util/DataDog';
import {DebugUtil} from 'Util/DebugUtil';
import {Environment} from 'Util/Environment';
Expand Down Expand Up @@ -389,6 +388,16 @@ export class App {

const selfUser = await this.initiateSelfUser();

const {features: teamFeatures, team} = await teamRepository.initTeam(selfUser.teamId);
const e2eiHandler = await configureE2EI(this.logger, teamFeatures);
if (e2eiHandler) {
/* We first try to do the initial enrollment (if the user has not yet enrolled)
* We need to enroll before anything else (in particular joining MLS conversations)
* Until the user is enrolled, we need to pause loading the app
*/
await e2eiHandler.attemptEnrollment();
}

this.core.configureCoreCallbacks({
groupIdFromConversationId: async conversationId => {
const conversation = await conversationRepository.getConversationById(conversationId);
Expand Down Expand Up @@ -435,18 +444,15 @@ export class App {

const conversations = await conversationRepository.loadConversations();

// We load all the users the self user is connected with
const contacts = await userRepository.loadUsers(selfUser, connections, conversations);
let e2eiHandler: E2EIHandler | undefined;
if (selfUser.teamId) {
const {features: teamFeatures} = await teamRepository.initTeam(selfUser.teamId, contacts);
e2eiHandler = await configureE2EI(this.logger, teamFeatures);
if (e2eiHandler) {
/* We first try to do the initial enrollment (if the user has not yet enrolled)
* We need to enroll before anything else (in particular joining MLS conversations)
* Until the user is enrolled, we need to pause loading the app
*/
await e2eiHandler.attemptEnrollment();
}

if (team) {
// If we are in the context of team, we load the team members metadata (user roles)
await teamRepository.updateTeamMembersByIds(
team,
contacts.filter(user => user.teamId === team.id).map(({id}) => id),
);
}

if (supportsMLS()) {
Expand Down
10 changes: 1 addition & 9 deletions src/script/team/TeamRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,14 @@ export class TeamRepository extends TypedEventEmitter<Events> {
* @param teamId the Id of the team to init
* @param contacts all the contacts the self user has, team members will be deduced from it.
*/
async initTeam(
teamId: string,
contacts: User[] = [],
): Promise<{team: TeamEntity | undefined; features: FeatureList}> {
async initTeam(teamId?: string): Promise<{team: TeamEntity | undefined; features: FeatureList}> {
// async initTeam(teamId?: string): Promise<{members: QualifiedId[]; features: FeatureList}> {
const team = await this.getTeam();
// get the fresh feature config from backend
const {newFeatureList} = await this.updateFeatureConfig();
if (!teamId) {
return {team: undefined, features: {}};
}
await this.updateTeamMembersByIds(
team,
contacts.filter(user => user.teamId === teamId).map(({id}) => id),
);

// Subscribe to team members change and update the user role and guest status
this.teamState.teamMembers.subscribe(members => {
this.userRepository.mapGuestStatus(members);
Expand Down

0 comments on commit a200b22

Please sign in to comment.