Eliminate the use of MatrixClientPeg in utils (#10910)

This commit is contained in:
Michael Telatynski 2023-05-23 16:24:12 +01:00 committed by GitHub
parent a0c2676c38
commit 30429df948
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
108 changed files with 409 additions and 325 deletions

View file

@ -17,27 +17,27 @@ limitations under the License.
import { SERVICE_TYPES } from "matrix-js-sdk/src/service-types";
import { logger } from "matrix-js-sdk/src/logger";
import { HTTPError } from "matrix-js-sdk/src/http-api";
import { MatrixClient } from "matrix-js-sdk/src/matrix";
import SdkConfig from "../SdkConfig";
import { MatrixClientPeg } from "../MatrixClientPeg";
import { Policies } from "../Terms";
export function getDefaultIdentityServerUrl(): string | undefined {
return SdkConfig.get("validated_server_config")?.isUrl;
}
export function setToDefaultIdentityServer(): void {
export function setToDefaultIdentityServer(matrixClient: MatrixClient): void {
const url = getDefaultIdentityServerUrl();
// Account data change will update localstorage, client, etc through dispatcher
MatrixClientPeg.get().setAccountData("m.identity_server", {
matrixClient.setAccountData("m.identity_server", {
base_url: url,
});
}
export async function doesIdentityServerHaveTerms(fullUrl: string): Promise<boolean> {
export async function doesIdentityServerHaveTerms(matrixClient: MatrixClient, fullUrl: string): Promise<boolean> {
let terms: { policies?: Policies } | null;
try {
terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl);
terms = await matrixClient.getTerms(SERVICE_TYPES.IS, fullUrl);
} catch (e) {
logger.error(e);
if (e.cors === "rejected" || (e instanceof HTTPError && e.httpStatus === 404)) {
@ -50,7 +50,7 @@ export async function doesIdentityServerHaveTerms(fullUrl: string): Promise<bool
return !!terms?.["policies"] && Object.keys(terms["policies"]).length > 0;
}
export function doesAccountDataHaveIdentityServer(): boolean {
const event = MatrixClientPeg.get().getAccountData("m.identity_server");
return event && event.getContent() && event.getContent()["base_url"];
export function doesAccountDataHaveIdentityServer(matrixClient: MatrixClient): boolean {
const event = matrixClient.getAccountData("m.identity_server");
return event?.getContent()["base_url"];
}