2019-02-22 16:33:20 -07:00
|
|
|
/*
|
2020-07-28 16:20:05 -06:00
|
|
|
Copyright 2019, 2020 The Matrix.org Foundation C.I.C.
|
2019-02-22 16:33:20 -07:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-28 16:20:05 -06:00
|
|
|
import { MatrixClient } from "matrix-js-sdk/src/client";
|
2021-10-15 16:31:29 +02:00
|
|
|
|
2021-10-22 17:23:32 -05:00
|
|
|
import SettingsHandler from "./SettingsHandler";
|
|
|
|
|
|
2019-02-22 16:33:20 -07:00
|
|
|
// Dev note: This whole class exists in the event someone logs out and back in - we want
|
|
|
|
|
// to make sure the right MatrixClient is listening for changes.
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Represents the base class for settings handlers which need access to a MatrixClient.
|
|
|
|
|
* This class performs no logic and should be overridden.
|
|
|
|
|
*/
|
2020-07-28 16:20:05 -06:00
|
|
|
export default abstract class MatrixClientBackedSettingsHandler extends SettingsHandler {
|
|
|
|
|
private static _matrixClient: MatrixClient;
|
|
|
|
|
private static instances: MatrixClientBackedSettingsHandler[] = [];
|
2019-02-22 16:33:20 -07:00
|
|
|
|
2020-07-28 16:20:05 -06:00
|
|
|
public static set matrixClient(client: MatrixClient) {
|
2019-02-22 16:33:20 -07:00
|
|
|
const oldClient = MatrixClientBackedSettingsHandler._matrixClient;
|
|
|
|
|
MatrixClientBackedSettingsHandler._matrixClient = client;
|
|
|
|
|
|
2020-07-28 16:20:05 -06:00
|
|
|
for (const instance of MatrixClientBackedSettingsHandler.instances) {
|
2019-02-22 16:33:20 -07:00
|
|
|
instance.initMatrixClient(oldClient, client);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-28 16:20:05 -06:00
|
|
|
protected constructor() {
|
2019-02-22 16:33:20 -07:00
|
|
|
super();
|
|
|
|
|
|
2020-07-28 16:20:05 -06:00
|
|
|
MatrixClientBackedSettingsHandler.instances.push(this);
|
2019-02-22 16:33:20 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-28 16:20:05 -06:00
|
|
|
public get client(): MatrixClient {
|
2020-07-29 11:51:42 -06:00
|
|
|
return MatrixClientBackedSettingsHandler._matrixClient;
|
2020-06-22 10:18:38 -06:00
|
|
|
}
|
|
|
|
|
|
2022-03-03 22:09:06 +00:00
|
|
|
protected abstract initMatrixClient(oldClient: MatrixClient, newClient: MatrixClient);
|
2019-02-22 16:33:20 -07:00
|
|
|
}
|