diff --git a/src/script/main/app.ts b/src/script/main/app.ts index a96db8eb402..2650428b057 100644 --- a/src/script/main/app.ts +++ b/src/script/main/app.ts @@ -372,6 +372,11 @@ export class App { onProgress(2.5); telemetry.timeStep(AppInitTimingsStep.RECEIVED_ACCESS_TOKEN); + const selfUser = await this.repository.user.getSelf([{position: 'App.initiateSelfUser', vendor: 'webapp'}]); + + await initializeDataDog(this.config, selfUser.qualifiedId); + onProgress(5, t('initReceivedSelfUser', selfUser.name())); + try { await this.core.init(clientType); } catch (error) { @@ -384,7 +389,7 @@ export class App { userRepository.addClientToUser(userId, newClient, true); }); - const selfUser = await this.initiateSelfUser(); + await this.initiateSelfUser(selfUser); const localClient = await this.core.getLocalClient(); if (!localClient) { @@ -403,8 +408,6 @@ export class App { }, }); - await initializeDataDog(this.config, selfUser.qualifiedId); - // Setup all event middleware const eventStorageMiddleware = new EventStorageMiddleware(this.service.event, selfUser); const serviceMiddleware = new ServiceMiddleware(conversationRepository, userRepository, selfUser); @@ -423,7 +426,6 @@ export class App { const federationEventProcessor = new FederationEventProcessor(eventRepository, serverTimeHandler, selfUser); eventRepository.setEventProcessors([federationEventProcessor]); - onProgress(5, t('initReceivedSelfUser', selfUser.name())); telemetry.timeStep(AppInitTimingsStep.RECEIVED_SELF_USER); const clientEntity = await this._initiateSelfUserClients(selfUser, clientRepository); callingRepository.initAvs(selfUser, clientEntity.id); @@ -612,20 +614,18 @@ export class App { * Initiate the self user by getting it from the backend. * @returns Resolves with the self user entity */ - private async initiateSelfUser() { - const userEntity = await this.repository.user.getSelf([{position: 'App.initiateSelfUser', vendor: 'webapp'}]); - - if (!userEntity.hasActivatedIdentity()) { - if (!userEntity.isTemporaryGuest()) { + private async initiateSelfUser(selfUser: User) { + if (!selfUser.hasActivatedIdentity()) { + if (!selfUser.isTemporaryGuest()) { throw new Error('User does not have an activated identity'); } } container.resolve(StorageService).init(this.core.storage); - this.repository.client.init(userEntity); - await this.repository.properties.init(userEntity); + this.repository.client.init(selfUser); + await this.repository.properties.init(selfUser); - return userEntity; + return selfUser; } /**