mv element.io @types __mocks__/ debian docker module_system/ playwright res src test webapp Dockerfile .dockerignore .eslintignore .stylelintrc.cjs babel.config.cjs recorder-worklet-loader.cjs .modernizr.json components.json config.json config.sample.json package.json project.json tsconfig.json tsconfig.module_system.json jest.config.ts playwright.config.ts webpack.config.ts build_config.sample.yaml apps/web/
mkdir apps/web/scripts
mv scripts/{cleanup.sh,ci_package.sh,copy-res.ts,deploy.py,package.sh} apps/web/scripts
And a couple of gitignore tweaks
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { type ComponentProps } from "react";
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
|
||||
import type { Room } from "matrix-js-sdk/src/matrix";
|
||||
import ScalarAuthClient from "../ScalarAuthClient";
|
||||
import { dialogTermsInteractionCallback, TermsNotSignedError } from "../Terms";
|
||||
import Modal from "../Modal";
|
||||
import SettingsStore from "../settings/SettingsStore";
|
||||
import IntegrationManager from "../components/views/settings/IntegrationManager";
|
||||
import { IntegrationManagers } from "./IntegrationManagers";
|
||||
import { parseUrl } from "../utils/UrlUtils";
|
||||
|
||||
export enum Kind {
|
||||
Account = "account",
|
||||
Config = "config",
|
||||
Homeserver = "homeserver",
|
||||
}
|
||||
|
||||
export class IntegrationManagerInstance {
|
||||
// Per the spec: UI URL is optional.
|
||||
public constructor(
|
||||
public readonly kind: string,
|
||||
public readonly apiUrl: string,
|
||||
public readonly uiUrl: string = apiUrl,
|
||||
public readonly id?: string, // only applicable in some cases
|
||||
) {}
|
||||
|
||||
public get name(): string {
|
||||
const parsed = parseUrl(this.uiUrl);
|
||||
return parsed.host ?? "";
|
||||
}
|
||||
|
||||
public get trimmedApiUrl(): string {
|
||||
const parsed = parseUrl(this.apiUrl);
|
||||
parsed.pathname = "";
|
||||
return parsed.toString();
|
||||
}
|
||||
|
||||
public getScalarClient(): ScalarAuthClient {
|
||||
return new ScalarAuthClient(this.apiUrl, this.uiUrl);
|
||||
}
|
||||
|
||||
public async open(room: Room, screen?: string, integrationId?: string): Promise<void> {
|
||||
if (!SettingsStore.getValue("integrationProvisioning")) {
|
||||
return IntegrationManagers.sharedInstance().showDisabledDialog();
|
||||
}
|
||||
|
||||
const dialog = Modal.createDialog(IntegrationManager, { loading: true }, "mx_IntegrationManager");
|
||||
|
||||
const client = this.getScalarClient();
|
||||
client.setTermsInteractionCallback((policyInfo, agreedUrls) => {
|
||||
// To avoid visual glitching of two modals stacking briefly, we customise the
|
||||
// terms dialog sizing when it will appear for the integration manager so that
|
||||
// it gets the same basic size as the integration manager's own modal.
|
||||
return dialogTermsInteractionCallback(policyInfo, agreedUrls, "mx_TermsDialog_forIntegrationManager");
|
||||
});
|
||||
|
||||
const newProps: Partial<ComponentProps<typeof IntegrationManager>> = {};
|
||||
try {
|
||||
await client.connect();
|
||||
if (!client.hasCredentials()) {
|
||||
newProps["connected"] = false;
|
||||
} else {
|
||||
newProps["url"] = client.getScalarInterfaceUrlForRoom(room, screen, integrationId);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof TermsNotSignedError) {
|
||||
dialog.close();
|
||||
return;
|
||||
}
|
||||
|
||||
logger.error(e);
|
||||
newProps["connected"] = false;
|
||||
}
|
||||
|
||||
// Close the old dialog and open a new one
|
||||
dialog.close();
|
||||
Modal.createDialog(IntegrationManager, newProps, "mx_IntegrationManager");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2019 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { ClientEvent, type IClientWellKnown, type MatrixClient, type MatrixEvent } from "matrix-js-sdk/src/matrix";
|
||||
|
||||
import SdkConfig from "../SdkConfig";
|
||||
import Modal from "../Modal";
|
||||
import { IntegrationManagerInstance, Kind } from "./IntegrationManagerInstance";
|
||||
import IntegrationsImpossibleDialog from "../components/views/dialogs/IntegrationsImpossibleDialog";
|
||||
import { IntegrationsDisabledDialog } from "../components/views/dialogs/IntegrationsDisabledDialog";
|
||||
import WidgetUtils from "../utils/WidgetUtils";
|
||||
import { MatrixClientPeg } from "../MatrixClientPeg";
|
||||
|
||||
const KIND_PREFERENCE = [
|
||||
// Ordered: first is most preferred, last is least preferred.
|
||||
Kind.Account,
|
||||
Kind.Homeserver,
|
||||
Kind.Config,
|
||||
];
|
||||
|
||||
export class IntegrationManagers {
|
||||
private static instance?: IntegrationManagers;
|
||||
|
||||
private managers: IntegrationManagerInstance[] = [];
|
||||
private client?: MatrixClient;
|
||||
private primaryManager: IntegrationManagerInstance | null = null;
|
||||
|
||||
public static sharedInstance(): IntegrationManagers {
|
||||
if (!IntegrationManagers.instance) {
|
||||
IntegrationManagers.instance = new IntegrationManagers();
|
||||
}
|
||||
return IntegrationManagers.instance;
|
||||
}
|
||||
|
||||
public constructor() {
|
||||
this.compileManagers();
|
||||
}
|
||||
|
||||
public startWatching(): void {
|
||||
this.stopWatching();
|
||||
this.client = MatrixClientPeg.safeGet();
|
||||
this.client.on(ClientEvent.AccountData, this.onAccountData);
|
||||
this.client.on(ClientEvent.ClientWellKnown, this.setupHomeserverManagers);
|
||||
this.compileManagers();
|
||||
}
|
||||
|
||||
public stopWatching(): void {
|
||||
if (!this.client) return;
|
||||
this.client.removeListener(ClientEvent.AccountData, this.onAccountData);
|
||||
this.client.removeListener(ClientEvent.ClientWellKnown, this.setupHomeserverManagers);
|
||||
}
|
||||
|
||||
private compileManagers(): void {
|
||||
this.managers = [];
|
||||
this.setupConfiguredManager();
|
||||
this.setupAccountManagers();
|
||||
}
|
||||
|
||||
private setupConfiguredManager(): void {
|
||||
const apiUrl = SdkConfig.get("integrations_rest_url");
|
||||
const uiUrl = SdkConfig.get("integrations_ui_url");
|
||||
|
||||
if (apiUrl && uiUrl) {
|
||||
this.managers.push(new IntegrationManagerInstance(Kind.Config, apiUrl, uiUrl));
|
||||
this.primaryManager = null; // reset primary
|
||||
}
|
||||
}
|
||||
|
||||
private setupHomeserverManagers = async (discoveryResponse: IClientWellKnown): Promise<void> => {
|
||||
logger.log("Updating homeserver-configured integration managers...");
|
||||
if (discoveryResponse && discoveryResponse["m.integrations"]) {
|
||||
let managers = discoveryResponse["m.integrations"]["managers"];
|
||||
if (!Array.isArray(managers)) managers = []; // make it an array so we can wipe the HS managers
|
||||
|
||||
logger.log(`Homeserver has ${managers.length} integration managers`);
|
||||
|
||||
// Clear out any known managers for the homeserver
|
||||
// TODO: Log out of the scalar clients
|
||||
this.managers = this.managers.filter((m) => m.kind !== Kind.Homeserver);
|
||||
|
||||
// Now add all the managers the homeserver wants us to have
|
||||
for (const hsManager of managers) {
|
||||
if (!hsManager["api_url"]) continue;
|
||||
this.managers.push(
|
||||
new IntegrationManagerInstance(
|
||||
Kind.Homeserver,
|
||||
hsManager["api_url"],
|
||||
hsManager["ui_url"], // optional
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
this.primaryManager = null; // reset primary
|
||||
} else {
|
||||
logger.log("Homeserver has no integration managers");
|
||||
}
|
||||
};
|
||||
|
||||
private setupAccountManagers(): void {
|
||||
if (!this.client || !this.client.getUserId()) return; // not logged in
|
||||
const widgets = WidgetUtils.getIntegrationManagerWidgets(this.client);
|
||||
widgets.forEach((w) => {
|
||||
const data = w.content["data"];
|
||||
if (!data) return;
|
||||
|
||||
const uiUrl = w.content["url"];
|
||||
const apiUrl = data["api_url"] as string;
|
||||
if (!apiUrl || !uiUrl) return;
|
||||
|
||||
const manager = new IntegrationManagerInstance(
|
||||
Kind.Account,
|
||||
apiUrl,
|
||||
uiUrl,
|
||||
w["id"] || w["state_key"] || "",
|
||||
);
|
||||
this.managers.push(manager);
|
||||
});
|
||||
this.primaryManager = null; // reset primary
|
||||
}
|
||||
|
||||
private onAccountData = (ev: MatrixEvent): void => {
|
||||
if (ev.getType() === "m.widgets") {
|
||||
this.compileManagers();
|
||||
}
|
||||
};
|
||||
|
||||
public hasManager(): boolean {
|
||||
return this.managers.length > 0;
|
||||
}
|
||||
|
||||
public getOrderedManagers(): IntegrationManagerInstance[] {
|
||||
const collator = new Intl.Collator();
|
||||
const ordered: IntegrationManagerInstance[] = [];
|
||||
for (const kind of KIND_PREFERENCE) {
|
||||
const managers = this.managers.filter((m) => m.kind === kind);
|
||||
if (!managers || !managers.length) continue;
|
||||
|
||||
if (kind === Kind.Account) {
|
||||
// Order by state_keys (IDs)
|
||||
managers.sort((a, b) => collator.compare(a.id ?? "", b.id ?? ""));
|
||||
}
|
||||
|
||||
ordered.push(...managers);
|
||||
}
|
||||
return ordered;
|
||||
}
|
||||
|
||||
public getPrimaryManager(): IntegrationManagerInstance | null {
|
||||
if (this.hasManager()) {
|
||||
if (this.primaryManager) return this.primaryManager;
|
||||
|
||||
this.primaryManager = this.getOrderedManagers()[0];
|
||||
return this.primaryManager;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public openNoManagerDialog(): void {
|
||||
Modal.createDialog(IntegrationsImpossibleDialog);
|
||||
}
|
||||
|
||||
public showDisabledDialog(): void {
|
||||
Modal.createDialog(IntegrationsDisabledDialog);
|
||||
}
|
||||
}
|
||||
|
||||
// For debugging
|
||||
window.mxIntegrationManagers = IntegrationManagers;
|
||||
Reference in New Issue
Block a user