use notification type in url params

This commit is contained in:
Timo
2025-07-18 13:29:50 +02:00
parent 46698055e6
commit 5af3537454
3 changed files with 10 additions and 41 deletions

View File

@@ -8,6 +8,7 @@ Please see LICENSE in the repository root for full details.
import { useMemo } from "react";
import { useLocation } from "react-router-dom";
import { logger } from "matrix-js-sdk/lib/logger";
import { type RTCNotificationType } from "matrix-js-sdk/lib/matrixrtc";
import { Config } from "./config/Config";
import { type EncryptionSystem } from "./e2ee/sharedKeyManagement";
@@ -194,13 +195,9 @@ export interface UrlParams {
*/
sentryEnvironment: string | null;
/**
* Whether to send a notification when the user joins the call.
* This does all the necessary logic to check if it is actually appropriate to send the notification,
* - is it the first joiner
* - it it a 1:1 room
* - ...
* Whether and what type of notification EC should send, when the user joins the call.
*/
sendNotification: boolean;
sendNotificationType?: RTCNotificationType;
}
// This is here as a stopgap, but what would be far nicer is a function that
@@ -283,6 +280,11 @@ export const getUrlParams = (
? HeaderStyle.None
: HeaderStyle.Standard);
const sendNotificationType = ["ring", "notification"].includes(
parser.getParam("sendNotificationType") ?? "",
)
? (parser.getParam("sendNotificationType") as RTCNotificationType)
: undefined;
const widgetId = parser.getParam("widgetId");
const parentUrl = parser.getParam("parentUrl");
const isWidget = !!widgetId && !!parentUrl;
@@ -337,7 +339,7 @@ export const getUrlParams = (
rageshakeSubmitUrl: parser.getParam("rageshakeSubmitUrl"),
sentryDsn: parser.getParam("sentryDsn"),
sentryEnvironment: parser.getParam("sentryEnvironment"),
sendNotification: parser.getFlagParam("sendNotification"),
sendNotificationType,
};
};

View File

@@ -6,7 +6,6 @@ Please see LICENSE in the repository root for full details.
*/
import {
type RTCNotificationType,
type MatrixRTCSession,
} from "matrix-js-sdk/lib/matrixrtc";
import { logger } from "matrix-js-sdk/lib/logger";
@@ -17,14 +16,12 @@ import {
type LivekitFocusActive,
} from "matrix-js-sdk/lib/matrixrtc";
import { AutoDiscovery } from "matrix-js-sdk/lib/autodiscovery";
import { type Room } from "matrix-js-sdk";
import { PosthogAnalytics } from "./analytics/PosthogAnalytics";
import { Config } from "./config/Config";
import { ElementWidgetActions, widget, type WidgetHelpers } from "./widget";
import { MatrixRTCFocusMissingError } from "./utils/errors";
import { getUrlParams } from "./UrlParams";
import { getJoinedNonFunctionalMembers } from "./utils/matrix";
const FOCI_WK_KEY = "org.matrix.msc4143.rtc_foci";
@@ -99,12 +96,6 @@ async function makePreferredLivekitFoci(
// if (focusOtherMembers) preferredFoci.push(focusOtherMembers);
}
function getRTCNotificationType(room: Room): RTCNotificationType | undefined {
if (room.isCallRoom()) return undefined;
if (getJoinedNonFunctionalMembers(room).length === 2) return "ring";
return "notification";
}
export async function enterRTCSession(
rtcSession: MatrixRTCSession,
encryptMedia: boolean,
@@ -127,7 +118,7 @@ export async function enterRTCSession(
await makePreferredLivekitFoci(rtcSession, livekitAlias),
makeActiveFocus(),
{
notificationType: getRTCNotificationType(rtcSession.room),
notificationType: getUrlParams().sendNotificationType,
useNewMembershipManager,
manageMediaKeys: encryptMedia,
...(useDeviceSessionMemberEvents !== undefined && {

View File

@@ -12,10 +12,7 @@ import {
IndexedDBStore,
MemoryStore,
Preset,
type RoomMember,
UNSTABLE_ELEMENT_FUNCTIONAL_USERS,
Visibility,
Direction,
} from "matrix-js-sdk";
import { type ISyncStateData, type SyncState } from "matrix-js-sdk/lib/sync";
import { logger } from "matrix-js-sdk/lib/logger";
@@ -339,27 +336,6 @@ export function getRelativeRoomUrl(
return `/room/#${roomPart}?${generateUrlSearchParams(roomId, encryptionSystem, viaServers).toString()}`;
}
/**
* Returns all room members that are non-functional (all actual room members).
* A functional user is a user that is not a real user, but a bot, assistant, etc.
*/
export function getJoinedNonFunctionalMembers(room: Room): RoomMember[] {
const functionalUsersStateEvent = room
.getLiveTimeline()
.getState(Direction.Forward)
?.getStateEvents(UNSTABLE_ELEMENT_FUNCTIONAL_USERS.name, "");
const functionalMembers = Array.isArray(
functionalUsersStateEvent?.getContent().service_members,
)
? functionalUsersStateEvent.getContent().service_members
: [];
return room
.getJoinedMembers()
.filter((m) => !functionalMembers.includes(m.userId));
}
/**
* Perform a network operation with retries on ConnectionError.
* If the error is not retryable, or the max number of retries is reached, the error is rethrown.