Skip to content

Commit

Permalink
[Backport staging] Ensure setUserCreator is called when a store is …
Browse files Browse the repository at this point in the history
…assigned (#3876)

Co-authored-by: R Midhun Suresh <[email protected]>
  • Loading branch information
RiotRobot and MidhunSureshR authored Nov 13, 2023
1 parent fe3f969 commit 46a6a76
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
public reEmitter = new TypedReEmitter<EmittedEvents, ClientEventHandlerMap>(this);
public olmVersion: [number, number, number] | null = null; // populated after initCrypto
public usingExternalCrypto = false;
public store: Store;
private _store!: Store;
public deviceId: string | null;
public credentials: { userId: string | null };

Expand Down Expand Up @@ -1342,7 +1342,6 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa

this.usingExternalCrypto = opts.usingExternalCrypto ?? false;
this.store = opts.store || new StubStore();
this.store.setUserCreator((userId) => User.createUser(userId, this));
this.deviceId = opts.deviceId || null;
this.sessionId = randomString(10);

Expand Down Expand Up @@ -1507,6 +1506,15 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
this._secretStorage = new ServerSideSecretStorageImpl(this, opts.cryptoCallbacks ?? {});
}

public set store(newStore: Store) {
this._store = newStore;
this._store.setUserCreator((userId) => User.createUser(userId, this));
}

public get store(): Store {
return this._store;
}

/**
* High level helper method to begin syncing and poll for new events. To listen for these
* events, add a listener for {@link ClientEvent.Event}
Expand Down

0 comments on commit 46a6a76

Please sign in to comment.