diff --git a/src/state/CallViewModel/CallNotificationLifecycle.test.ts b/src/state/CallViewModel/CallNotificationLifecycle.test.ts index e5463e93..c82253a1 100644 --- a/src/state/CallViewModel/CallNotificationLifecycle.test.ts +++ b/src/state/CallViewModel/CallNotificationLifecycle.test.ts @@ -5,7 +5,6 @@ SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial Please see LICENSE in the repository root for full details. */ -import { type IRTCNotificationContent } from "matrix-js-sdk/lib/matrixrtc"; import { describe, it } from "vitest"; import { EventType, @@ -22,6 +21,7 @@ import { localRtcMember, } from "../../utils/test-fixtures"; import { + type CallNotificationWrapper, createCallNotificationLifecycle$, type Props as CallNotificationLifecycleProps, } from "./CallNotificationLifecycle"; @@ -31,13 +31,13 @@ function mockRingEvent( eventId: string, lifetimeMs: number | undefined, sender = local.userId, -): { event_id: string } & IRTCNotificationContent { +): CallNotificationWrapper { return { event_id: eventId, ...(lifetimeMs === undefined ? {} : { lifetime: lifetimeMs }), notification_type: "ring", sender, - } as unknown as { event_id: string } & IRTCNotificationContent; + } as unknown as CallNotificationWrapper; } describe("waitForCallPickup$", () => { @@ -50,7 +50,7 @@ describe("waitForCallPickup$", () => { behavior("a", { a: [] }).pipe(trackEpoch()), ), sentCallNotification$: hot("10ms a", { - a: [mockRingEvent("$notif1", 30)], + a: mockRingEvent("$notif1", 30), }), receivedDecline$: hot(""), options: { @@ -82,7 +82,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("5ms a", { - a: [mockRingEvent("$notif2", 100)], + a: mockRingEvent("$notif2", 100), }), receivedDecline$: hot(""), options: { @@ -111,7 +111,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("20ms a", { - a: [mockRingEvent("$notif2", 50)], + a: mockRingEvent("$notif2", 50), }), receivedDecline$: hot(""), options: { @@ -138,7 +138,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("10ms a", { - a: [mockRingEvent("$notif2", undefined)], + a: mockRingEvent("$notif2", undefined), }), receivedDecline$: hot(""), options: { @@ -167,7 +167,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("10ms a", { - a: [mockRingEvent("$notif5", 30)], + a: mockRingEvent("$notif5", 30), }), receivedDecline$: hot(""), options: { @@ -206,7 +206,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("10ms a", { - a: [mockRingEvent("$decl1", 50)], + a: mockRingEvent("$decl1", 50), }), receivedDecline$: hot("40ms d", { d: [ @@ -250,7 +250,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("10ms a", { - a: [mockRingEvent("$decl", 20)], + a: mockRingEvent("$decl", 20), }), receivedDecline$: hot("40ms d", { d: [ @@ -301,7 +301,7 @@ describe("waitForCallPickup$", () => { }).pipe(trackEpoch()), ), sentCallNotification$: hot("10ms a", { - a: [mockRingEvent("$right", 50)], + a: mockRingEvent("$right", 50), }), receivedDecline$: hot("20ms d", { d: [ diff --git a/src/state/CallViewModel/CallNotificationLifecycle.ts b/src/state/CallViewModel/CallNotificationLifecycle.ts index b56e2f40..0b2bf27d 100644 --- a/src/state/CallViewModel/CallNotificationLifecycle.ts +++ b/src/state/CallViewModel/CallNotificationLifecycle.ts @@ -9,7 +9,6 @@ import { type CallMembership, type MatrixRTCSession, MatrixRTCSessionEvent, - type MatrixRTCSessionEventHandlerMap, } from "matrix-js-sdk/lib/matrixrtc"; import { combineLatest, @@ -34,6 +33,7 @@ import { EventType, type Room as MatrixRoom, RoomEvent, + type IRTCNotificationContent, } from "matrix-js-sdk"; import { type Behavior } from "../Behavior"; @@ -46,9 +46,11 @@ export type CallPickupState = | "decline" | "success" | null; -export type CallNotificationWrapper = Parameters< - MatrixRTCSessionEventHandlerMap[MatrixRTCSessionEvent.DidSendCallNotification] ->; + +export type CallNotificationWrapper = { + event_id: string; +} & IRTCNotificationContent; + export function createSentCallNotification$( scope: ObservableScope, matrixRTCSession: MatrixRTCSession, @@ -140,12 +142,12 @@ export function createCallNotificationLifecycle$({ scope.behavior( sentCallNotification$.pipe( filter( - (notificationEventArgs) => + (notificationEventArgs: CallNotificationWrapper | null) => // only care about new events (legacy do not have decline pattern) - notificationEventArgs?.[0].notification_type === "ring", + notificationEventArgs?.notification_type === "ring", ), map((e) => e as CallNotificationWrapper), - switchMap(([notificationEvent]) => { + switchMap((notificationEvent) => { const lifetimeMs = notificationEvent?.lifetime ?? 0; return concat( lifetimeMs === 0