Fix race condition in AccountSettingsHandler local echo (#9172)

Should fix https://github.com/vector-im/element-web/issues/23006
This commit is contained in:
Travis Ralston 2022-08-10 19:34:21 -04:00 committed by GitHub
parent 946aa7f979
commit 0697d1d6d4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -165,8 +165,8 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
content[field] = value;
await this.client.setAccountData(eventType, content);
// Attach a deferred *before* setting the account data to ensure we catch any requests
// which race between different lines.
const deferred = defer<void>();
const handler = (event: MatrixEvent) => {
if (event.getType() !== eventType || event.getContent()[field] !== value) return;
@ -175,6 +175,8 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
};
this.client.on(ClientEvent.AccountData, handler);
await this.client.setAccountData(eventType, content);
await deferred.promise;
}