Fix race condition in AccountSettingsHandler
local echo (#9172)
Should fix https://github.com/vector-im/element-web/issues/23006
This commit is contained in:
parent
946aa7f979
commit
0697d1d6d4
1 changed files with 4 additions and 2 deletions
|
@ -165,8 +165,8 @@ export default class AccountSettingsHandler extends MatrixClientBackedSettingsHa
|
||||||
|
|
||||||
content[field] = value;
|
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 deferred = defer<void>();
|
||||||
const handler = (event: MatrixEvent) => {
|
const handler = (event: MatrixEvent) => {
|
||||||
if (event.getType() !== eventType || event.getContent()[field] !== value) return;
|
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);
|
this.client.on(ClientEvent.AccountData, handler);
|
||||||
|
|
||||||
|
await this.client.setAccountData(eventType, content);
|
||||||
|
|
||||||
await deferred.promise;
|
await deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue