From a342293b39b900d8d91303510e28f52e2926fba4 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Thu, 3 Dec 2020 12:35:53 +0100 Subject: [PATCH] add code to get privacy policy from homeserver --- src/preview/HomeServer.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/preview/HomeServer.js b/src/preview/HomeServer.js index 872d8af..5080e3b 100644 --- a/src/preview/HomeServer.js +++ b/src/preview/HomeServer.js @@ -75,6 +75,24 @@ export class HomeServer { } } + async getPrivacyPolicyUrl(lang = "en") { + const headers = new Map(); + headers.set("Content-Type", "application/json"); + const options = {method: "POST", body: "{}", headers}; + const {status, body} = await this._request(`${this.baseURL}/_matrix/client/r0/register`, options).response(); + if (status === 401 && body) { // Unauthorized + const stages = body.flows?.stages; + if (Array.isArray(stages) && stages.includes("m.login.terms")) { + const privacyPolicy = body.params?.["m.login.terms"]?.policies?.privacy_policy; + if (privacyPolicy) { + const firstLang = Object.keys(privacyPolicy).find(k => k !== "version"); + let languagePolicy = privacyPolicy[lang] || privacyPolicy[firstLang]; + return languagePolicy?.url; + } + } + } + } + mxcUrlThumbnail(url, width, height, method) { const parts = parseMxcUrl(url); if (parts) {