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:
Michael Telatynski
2026-02-24 15:43:58 +00:00
parent e7509c92a1
commit 91a3cb03c1
3408 changed files with 28 additions and 32 deletions
+434
View File
@@ -0,0 +1,434 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2020, 2021 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 Capability,
EventDirection,
EventKind,
getTimelineRoomIDFromCapability,
isTimelineCapability,
isTimelineCapabilityFor,
MatrixCapabilities,
Symbols,
WidgetEventCapability,
WidgetKind,
} from "matrix-widget-api";
import { EventType, MsgType } from "matrix-js-sdk/src/matrix";
import React from "react";
import { _t, _td, type TranslatedString } from "../languageHandler";
import { ElementWidgetCapabilities } from "../stores/widgets/ElementWidgetCapabilities";
import { MatrixClientPeg } from "../MatrixClientPeg";
import TextWithTooltip from "../components/views/elements/TextWithTooltip";
type GENERIC_WIDGET_KIND = "generic"; // eslint-disable-line @typescript-eslint/naming-convention
const GENERIC_WIDGET_KIND: GENERIC_WIDGET_KIND = "generic";
type SendRecvStaticCapText = Partial<
Record<
EventType | string,
Partial<Record<WidgetKind | GENERIC_WIDGET_KIND, Record<EventDirection, TranslationKey>>>
>
>;
export interface TranslatedCapabilityText {
primary: TranslatedString;
byline?: TranslatedString;
}
export class CapabilityText {
private static simpleCaps: Record<Capability, Partial<Record<WidgetKind | GENERIC_WIDGET_KIND, TranslationKey>>> = {
[MatrixCapabilities.AlwaysOnScreen]: {
[WidgetKind.Room]: _td("widget|capability|always_on_screen_viewing_another_room"),
[GENERIC_WIDGET_KIND]: _td("widget|capability|always_on_screen_generic"),
},
[MatrixCapabilities.StickerSending]: {
[WidgetKind.Room]: _td("widget|capability|send_stickers_this_room"),
[GENERIC_WIDGET_KIND]: _td("widget|capability|send_stickers_active_room"),
},
[ElementWidgetCapabilities.CanChangeViewedRoom]: {
[GENERIC_WIDGET_KIND]: _td("widget|capability|switch_room"),
},
[MatrixCapabilities.MSC2931Navigate]: {
[GENERIC_WIDGET_KIND]: _td("widget|capability|switch_room_message_user"),
},
};
private static stateSendRecvCaps: SendRecvStaticCapText = {
[EventType.RoomTopic]: {
[WidgetKind.Room]: {
[EventDirection.Send]: _td("widget|capability|change_topic_this_room"),
[EventDirection.Receive]: _td("widget|capability|see_topic_change_this_room"),
},
[GENERIC_WIDGET_KIND]: {
[EventDirection.Send]: _td("widget|capability|change_topic_active_room"),
[EventDirection.Receive]: _td("widget|capability|see_topic_change_active_room"),
},
},
[EventType.RoomName]: {
[WidgetKind.Room]: {
[EventDirection.Send]: _td("widget|capability|change_name_this_room"),
[EventDirection.Receive]: _td("widget|capability|see_name_change_this_room"),
},
[GENERIC_WIDGET_KIND]: {
[EventDirection.Send]: _td("widget|capability|change_name_active_room"),
[EventDirection.Receive]: _td("widget|capability|see_name_change_active_room"),
},
},
[EventType.RoomAvatar]: {
[WidgetKind.Room]: {
[EventDirection.Send]: _td("widget|capability|change_avatar_this_room"),
[EventDirection.Receive]: _td("widget|capability|see_avatar_change_this_room"),
},
[GENERIC_WIDGET_KIND]: {
[EventDirection.Send]: _td("widget|capability|change_avatar_active_room"),
[EventDirection.Receive]: _td("widget|capability|see_avatar_change_active_room"),
},
},
[EventType.RoomMember]: {
[WidgetKind.Room]: {
[EventDirection.Send]: _td("widget|capability|remove_ban_invite_leave_this_room"),
[EventDirection.Receive]: _td("widget|capability|receive_membership_this_room"),
},
[GENERIC_WIDGET_KIND]: {
[EventDirection.Send]: _td("widget|capability|remove_ban_invite_leave_active_room"),
[EventDirection.Receive]: _td("widget|capability|receive_membership_active_room"),
},
},
};
private static nonStateSendRecvCaps: SendRecvStaticCapText = {
[EventType.Sticker]: {
[WidgetKind.Room]: {
[EventDirection.Send]: _td("widget|capability|send_stickers_this_room_as_you"),
[EventDirection.Receive]: _td("widget|capability|see_sticker_posted_this_room"),
},
[GENERIC_WIDGET_KIND]: {
[EventDirection.Send]: _td("widget|capability|send_stickers_active_room_as_you"),
[EventDirection.Receive]: _td("widget|capability|see_sticker_posted_active_room"),
},
},
};
private static bylineFor(eventCap: WidgetEventCapability): TranslatedString {
if (eventCap.kind === EventKind.State) {
return !eventCap.keyStr
? _t("widget|capability|byline_empty_state_key")
: _t("widget|capability|byline_state_key", { stateKey: eventCap.keyStr });
}
return null; // room messages are handled specially
}
public static for(capability: Capability, kind: WidgetKind): TranslatedCapabilityText {
// TODO: Support MSC3819 (to-device capabilities)
// First see if we have a super simple line of text to provide back
if (CapabilityText.simpleCaps[capability]) {
const textForKind = CapabilityText.simpleCaps[capability];
if (textForKind[kind]) return { primary: _t(textForKind[kind]!) };
if (textForKind[GENERIC_WIDGET_KIND]) return { primary: _t(textForKind[GENERIC_WIDGET_KIND]) };
// ... we'll fall through to the generic capability processing at the end of this
// function if we fail to generate a string for the capability.
}
// Try to handle timeline capabilities. The text here implies that the caller has sorted
// the timeline caps to the end for UI purposes.
if (isTimelineCapability(capability)) {
if (isTimelineCapabilityFor(capability, Symbols.AnyRoom)) {
return { primary: _t("widget|capability|any_room") };
} else {
const roomId = getTimelineRoomIDFromCapability(capability);
const room = MatrixClientPeg.safeGet().getRoom(roomId);
return {
primary: _t(
"widget|capability|specific_room",
{},
{
Room: () => {
if (room) {
return (
<TextWithTooltip tooltip={room.getCanonicalAlias() ?? roomId}>
<strong>{room.name}</strong>
</TextWithTooltip>
);
} else {
return (
<strong>
<code>{roomId}</code>
</strong>
);
}
},
},
),
};
}
}
// We didn't have a super simple line of text, so try processing the capability as the
// more complex event send/receive permission type.
const [eventCap] = WidgetEventCapability.findEventCapabilities([capability]);
if (eventCap) {
// Special case room messages so they show up a bit cleaner to the user. Result is
// effectively "Send images" instead of "Send messages... of type images" if we were
// to handle the msgtype nuances in this function.
if (eventCap.kind === EventKind.Event && eventCap.eventType === EventType.RoomMessage) {
return CapabilityText.forRoomMessageCap(eventCap, kind);
}
// See if we have a static line of text to provide for the given event type and
// direction. The hope is that we do for common event types for friendlier copy.
const evSendRecv =
eventCap.kind === EventKind.State
? CapabilityText.stateSendRecvCaps
: CapabilityText.nonStateSendRecvCaps;
if (evSendRecv[eventCap.eventType]) {
const textForKind = evSendRecv[eventCap.eventType];
const textForDirection = textForKind?.[kind] || textForKind?.[GENERIC_WIDGET_KIND];
if (textForDirection?.[eventCap.direction]) {
return {
primary: _t(textForDirection[eventCap.direction]),
// no byline because we would have already represented the event properly
};
}
}
// We don't have anything simple, so just return a generic string for the event cap
if (kind === WidgetKind.Room) {
if (eventCap.direction === EventDirection.Send) {
return {
primary: _t(
"widget|capability|send_event_type_this_room",
{
eventType: eventCap.eventType,
},
{
b: (sub) => <strong>{sub}</strong>,
},
),
byline: CapabilityText.bylineFor(eventCap),
};
} else {
return {
primary: _t(
"widget|capability|see_event_type_sent_this_room",
{
eventType: eventCap.eventType,
},
{
b: (sub) => <strong>{sub}</strong>,
},
),
byline: CapabilityText.bylineFor(eventCap),
};
}
} else {
// assume generic
if (eventCap.direction === EventDirection.Send) {
return {
primary: _t(
"widget|capability|send_event_type_active_room",
{
eventType: eventCap.eventType,
},
{
b: (sub) => <strong>{sub}</strong>,
},
),
byline: CapabilityText.bylineFor(eventCap),
};
} else {
return {
primary: _t(
"widget|capability|see_event_type_sent_active_room",
{
eventType: eventCap.eventType,
},
{
b: (sub) => <strong>{sub}</strong>,
},
),
byline: CapabilityText.bylineFor(eventCap),
};
}
}
}
// We don't have enough context to render this capability specially, so we'll present it as-is
return {
primary: _t(
"widget|capability|capability",
{ capability },
{
b: (sub) => <strong>{sub}</strong>,
},
),
};
}
private static forRoomMessageCap(eventCap: WidgetEventCapability, kind: WidgetKind): TranslatedCapabilityText {
// First handle the case of "all messages" to make the switch later on a bit clearer
if (!eventCap.keyStr) {
if (eventCap.direction === EventDirection.Send) {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|send_messages_this_room")
: _t("widget|capability|send_messages_active_room"),
};
} else {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|see_messages_sent_this_room")
: _t("widget|capability|see_messages_sent_active_room"),
};
}
}
// Now handle all the message types we care about. There are more message types available, however
// they are not as common so we don't bother rendering them. They'll fall into the generic case.
switch (eventCap.keyStr) {
case MsgType.Text: {
if (eventCap.direction === EventDirection.Send) {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|send_text_messages_this_room")
: _t("widget|capability|send_text_messages_active_room"),
};
} else {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|see_text_messages_sent_this_room")
: _t("widget|capability|see_text_messages_sent_active_room"),
};
}
}
case MsgType.Emote: {
if (eventCap.direction === EventDirection.Send) {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|send_emotes_this_room")
: _t("widget|capability|send_emotes_active_room"),
};
} else {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|see_sent_emotes_this_room")
: _t("widget|capability|see_sent_emotes_active_room"),
};
}
}
case MsgType.Image: {
if (eventCap.direction === EventDirection.Send) {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|send_images_this_room")
: _t("widget|capability|send_images_active_room"),
};
} else {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|see_images_sent_this_room")
: _t("widget|capability|see_images_sent_active_room"),
};
}
}
case MsgType.Video: {
if (eventCap.direction === EventDirection.Send) {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|send_videos_this_room")
: _t("widget|capability|send_videos_active_room"),
};
} else {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|see_videos_sent_this_room")
: _t("widget|capability|see_videos_sent_active_room"),
};
}
}
case MsgType.File: {
if (eventCap.direction === EventDirection.Send) {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|send_files_this_room")
: _t("widget|capability|send_files_active_room"),
};
} else {
return {
primary:
kind === WidgetKind.Room
? _t("widget|capability|see_sent_files_this_room")
: _t("widget|capability|see_sent_files_active_room"),
};
}
}
default: {
let primary: TranslatedString;
if (eventCap.direction === EventDirection.Send) {
if (kind === WidgetKind.Room) {
primary = _t(
"widget|capability|send_msgtype_this_room",
{
msgtype: eventCap.keyStr,
},
{
b: (sub) => <strong>{sub}</strong>,
},
);
} else {
primary = _t(
"widget|capability|send_msgtype_active_room",
{
msgtype: eventCap.keyStr,
},
{
b: (sub) => <strong>{sub}</strong>,
},
);
}
} else {
if (kind === WidgetKind.Room) {
primary = _t(
"widget|capability|see_msgtype_sent_this_room",
{
msgtype: eventCap.keyStr,
},
{
b: (sub) => <strong>{sub}</strong>,
},
);
} else {
primary = _t(
"widget|capability|see_msgtype_sent_active_room",
{
msgtype: eventCap.keyStr,
},
{
b: (sub) => <strong>{sub}</strong>,
},
);
}
}
return { primary };
}
}
}
}
+110
View File
@@ -0,0 +1,110 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2020 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 } from "matrix-js-sdk/src/matrix";
import SdkConfig from "../SdkConfig";
import { MatrixClientPeg } from "../MatrixClientPeg";
const JITSI_WK_PROPERTY_LEGACY = "im.vector.riot.jitsi";
const JITSI_WK_PROPERTY = "io.element.jitsi";
export interface JitsiWidgetData {
conferenceId: string;
isAudioOnly: boolean;
domain: string;
}
export class Jitsi {
private static instance: Jitsi;
private domain?: string;
private _useFor1To1Calls = false;
public get preferredDomain(): string {
return this.domain || "meet.element.io";
}
public get useFor1To1Calls(): boolean {
return this._useFor1To1Calls;
}
/**
* Checks for auth needed by looking up a well-known file
*
* If the file does not exist, we assume no auth.
*
* See https://github.com/matrix-org/prosody-mod-auth-matrix-user-verification
*/
public async getJitsiAuth(): Promise<string | null> {
if (!this.preferredDomain) {
return null;
}
let data;
try {
const response = await fetch(`https://${this.preferredDomain}/.well-known/element/jitsi`);
data = await response.json();
} catch {
return null;
}
if (data.auth) {
return data.auth;
}
return null;
}
public start(): void {
const cli = MatrixClientPeg.safeGet();
cli.on(ClientEvent.ClientWellKnown, this.update);
// call update initially in case we missed the first WellKnown.client event and for if no well-known present
this.update(cli.getClientWellKnown());
}
private update = async (discoveryResponse?: IClientWellKnown): Promise<any> => {
// Start with a default of the config's domain
let domain = SdkConfig.getObject("jitsi")?.get("preferred_domain") || "meet.element.io";
logger.log("Attempting to get Jitsi conference information from homeserver");
const wkJitsiConfig = discoveryResponse?.[JITSI_WK_PROPERTY] ?? discoveryResponse?.[JITSI_WK_PROPERTY_LEGACY];
const wkPreferredDomain = wkJitsiConfig?.["preferredDomain"];
if (wkPreferredDomain) domain = wkPreferredDomain;
// Put the result into memory for us to use later
this.domain = domain;
logger.log("Jitsi conference domain:", this.preferredDomain);
this._useFor1To1Calls = wkJitsiConfig?.["useFor1To1Calls"] || false;
logger.log("Jitsi use for 1:1 calls:", this.useFor1To1Calls);
};
/**
* Parses the given URL into the data needed for a Jitsi widget, if the widget
* URL matches the preferredDomain for the app.
* @param {string} url The URL to parse.
* @returns {JitsiWidgetData} The widget data if eligible, otherwise null.
*/
public parsePreferredConferenceUrl(url: string): JitsiWidgetData | null {
const parsed = new URL(url);
if (parsed.hostname !== this.preferredDomain) return null; // invalid
return {
// URL pathnames always contain a leading slash.
// Remove it to be left with just the conference name.
conferenceId: parsed.pathname.substring(1),
domain: parsed.hostname,
isAudioOnly: false,
};
}
public static getInstance(): Jitsi {
if (!Jitsi.instance) {
Jitsi.instance = new Jitsi();
}
return Jitsi.instance;
}
}
+112
View File
@@ -0,0 +1,112 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2021 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 IWidget } from "matrix-widget-api";
import { logger } from "matrix-js-sdk/src/logger";
import { type Room } from "matrix-js-sdk/src/matrix";
import { getCallBehaviourWellKnown } from "../utils/WellKnownUtils";
import WidgetUtils from "../utils/WidgetUtils";
import { type IStoredLayout, WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore";
import WidgetEchoStore from "../stores/WidgetEchoStore";
import WidgetStore, { type IApp } from "../stores/WidgetStore";
import SdkConfig from "../SdkConfig";
import { getJoinedNonFunctionalMembers } from "../utils/room/getJoinedNonFunctionalMembers";
/* eslint-disable camelcase */
interface IManagedHybridWidgetData {
widget_id: string;
widget: IWidget;
layout: IStoredLayout;
}
/* eslint-enable camelcase */
function getWidgetBuildUrl(room: Room): string | undefined {
const functionalMembers = getJoinedNonFunctionalMembers(room);
const isDm = functionalMembers.length === 2;
if (SdkConfig.get().widget_build_url) {
if (isDm && SdkConfig.get().widget_build_url_ignore_dm) {
return undefined;
}
return SdkConfig.get().widget_build_url;
}
const wellKnown = getCallBehaviourWellKnown(room.client);
if (isDm && wellKnown?.ignore_dm) {
return undefined;
}
/* eslint-disable-next-line camelcase */
return wellKnown?.widget_build_url;
}
export function isManagedHybridWidgetEnabled(room: Room): boolean {
return !!getWidgetBuildUrl(room);
}
export async function addManagedHybridWidget(room: Room): Promise<void> {
// Check for permission
if (!WidgetUtils.canUserModifyWidgets(room.client, room.roomId)) {
logger.error(`User not allowed to modify widgets in ${room.roomId}`);
return;
}
// Get widget data
/* eslint-disable-next-line camelcase */
const widgetBuildUrl = getWidgetBuildUrl(room);
if (!widgetBuildUrl) {
return;
}
let widgetData: IManagedHybridWidgetData;
try {
const response = await fetch(`${widgetBuildUrl}?roomId=${room.roomId}`);
widgetData = await response.json();
} catch (e) {
logger.error(`Managed hybrid widget builder failed for room ${room.roomId}`, e);
return;
}
if (!widgetData) {
return;
}
const { widget_id: widgetId, widget: widgetContent, layout } = widgetData;
// Ensure the widget is not already present in the room
let widgets = WidgetStore.instance.getApps(room.roomId);
const existing = widgets.some((w) => w.id === widgetId) || WidgetEchoStore.roomHasPendingWidgets(room.roomId, []);
if (existing) {
logger.error(`Managed hybrid widget already present in room ${room.roomId}`);
return;
}
// Add the widget
try {
await WidgetUtils.setRoomWidgetContent(room.client, room.roomId, widgetId, {
...widgetContent,
"io.element.managed_hybrid": true,
});
} catch (e) {
logger.error(`Unable to add managed hybrid widget in room ${room.roomId}`, e);
return;
}
// Move the widget into position
if (!WidgetLayoutStore.instance.canCopyLayoutToRoom(room)) {
return;
}
widgets = WidgetStore.instance.getApps(room.roomId);
const installedWidget = widgets.find((w) => w.id === widgetId);
if (!installedWidget) {
return;
}
WidgetLayoutStore.instance.moveToContainer(room, installedWidget, layout.container);
WidgetLayoutStore.instance.setContainerHeight(room, layout.container, layout.height);
WidgetLayoutStore.instance.copyLayoutToRoom(room);
}
export function isManagedHybridWidget(widget: IApp): boolean {
return !!widget["io.element.managed_hybrid"];
}
+35
View File
@@ -0,0 +1,35 @@
/*
Copyright 2024 New Vector Ltd.
Copyright 2020 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.
*/
// TODO: Move to matrix-widget-api
export class WidgetType {
public static readonly JITSI = new WidgetType("m.jitsi", "jitsi");
public static readonly STICKERPICKER = new WidgetType("m.stickerpicker", "m.stickerpicker");
public static readonly INTEGRATION_MANAGER = new WidgetType("m.integration_manager", "m.integration_manager");
public static readonly CUSTOM = new WidgetType("m.custom", "m.custom");
public static readonly CALL = new WidgetType("m.call", "m.call");
public constructor(
public readonly preferred: string,
public readonly legacy: string,
) {}
public matches(type: string): boolean {
return type === this.preferred || type === this.legacy;
}
public static fromString(type: string): WidgetType {
// First try and match it against something we're already aware of
const known = Object.values(WidgetType).filter((v) => v instanceof WidgetType);
const knownMatch = known.find((w) => w.matches(type));
if (knownMatch) return knownMatch;
// If that fails, invent a new widget type
return new WidgetType(type, type);
}
}