Prevent mutations of js-sdk owned objects as it breaks accountData (#7504)

This commit is contained in:
Michael Telatynski 2022-01-10 17:09:35 +00:00 committed by GitHub
parent 3c70aa15d1
commit 8c20bcfe56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 25 deletions

View file

@ -15,7 +15,7 @@ limitations under the License.
*/
import React, { ComponentType, createRef } from 'react';
import { createClient, MatrixClient } from 'matrix-js-sdk/src/matrix';
import { createClient, EventType, MatrixClient } from 'matrix-js-sdk/src/matrix';
import { ISyncStateData, SyncState } from 'matrix-js-sdk/src/sync';
import { MatrixError } from 'matrix-js-sdk/src/http-api';
import { InvalidStoreError } from "matrix-js-sdk/src/errors";
@ -1297,16 +1297,10 @@ export default class MatrixChat extends React.PureComponent<IProps, IState> {
// run without the update to m.direct, making another welcome
// user room (it doesn't wait for new data from the server, just
// the saved sync to be loaded).
const saveWelcomeUser = (ev) => {
if (
ev.getType() === 'm.direct' &&
ev.getContent() &&
ev.getContent()[this.props.config.welcomeUserId]
) {
const saveWelcomeUser = (ev: MatrixEvent) => {
if (ev.getType() === EventType.Direct && ev.getContent()[this.props.config.welcomeUserId]) {
MatrixClientPeg.get().store.save(true);
MatrixClientPeg.get().removeListener(
"accountData", saveWelcomeUser,
);
MatrixClientPeg.get().removeListener("accountData", saveWelcomeUser);
}
};
MatrixClientPeg.get().on("accountData", saveWelcomeUser);