cleaning: Stop using deprecated callMembershipsForRoom (#31616)
* cleaning: Stop using deprecated callMembershipsForRoom * fix test * review: Added quick doc
This commit is contained in:
+8
-3
@@ -25,7 +25,7 @@ import {
|
|||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import { type PermissionChanged as PermissionChangedEvent } from "@matrix-org/analytics-events/types/typescript/PermissionChanged";
|
import { type PermissionChanged as PermissionChangedEvent } from "@matrix-org/analytics-events/types/typescript/PermissionChanged";
|
||||||
import { type IRTCNotificationContent, MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
|
import { type IRTCNotificationContent } from "matrix-js-sdk/src/matrixrtc";
|
||||||
|
|
||||||
import { MatrixClientPeg } from "./MatrixClientPeg";
|
import { MatrixClientPeg } from "./MatrixClientPeg";
|
||||||
import { PosthogAnalytics } from "./PosthogAnalytics";
|
import { PosthogAnalytics } from "./PosthogAnalytics";
|
||||||
@@ -486,8 +486,13 @@ class NotifierClass extends TypedEventEmitter<keyof EmittedEvents, EmittedEvents
|
|||||||
private performCustomEventHandling(ev: MatrixEvent): void {
|
private performCustomEventHandling(ev: MatrixEvent): void {
|
||||||
const cli = MatrixClientPeg.safeGet();
|
const cli = MatrixClientPeg.safeGet();
|
||||||
const room = cli.getRoom(ev.getRoomId());
|
const room = cli.getRoom(ev.getRoomId());
|
||||||
const thisUserHasConnectedDevice =
|
const rtcSession = room ? cli.matrixRTC.getRoomSession(room) : null;
|
||||||
room && MatrixRTCSession.callMembershipsForRoom(room).some((m) => m.sender === cli.getUserId());
|
let thisUserHasConnectedDevice = false;
|
||||||
|
if (rtcSession?.slotDescription?.application == "m.call") {
|
||||||
|
// Get the current state, the actual IncomingCallToast will update as needed by
|
||||||
|
// listening to the rtcSession directly.
|
||||||
|
thisUserHasConnectedDevice = rtcSession.memberships.some((m) => m.userId === cli.getUserId());
|
||||||
|
}
|
||||||
|
|
||||||
if (EventType.RTCNotification === ev.getType() && !thisUserHasConnectedDevice) {
|
if (EventType.RTCNotification === ev.getType() && !thisUserHasConnectedDevice) {
|
||||||
const content = ev.getContent() as IRTCNotificationContent;
|
const content = ev.getContent() as IRTCNotificationContent;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import {
|
|||||||
type AccountDataEvents,
|
type AccountDataEvents,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { waitFor } from "jest-matrix-react";
|
import { waitFor } from "jest-matrix-react";
|
||||||
import { CallMembership, MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
|
import { CallMembership, type MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
|
||||||
|
|
||||||
import type BasePlatform from "../../src/BasePlatform";
|
import type BasePlatform from "../../src/BasePlatform";
|
||||||
import Notifier from "../../src/Notifier";
|
import Notifier from "../../src/Notifier";
|
||||||
@@ -433,7 +433,7 @@ describe("Notifier", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should not show toast when group call is already connected", () => {
|
it("should not show toast when group call is already connected", () => {
|
||||||
const spyCallMemberships = jest.spyOn(MatrixRTCSession, "callMembershipsForRoom").mockReturnValue([
|
const members = [
|
||||||
new CallMembership(
|
new CallMembership(
|
||||||
mkEvent({
|
mkEvent({
|
||||||
event: true,
|
event: true,
|
||||||
@@ -450,14 +450,17 @@ describe("Notifier", () => {
|
|||||||
device_id: "DEVICE",
|
device_id: "DEVICE",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]);
|
];
|
||||||
|
|
||||||
const roomSession = MatrixRTCSession.roomSessionForRoom(mockClient, testRoom);
|
const mockRtcSession = {
|
||||||
|
memberships: members,
|
||||||
|
slotDescription: { application: "m.call", id: "" },
|
||||||
|
} as unknown as MatrixRTCSession;
|
||||||
|
|
||||||
|
mockClient.matrixRTC.getRoomSession.mockReturnValue(mockRtcSession);
|
||||||
|
|
||||||
mockClient.matrixRTC.getRoomSession.mockReturnValue(roomSession);
|
|
||||||
emitCallNotificationEvent();
|
emitCallNotificationEvent();
|
||||||
expect(ToastStore.sharedInstance().addOrReplaceToast).not.toHaveBeenCalled();
|
expect(ToastStore.sharedInstance().addOrReplaceToast).not.toHaveBeenCalled();
|
||||||
spyCallMemberships.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not show toast when calling with a different event type to org.matrix.msc4075.rtc.notification", () => {
|
it("should not show toast when calling with a different event type to org.matrix.msc4075.rtc.notification", () => {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
RoomVersionStability,
|
RoomVersionStability,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
import { type CryptoApi } from "matrix-js-sdk/src/crypto-api";
|
import { type CryptoApi } from "matrix-js-sdk/src/crypto-api";
|
||||||
import { MatrixRTCSession } from "matrix-js-sdk/src/matrixrtc";
|
|
||||||
import { act } from "jest-matrix-react";
|
import { act } from "jest-matrix-react";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -292,8 +291,6 @@ describe("createRoom", () => {
|
|||||||
|
|
||||||
it("sets up Element video rooms correctly", async () => {
|
it("sets up Element video rooms correctly", async () => {
|
||||||
const createCallSpy = jest.spyOn(ElementCall, "create");
|
const createCallSpy = jest.spyOn(ElementCall, "create");
|
||||||
const callMembershipSpy = jest.spyOn(MatrixRTCSession, "callMembershipsForRoom");
|
|
||||||
callMembershipSpy.mockReturnValue([]);
|
|
||||||
|
|
||||||
await createRoom(client, { roomType: RoomType.UnstableCall });
|
await createRoom(client, { roomType: RoomType.UnstableCall });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user