Skip to content

Commit 8025ab4

Browse files
committed
Refactor and fix intent bugs
1 parent a613180 commit 8025ab4

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

src/models/Call.ts

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -568,13 +568,14 @@ export class ElementCall extends Call {
568568
this.checkDestroy();
569569
}
570570

571-
private static generateWidgetUrl(client: MatrixClient, roomId: string, intent?: ElementCallIntent): URL {
571+
private static generateWidgetUrl(client: MatrixClient, roomId: string): URL {
572572
const baseUrl = window.location.href;
573573
let url = new URL("./widgets/element-call/index.html#", baseUrl); // this strips hash fragment from baseUrl
574574

575575
const elementCallUrl = SettingsStore.getValue("Developer.elementCallUrl");
576576
if (elementCallUrl) url = new URL(elementCallUrl);
577577

578+
578579
// Splice together the Element Call URL for this call
579580
const params = new URLSearchParams({
580581
confineToRoom: "true", // Only show the call interface for the configured room
@@ -590,17 +591,35 @@ export class ElementCall extends Call {
590591
lang: getCurrentLanguage().replace("_", "-"),
591592
fontScale: (FontWatcher.getRootFontSize() / FontWatcher.getBrowserDefaultFontSize()).toString(),
592593
theme: "$org.matrix.msc2873.client_theme",
593-
...(intent && { intent })
594594
});
595595

596596
const room = client.getRoom(roomId);
597597
if (room !== null && !isVideoRoom(room)) {
598+
const isDM = RoomListStore.instance.getTagsForRoom(room).includes(DefaultTagID.DM);
598599
params.append(
599600
"sendNotificationType",
600-
RoomListStore.instance.getTagsForRoom(room).includes(DefaultTagID.DM) ? "ring" : "notification",
601+
isDM ? "ring" : "notification",
601602
);
603+
if (isDM) {
604+
const oldestMembership = client.matrixRTC.getRoomSession(room).getOldestMembership();
605+
if (!oldestMembership) {
606+
// We are starting a call
607+
params.append("intent", ElementCallIntent.StartCallDM);
608+
// We force skiplobby to be true here as DMs never want to show a lobby.
609+
params.set("skipLobby", "true");
610+
// We force preload to be false, as the default in Element Call is `true` and we're going
611+
// to immediately jump into the call.
612+
params.set("preload", "false");
613+
} else if (oldestMembership.sender !== client.getSafeUserId()) {
614+
// We are joining a call.
615+
params.append("intent", ElementCallIntent.JoinExistingDM);
616+
params.set("skipLobby", "true");
617+
params.set("preload", "false");
618+
} // else, don't set an intent.
619+
}
602620
}
603621

622+
604623
const rageshakeSubmitUrl = SdkConfig.get("bug_report_endpoint_url");
605624
if (rageshakeSubmitUrl) {
606625
params.append("rageshakeSubmitUrl", rageshakeSubmitUrl);
@@ -681,24 +700,9 @@ export class ElementCall extends Call {
681700
return ecWidget;
682701
}
683702

684-
let intent: ElementCallIntent|undefined;
685-
const room = client.getRoom(roomId);
686-
const functionalMembers = room && getJoinedNonFunctionalMembers(room);
687-
const isDm = functionalMembers ? functionalMembers.length === 2 : false;
688-
689-
if (room && isDm) {
690-
const oldestMembership = client.matrixRTC.getRoomSession(room).getOldestMembership();
691-
if (!oldestMembership) {
692-
// We are starting a call
693-
intent = ElementCallIntent.StartCallDM;
694-
} else if (oldestMembership.sender !== client.getSafeUserId()) {
695-
intent = ElementCallIntent.JoinExistingDM;
696-
} // else, the call is ongoing but it was from us so just handle as normal.
697-
}
698-
699703
// To use Element Call without touching room state, we create a virtual
700704
// widget (one that doesn't have a corresponding state event)
701-
const url = ElementCall.generateWidgetUrl(client, roomId, intent);
705+
const url = ElementCall.generateWidgetUrl(client, roomId);
702706
const createdWidget = WidgetStore.instance.addVirtualWidget(
703707
{
704708
id: secureRandomString(24), // So that it's globally unique

0 commit comments

Comments
 (0)