Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 569832b

Browse files
committed
Handle ManagedHybrid widgets in useRoomCall and mark them in the widget state event
Signed-off-by: Michael Telatynski <[email protected]>
1 parent 5a2595a commit 569832b

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

src/hooks/room/useRoomCall.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { placeCall } from "../../utils/room/placeCall";
3131
import { Container, WidgetLayoutStore } from "../../stores/widgets/WidgetLayoutStore";
3232
import { useRoomState } from "../useRoomState";
3333
import { _t } from "../../languageHandler";
34+
import { isManagedHybridWidget } from "../../widgets/ManagedHybrid";
3435

3536
export type PlatformCallType = "element_call" | "jitsi_or_element_call" | "legacy_or_jitsi";
3637

@@ -69,6 +70,8 @@ export const useRoomCall = (
6970
const widgets = useWidgets(room);
7071
const jitsiWidget = useMemo(() => widgets.find((widget) => WidgetType.JITSI.matches(widget.type)), [widgets]);
7172
const hasJitsiWidget = !!jitsiWidget;
73+
const managedHybridWidget = useMemo(() => widgets.find(isManagedHybridWidget), [widgets]);
74+
const hasManagedHybridWidget = !!managedHybridWidget;
7275

7376
const groupCall = useCall(room.roomId);
7477
const hasGroupCall = groupCall !== null;
@@ -105,7 +108,7 @@ export const useRoomCall = (
105108
useElementCallExclusively,
106109
mayEditWidgets,
107110
]);
108-
const widget = callType === "element_call" ? groupCall?.widget : jitsiWidget;
111+
const widget = callType === "element_call" ? groupCall?.widget : jitsiWidget ?? managedHybridWidget;
109112

110113
const [canPinWidget, setCanPinWidget] = useState(false);
111114
const [widgetPinned, setWidgetPinned] = useState(false);
@@ -122,7 +125,7 @@ export const useRoomCall = (
122125
}, [room, jitsiWidget, groupCall, updateWidgetState]);
123126

124127
const state = useMemo((): State => {
125-
if (hasGroupCall || hasJitsiWidget) {
128+
if (hasGroupCall || hasJitsiWidget || hasManagedHybridWidget) {
126129
return promptPinWidget ? State.Unpinned : State.Ongoing;
127130
}
128131
if (hasLegacyCall) {
@@ -142,6 +145,7 @@ export const useRoomCall = (
142145
hasGroupCall,
143146
hasJitsiWidget,
144147
hasLegacyCall,
148+
hasManagedHybridWidget,
145149
mayCreateElementCalls,
146150
mayEditWidgets,
147151
memberCount,

src/stores/WidgetStore.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ import { UPDATE_EVENT } from "./AsyncStore";
2929
interface IState {}
3030

3131
export interface IApp extends IWidget {
32-
roomId: string;
33-
eventId?: string; // not present on virtual widgets
32+
"roomId": string;
33+
"eventId"?: string; // not present on virtual widgets
3434
// eslint-disable-next-line camelcase
35-
avatar_url?: string; // MSC2765 https://github.com/matrix-org/matrix-doc/pull/2765
35+
"avatar_url"?: string; // MSC2765 https://github.com/matrix-org/matrix-doc/pull/2765
36+
// Whether the widget was created from `widget_build_url` and thus is a call widget of some kind
37+
"io.element.managed_hybrid"?: boolean;
3638
}
3739

3840
export function isAppWidget(widget: IWidget | IApp): widget is IApp {

src/utils/WidgetUtils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ export default class WidgetUtils {
332332
client: MatrixClient,
333333
roomId: string,
334334
widgetId: string,
335-
content: IWidget,
335+
content: IWidget & Record<string, any>,
336336
): Promise<void> {
337337
const addingWidget = !!content.url;
338338

src/widgets/ManagedHybrid.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { getCallBehaviourWellKnown } from "../utils/WellKnownUtils";
2222
import WidgetUtils from "../utils/WidgetUtils";
2323
import { IStoredLayout, WidgetLayoutStore } from "../stores/widgets/WidgetLayoutStore";
2424
import WidgetEchoStore from "../stores/WidgetEchoStore";
25-
import WidgetStore from "../stores/WidgetStore";
25+
import WidgetStore, { IApp } from "../stores/WidgetStore";
2626
import SdkConfig from "../SdkConfig";
2727
import DMRoomMap from "../utils/DMRoomMap";
2828

@@ -97,7 +97,10 @@ export async function addManagedHybridWidget(roomId: string): Promise<void> {
9797

9898
// Add the widget
9999
try {
100-
await WidgetUtils.setRoomWidgetContent(cli, roomId, widgetId, widgetContent);
100+
await WidgetUtils.setRoomWidgetContent(cli, roomId, widgetId, {
101+
...widgetContent,
102+
"io.element.managed_hybrid": true,
103+
});
101104
} catch (e) {
102105
logger.error(`Unable to add managed hybrid widget in room ${roomId}`, e);
103106
return;
@@ -116,3 +119,7 @@ export async function addManagedHybridWidget(roomId: string): Promise<void> {
116119
WidgetLayoutStore.instance.setContainerHeight(room, layout.container, layout.height);
117120
WidgetLayoutStore.instance.copyLayoutToRoom(room);
118121
}
122+
123+
export function isManagedHybridWidget(widget: IApp): boolean {
124+
return !!widget["io.element.managed_hybrid"];
125+
}

0 commit comments

Comments
 (0)