2019-08-29 14:20:14 +00:00
|
|
|
/*
|
2021-06-22 16:22:38 +00:00
|
|
|
Copyright 2019 - 2021 The Matrix.org Foundation C.I.C.
|
2019-08-29 14:20:14 +00: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.
|
|
|
|
*/
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import { SERVICE_TYPES } from "matrix-js-sdk/src/service-types";
|
2021-10-22 22:23:32 +00:00
|
|
|
import { logger } from "matrix-js-sdk/src/logger";
|
2021-06-22 16:22:38 +00:00
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
import SdkConfig from "../SdkConfig";
|
|
|
|
import { MatrixClientPeg } from "../MatrixClientPeg";
|
2019-08-29 14:20:14 +00:00
|
|
|
|
2021-06-22 16:22:38 +00:00
|
|
|
export function getDefaultIdentityServerUrl(): string {
|
2022-03-18 16:12:36 +00:00
|
|
|
return SdkConfig.get("validated_server_config").isUrl;
|
2019-08-29 14:20:14 +00:00
|
|
|
}
|
|
|
|
|
2022-07-29 11:01:15 +00:00
|
|
|
export function setToDefaultIdentityServer(): void {
|
2019-08-29 14:20:14 +00:00
|
|
|
const url = getDefaultIdentityServerUrl();
|
|
|
|
// Account data change will update localstorage, client, etc through dispatcher
|
|
|
|
MatrixClientPeg.get().setAccountData("m.identity_server", {
|
|
|
|
base_url: url,
|
|
|
|
});
|
|
|
|
}
|
2019-10-31 11:58:31 +00:00
|
|
|
|
2021-06-22 16:22:38 +00:00
|
|
|
export async function doesIdentityServerHaveTerms(fullUrl: string): Promise<boolean> {
|
2019-10-31 11:58:31 +00:00
|
|
|
let terms;
|
|
|
|
try {
|
|
|
|
terms = await MatrixClientPeg.get().getTerms(SERVICE_TYPES.IS, fullUrl);
|
|
|
|
} catch (e) {
|
2021-10-15 14:30:53 +00:00
|
|
|
logger.error(e);
|
2019-10-31 11:58:31 +00:00
|
|
|
if (e.cors === "rejected" || e.httpStatus === 404) {
|
|
|
|
terms = null;
|
|
|
|
} else {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 11:24:14 +00:00
|
|
|
return terms && terms["policies"] && Object.keys(terms["policies"]).length > 0;
|
2019-10-31 11:58:31 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 16:22:38 +00:00
|
|
|
export function doesAccountDataHaveIdentityServer(): boolean {
|
2019-10-31 11:58:31 +00:00
|
|
|
const event = MatrixClientPeg.get().getAccountData("m.identity_server");
|
2022-12-12 11:24:14 +00:00
|
|
|
return event && event.getContent() && event.getContent()["base_url"];
|
2019-10-31 11:58:31 +00:00
|
|
|
}
|