mirror of
https://github.com/vector-im/element-web.git
synced 2024-11-15 12:45:11 +08:00
Avoid using deprecated exports & methods from matrix-js-sdk (#12359)
This commit is contained in:
parent
11912a0da0
commit
4941327c78
@ -19,7 +19,6 @@ limitations under the License.
|
|||||||
import {
|
import {
|
||||||
MatrixClient,
|
MatrixClient,
|
||||||
MsgType,
|
MsgType,
|
||||||
IImageInfo,
|
|
||||||
HTTPError,
|
HTTPError,
|
||||||
IEventRelation,
|
IEventRelation,
|
||||||
ISendEventResponse,
|
ISendEventResponse,
|
||||||
@ -390,7 +389,7 @@ export default class ContentMessages {
|
|||||||
url: string,
|
url: string,
|
||||||
roomId: string,
|
roomId: string,
|
||||||
threadId: string | null,
|
threadId: string | null,
|
||||||
info: IImageInfo,
|
info: ImageInfo,
|
||||||
text: string,
|
text: string,
|
||||||
matrixClient: MatrixClient,
|
matrixClient: MatrixClient,
|
||||||
): Promise<ISendEventResponse> {
|
): Promise<ISendEventResponse> {
|
||||||
|
@ -612,15 +612,7 @@ async function setBotPower(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await client.setPowerLevel(
|
await client.setPowerLevel(roomId, userId, level);
|
||||||
roomId,
|
|
||||||
userId,
|
|
||||||
level,
|
|
||||||
new MatrixEvent({
|
|
||||||
type: "m.room.power_levels",
|
|
||||||
content: powerLevels,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
return sendResponse(event, {
|
return sendResponse(event, {
|
||||||
success: true,
|
success: true,
|
||||||
});
|
});
|
||||||
|
@ -18,7 +18,7 @@ import React, { createRef } from "react";
|
|||||||
import {
|
import {
|
||||||
AuthType,
|
AuthType,
|
||||||
IAuthData,
|
IAuthData,
|
||||||
IAuthDict,
|
AuthDict,
|
||||||
IInputs,
|
IInputs,
|
||||||
InteractiveAuth,
|
InteractiveAuth,
|
||||||
IStageStatus,
|
IStageStatus,
|
||||||
@ -64,7 +64,7 @@ export interface InteractiveAuthProps<T> {
|
|||||||
continueText?: string;
|
continueText?: string;
|
||||||
continueKind?: ContinueKind;
|
continueKind?: ContinueKind;
|
||||||
// callback
|
// callback
|
||||||
makeRequest(auth: IAuthDict | null): Promise<T>;
|
makeRequest(auth: AuthDict | null): Promise<T>;
|
||||||
// callback called when the auth process has finished,
|
// callback called when the auth process has finished,
|
||||||
// successfully or unsuccessfully.
|
// successfully or unsuccessfully.
|
||||||
// @param {boolean} status True if the operation requiring
|
// @param {boolean} status True if the operation requiring
|
||||||
@ -213,7 +213,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
private requestCallback = (auth: IAuthDict | null, background: boolean): Promise<T> => {
|
private requestCallback = (auth: AuthDict | null, background: boolean): Promise<T> => {
|
||||||
// This wrapper just exists because the js-sdk passes a second
|
// This wrapper just exists because the js-sdk passes a second
|
||||||
// 'busy' param for backwards compat. This throws the tests off
|
// 'busy' param for backwards compat. This throws the tests off
|
||||||
// so discard it here.
|
// so discard it here.
|
||||||
@ -246,7 +246,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
|
|||||||
this.stageComponent.current?.focus?.();
|
this.stageComponent.current?.focus?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
private submitAuthDict = (authData: IAuthDict): void => {
|
private submitAuthDict = (authData: AuthDict): void => {
|
||||||
this.authLogic.submitAuthDict(authData);
|
this.authLogic.submitAuthDict(authData);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ import {
|
|||||||
AuthType,
|
AuthType,
|
||||||
createClient,
|
createClient,
|
||||||
IAuthData,
|
IAuthData,
|
||||||
IAuthDict,
|
AuthDict,
|
||||||
IInputs,
|
IInputs,
|
||||||
MatrixError,
|
MatrixError,
|
||||||
IRegisterRequestParams,
|
IRegisterRequestParams,
|
||||||
@ -478,7 +478,7 @@ export default class Registration extends React.Component<IProps, IState> {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
private makeRegisterRequest = (auth: IAuthDict | null): Promise<RegisterResponse> => {
|
private makeRegisterRequest = (auth: AuthDict | null): Promise<RegisterResponse> => {
|
||||||
if (!this.state.matrixClient) throw new Error("Matrix client has not yet been loaded");
|
if (!this.state.matrixClient) throw new Error("Matrix client has not yet been loaded");
|
||||||
|
|
||||||
const registerParams: IRegisterRequestParams = {
|
const registerParams: IRegisterRequestParams = {
|
||||||
|
@ -16,7 +16,7 @@ limitations under the License.
|
|||||||
|
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient } from "matrix-js-sdk/src/matrix";
|
||||||
import { AuthType, IAuthDict, IInputs, IStageStatus } from "matrix-js-sdk/src/interactive-auth";
|
import { AuthType, AuthDict, IInputs, IStageStatus } from "matrix-js-sdk/src/interactive-auth";
|
||||||
import { logger } from "matrix-js-sdk/src/logger";
|
import { logger } from "matrix-js-sdk/src/logger";
|
||||||
import React, { ChangeEvent, createRef, FormEvent, Fragment } from "react";
|
import React, { ChangeEvent, createRef, FormEvent, Fragment } from "react";
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ interface IAuthEntryProps {
|
|||||||
// Is the auth logic currently waiting for something to happen?
|
// Is the auth logic currently waiting for something to happen?
|
||||||
busy?: boolean;
|
busy?: boolean;
|
||||||
onPhaseChange: (phase: number) => void;
|
onPhaseChange: (phase: number) => void;
|
||||||
submitAuthDict: (auth: IAuthDict) => void;
|
submitAuthDict: (auth: AuthDict) => void;
|
||||||
requestEmailToken?: () => Promise<void>;
|
requestEmailToken?: () => Promise<void>;
|
||||||
fail: (error: Error) => void;
|
fail: (error: Error) => void;
|
||||||
clientSecret: string;
|
clientSecret: string;
|
||||||
|
@ -932,7 +932,7 @@ const MuteToggleButton: React.FC<IBaseRoomProps> = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cli.setPowerLevel(roomId, target, level, powerLevelEvent)
|
cli.setPowerLevel(roomId, target, level)
|
||||||
.then(
|
.then(
|
||||||
() => {
|
() => {
|
||||||
// NO-OP; rely on the m.room.member event coming down else we could
|
// NO-OP; rely on the m.room.member event coming down else we could
|
||||||
@ -1159,13 +1159,8 @@ export const PowerLevelEditor: React.FC<{
|
|||||||
async (powerLevel: number) => {
|
async (powerLevel: number) => {
|
||||||
setSelectedPowerLevel(powerLevel);
|
setSelectedPowerLevel(powerLevel);
|
||||||
|
|
||||||
const applyPowerChange = (
|
const applyPowerChange = (roomId: string, target: string, powerLevel: number): Promise<unknown> => {
|
||||||
roomId: string,
|
return cli.setPowerLevel(roomId, target, powerLevel).then(
|
||||||
target: string,
|
|
||||||
powerLevel: number,
|
|
||||||
powerLevelEvent: MatrixEvent,
|
|
||||||
): Promise<unknown> => {
|
|
||||||
return cli.setPowerLevel(roomId, target, powerLevel, powerLevelEvent).then(
|
|
||||||
function () {
|
function () {
|
||||||
// NO-OP; rely on the m.room.member event coming down else we could
|
// NO-OP; rely on the m.room.member event coming down else we could
|
||||||
// get out of sync if we force setState here!
|
// get out of sync if we force setState here!
|
||||||
@ -1213,7 +1208,7 @@ export const PowerLevelEditor: React.FC<{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
|
await applyPowerChange(roomId, target, powerLevel);
|
||||||
},
|
},
|
||||||
[user.roomId, user.userId, cli, room],
|
[user.roomId, user.userId, cli, room],
|
||||||
);
|
);
|
||||||
|
@ -62,7 +62,7 @@ export const AddPrivilegedUsers: React.FC<AddPrivilegedUsersProps> = ({ room, de
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await client.setPowerLevel(room.roomId, userIds, powerLevel, powerLevelEvent);
|
await client.setPowerLevel(room.roomId, userIds, powerLevel);
|
||||||
setSelectedUsers([]);
|
setSelectedUsers([]);
|
||||||
setPowerLevel(defaultUserLevel);
|
setPowerLevel(defaultUserLevel);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
|
||||||
import { IAuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
|
import { AuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
|
||||||
|
|
||||||
import { _t } from "../../../../languageHandler";
|
import { _t } from "../../../../languageHandler";
|
||||||
import Modal from "../../../../Modal";
|
import Modal from "../../../../Modal";
|
||||||
@ -25,7 +25,7 @@ import InteractiveAuthDialog from "../../dialogs/InteractiveAuthDialog";
|
|||||||
|
|
||||||
const makeDeleteRequest =
|
const makeDeleteRequest =
|
||||||
(matrixClient: MatrixClient, deviceIds: string[]) =>
|
(matrixClient: MatrixClient, deviceIds: string[]) =>
|
||||||
async (auth: IAuthDict | null): Promise<IAuthData> => {
|
async (auth: AuthDict | null): Promise<IAuthData> => {
|
||||||
return matrixClient.deleteMultipleDevices(deviceIds, auth ?? undefined);
|
return matrixClient.deleteMultipleDevices(deviceIds, auth ?? undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -347,15 +347,13 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro
|
|||||||
await JitsiCall.create(await room);
|
await JitsiCall.create(await room);
|
||||||
|
|
||||||
// Reset our power level back to admin so that the widget becomes immutable
|
// Reset our power level back to admin so that the widget becomes immutable
|
||||||
const plEvent = (await room).currentState.getStateEvents(EventType.RoomPowerLevels, "");
|
await client.setPowerLevel(roomId, client.getUserId()!, 100);
|
||||||
await client.setPowerLevel(roomId, client.getUserId()!, 100, plEvent);
|
|
||||||
} else if (opts.roomType === RoomType.UnstableCall) {
|
} else if (opts.roomType === RoomType.UnstableCall) {
|
||||||
// Set up this video room with an Element call
|
// Set up this video room with an Element call
|
||||||
await ElementCall.create(await room);
|
await ElementCall.create(await room);
|
||||||
|
|
||||||
// Reset our power level back to admin so that the call becomes immutable
|
// Reset our power level back to admin so that the call becomes immutable
|
||||||
const plEvent = (await room).currentState.getStateEvents(EventType.RoomPowerLevels, "");
|
await client.setPowerLevel(roomId, client.getUserId()!, 100);
|
||||||
await client.setPowerLevel(roomId, client.getUserId()!, 100, plEvent);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
|
@ -74,9 +74,7 @@ export default class JSONExporter extends Exporter {
|
|||||||
logger.log("Error fetching file: " + err);
|
logger.log("Error fetching file: " + err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const jsonEvent: any = mxEv.toJSON();
|
return mxEv.getEffectiveEvent();
|
||||||
const clearEvent = mxEv.isEncrypted() ? jsonEvent.decrypted : jsonEvent;
|
|
||||||
return clearEvent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async createOutput(events: MatrixEvent[]): Promise<string> {
|
protected async createOutput(events: MatrixEvent[]): Promise<string> {
|
||||||
|
@ -15,7 +15,8 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { mocked } from "jest-mock";
|
import { mocked } from "jest-mock";
|
||||||
import { IImageInfo, ISendEventResponse, MatrixClient, RelationType, UploadResponse } from "matrix-js-sdk/src/matrix";
|
import { ISendEventResponse, MatrixClient, RelationType, UploadResponse } from "matrix-js-sdk/src/matrix";
|
||||||
|
import { ImageInfo } from "matrix-js-sdk/src/types";
|
||||||
import { defer } from "matrix-js-sdk/src/utils";
|
import { defer } from "matrix-js-sdk/src/utils";
|
||||||
import encrypt, { IEncryptedFile } from "matrix-encrypt-attachment";
|
import encrypt, { IEncryptedFile } from "matrix-encrypt-attachment";
|
||||||
|
|
||||||
@ -43,7 +44,7 @@ const createElement = document.createElement.bind(document);
|
|||||||
describe("ContentMessages", () => {
|
describe("ContentMessages", () => {
|
||||||
const stickerUrl = "https://example.com/sticker";
|
const stickerUrl = "https://example.com/sticker";
|
||||||
const roomId = "!room:example.com";
|
const roomId = "!room:example.com";
|
||||||
const imageInfo = {} as unknown as IImageInfo;
|
const imageInfo = {} as unknown as ImageInfo;
|
||||||
const text = "test sticker";
|
const text = "test sticker";
|
||||||
let client: MatrixClient;
|
let client: MatrixClient;
|
||||||
let contentMessages: ContentMessages;
|
let contentMessages: ContentMessages;
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
LocationAssetType,
|
LocationAssetType,
|
||||||
M_ASSET,
|
M_ASSET,
|
||||||
M_POLL_END,
|
M_POLL_END,
|
||||||
|
Room,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -31,7 +32,7 @@ import {
|
|||||||
stripHTMLReply,
|
stripHTMLReply,
|
||||||
stripPlainReply,
|
stripPlainReply,
|
||||||
} from "../src/utils/Reply";
|
} from "../src/utils/Reply";
|
||||||
import { makePollStartEvent, mkEvent } from "./test-utils";
|
import { makePollStartEvent, mkEvent, stubClient } from "./test-utils";
|
||||||
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";
|
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";
|
||||||
|
|
||||||
function makeTestEvent(type: string, content: IContent): MatrixEvent {
|
function makeTestEvent(type: string, content: IContent): MatrixEvent {
|
||||||
@ -66,7 +67,7 @@ describe("Reply", () => {
|
|||||||
room: "!room1:server",
|
room: "!room1:server",
|
||||||
content: {},
|
content: {},
|
||||||
});
|
});
|
||||||
event.makeRedacted(event);
|
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));
|
||||||
|
|
||||||
expect(getParentEventId(event)).toBeUndefined();
|
expect(getParentEventId(event)).toBeUndefined();
|
||||||
});
|
});
|
||||||
@ -182,7 +183,7 @@ But this is not
|
|||||||
room: "!room1:server",
|
room: "!room1:server",
|
||||||
content: {},
|
content: {},
|
||||||
});
|
});
|
||||||
event.makeRedacted(event);
|
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));
|
||||||
|
|
||||||
expect(shouldDisplayReply(event)).toBe(false);
|
expect(shouldDisplayReply(event)).toBe(false);
|
||||||
});
|
});
|
||||||
|
@ -419,7 +419,7 @@ describe("TextForEvent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns correct message for redacted poll start", () => {
|
it("returns correct message for redacted poll start", () => {
|
||||||
pollEvent.makeRedacted(pollEvent);
|
pollEvent.makeRedacted(pollEvent, new Room(pollEvent.getRoomId()!, mockClient, mockClient.getSafeUserId()));
|
||||||
|
|
||||||
expect(textForEvent(pollEvent, mockClient)).toEqual("@a: Message deleted");
|
expect(textForEvent(pollEvent, mockClient)).toEqual("@a: Message deleted");
|
||||||
});
|
});
|
||||||
@ -445,7 +445,10 @@ describe("TextForEvent", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("returns correct message for redacted message", () => {
|
it("returns correct message for redacted message", () => {
|
||||||
messageEvent.makeRedacted(messageEvent);
|
messageEvent.makeRedacted(
|
||||||
|
messageEvent,
|
||||||
|
new Room(messageEvent.getRoomId()!, mockClient, mockClient.getSafeUserId()),
|
||||||
|
);
|
||||||
|
|
||||||
expect(textForEvent(messageEvent, mockClient)).toEqual("@a: Message deleted");
|
expect(textForEvent(messageEvent, mockClient)).toEqual("@a: Message deleted");
|
||||||
});
|
});
|
||||||
|
@ -63,7 +63,7 @@ describe("Unread", () => {
|
|||||||
type: EventType.RoomMessage,
|
type: EventType.RoomMessage,
|
||||||
sender: aliceId,
|
sender: aliceId,
|
||||||
});
|
});
|
||||||
redactedEvent.makeRedacted(redactedEvent);
|
redactedEvent.makeRedacted(redactedEvent, new Room(redactedEvent.getRoomId()!, client, aliceId));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
jest.clearAllMocks();
|
jest.clearAllMocks();
|
||||||
@ -408,7 +408,7 @@ describe("Unread", () => {
|
|||||||
content: {},
|
content: {},
|
||||||
});
|
});
|
||||||
console.log("Event Id", redactedEvent.getId());
|
console.log("Event Id", redactedEvent.getId());
|
||||||
redactedEvent.makeRedacted(redactedEvent);
|
redactedEvent.makeRedacted(redactedEvent, room);
|
||||||
console.log("Event Id", redactedEvent.getId());
|
console.log("Event Id", redactedEvent.getId());
|
||||||
// Only for timeline events.
|
// Only for timeline events.
|
||||||
room.addLiveEvents([redactedEvent]);
|
room.addLiveEvents([redactedEvent]);
|
||||||
|
@ -15,7 +15,7 @@ limitations under the License.
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { render } from "@testing-library/react";
|
import { render } from "@testing-library/react";
|
||||||
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
import { EventType, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
|
||||||
import ViewSource from "../../../src/components/structures/ViewSource";
|
import ViewSource from "../../../src/components/structures/ViewSource";
|
||||||
@ -43,7 +43,7 @@ describe("ViewSource", () => {
|
|||||||
content: {},
|
content: {},
|
||||||
state_key: undefined,
|
state_key: undefined,
|
||||||
});
|
});
|
||||||
redactedMessageEvent.makeRedacted(redactionEvent);
|
redactedMessageEvent.makeRedacted(redactionEvent, new Room(ROOM_ID, stubClient(), SENDER));
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(stubClient);
|
beforeEach(stubClient);
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
EventType,
|
EventType,
|
||||||
Relations,
|
Relations,
|
||||||
M_BEACON,
|
M_BEACON,
|
||||||
|
Room,
|
||||||
} from "matrix-js-sdk/src/matrix";
|
} from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import MBeaconBody from "../../../../src/components/views/messages/MBeaconBody";
|
import MBeaconBody from "../../../../src/components/views/messages/MBeaconBody";
|
||||||
@ -304,10 +305,11 @@ describe("<MBeaconBody />", () => {
|
|||||||
|
|
||||||
const redactionEvent = new MatrixEvent({ type: EventType.RoomRedaction, content: { reason: "test reason" } });
|
const redactionEvent = new MatrixEvent({ type: EventType.RoomRedaction, content: { reason: "test reason" } });
|
||||||
|
|
||||||
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []) => {
|
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []): Room => {
|
||||||
const room = makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
|
const room = makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
|
||||||
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent))!;
|
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent))!;
|
||||||
beaconInstance.addLocations(locationEvents);
|
beaconInstance.addLocations(locationEvents);
|
||||||
|
return room;
|
||||||
};
|
};
|
||||||
const mockGetRelationsForEvent = (locationEvents: MatrixEvent[] = []) => {
|
const mockGetRelationsForEvent = (locationEvents: MatrixEvent[] = []) => {
|
||||||
const relations = new Relations(RelationType.Reference, M_BEACON.name, mockClient);
|
const relations = new Relations(RelationType.Reference, M_BEACON.name, mockClient);
|
||||||
@ -320,12 +322,12 @@ describe("<MBeaconBody />", () => {
|
|||||||
|
|
||||||
it("does nothing when getRelationsForEvent is falsy", () => {
|
it("does nothing when getRelationsForEvent is falsy", () => {
|
||||||
const { beaconInfoEvent, location1, location2 } = makeEvents();
|
const { beaconInfoEvent, location1, location2 } = makeEvents();
|
||||||
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
|
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
|
||||||
|
|
||||||
getComponent({ mxEvent: beaconInfoEvent });
|
getComponent({ mxEvent: beaconInfoEvent });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
beaconInfoEvent.makeRedacted(redactionEvent);
|
beaconInfoEvent.makeRedacted(redactionEvent, room);
|
||||||
});
|
});
|
||||||
|
|
||||||
// no error, no redactions
|
// no error, no redactions
|
||||||
@ -349,13 +351,13 @@ describe("<MBeaconBody />", () => {
|
|||||||
it("does nothing when beacon has no related locations", async () => {
|
it("does nothing when beacon has no related locations", async () => {
|
||||||
const { beaconInfoEvent } = makeEvents();
|
const { beaconInfoEvent } = makeEvents();
|
||||||
// no locations
|
// no locations
|
||||||
setupRoomWithBeacon(beaconInfoEvent, []);
|
const room = setupRoomWithBeacon(beaconInfoEvent, []);
|
||||||
const getRelationsForEvent = await mockGetRelationsForEvent();
|
const getRelationsForEvent = await mockGetRelationsForEvent();
|
||||||
|
|
||||||
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
|
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
beaconInfoEvent.makeRedacted(redactionEvent);
|
beaconInfoEvent.makeRedacted(redactionEvent, room);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getRelationsForEvent).toHaveBeenCalledWith(
|
expect(getRelationsForEvent).toHaveBeenCalledWith(
|
||||||
@ -368,14 +370,14 @@ describe("<MBeaconBody />", () => {
|
|||||||
|
|
||||||
it("redacts related locations on beacon redaction", async () => {
|
it("redacts related locations on beacon redaction", async () => {
|
||||||
const { beaconInfoEvent, location1, location2 } = makeEvents();
|
const { beaconInfoEvent, location1, location2 } = makeEvents();
|
||||||
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
|
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
|
||||||
|
|
||||||
const getRelationsForEvent = await mockGetRelationsForEvent([location1, location2]);
|
const getRelationsForEvent = await mockGetRelationsForEvent([location1, location2]);
|
||||||
|
|
||||||
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
|
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
|
||||||
|
|
||||||
act(() => {
|
act(() => {
|
||||||
beaconInfoEvent.makeRedacted(redactionEvent);
|
beaconInfoEvent.makeRedacted(redactionEvent, room);
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(getRelationsForEvent).toHaveBeenCalledWith(
|
expect(getRelationsForEvent).toHaveBeenCalledWith(
|
||||||
|
@ -96,7 +96,7 @@ describe("<MPollEndBody />", () => {
|
|||||||
mockClient.relations.mockResolvedValue({
|
mockClient.relations.mockResolvedValue({
|
||||||
events: [],
|
events: [],
|
||||||
});
|
});
|
||||||
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.toJSON());
|
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.getEffectiveEvent());
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
@ -46,6 +46,14 @@ jest.mock("../../../../src/dispatcher/dispatcher");
|
|||||||
describe("<MessageActionBar />", () => {
|
describe("<MessageActionBar />", () => {
|
||||||
const userId = "@alice:server.org";
|
const userId = "@alice:server.org";
|
||||||
const roomId = "!room:server.org";
|
const roomId = "!room:server.org";
|
||||||
|
|
||||||
|
const client = getMockClientWithEventEmitter({
|
||||||
|
...mockClientMethodsUser(userId),
|
||||||
|
...mockClientMethodsEvents(),
|
||||||
|
getRoom: jest.fn(),
|
||||||
|
});
|
||||||
|
const room = new Room(roomId, client, userId);
|
||||||
|
|
||||||
const alicesMessageEvent = new MatrixEvent({
|
const alicesMessageEvent = new MatrixEvent({
|
||||||
type: EventType.RoomMessage,
|
type: EventType.RoomMessage,
|
||||||
sender: userId,
|
sender: userId,
|
||||||
@ -72,13 +80,7 @@ describe("<MessageActionBar />", () => {
|
|||||||
type: EventType.RoomMessage,
|
type: EventType.RoomMessage,
|
||||||
sender: userId,
|
sender: userId,
|
||||||
});
|
});
|
||||||
redactedEvent.makeRedacted(redactedEvent);
|
redactedEvent.makeRedacted(redactedEvent, room);
|
||||||
|
|
||||||
const client = getMockClientWithEventEmitter({
|
|
||||||
...mockClientMethodsUser(userId),
|
|
||||||
...mockClientMethodsEvents(),
|
|
||||||
getRoom: jest.fn(),
|
|
||||||
});
|
|
||||||
|
|
||||||
const localStorageMock = (() => {
|
const localStorageMock = (() => {
|
||||||
let store: Record<string, any> = {};
|
let store: Record<string, any> = {};
|
||||||
@ -98,7 +100,6 @@ describe("<MessageActionBar />", () => {
|
|||||||
writable: true,
|
writable: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const room = new Room(roomId, client, userId);
|
|
||||||
jest.spyOn(room, "getPendingEvents").mockReturnValue([]);
|
jest.spyOn(room, "getPendingEvents").mockReturnValue([]);
|
||||||
|
|
||||||
client.getRoom.mockReturnValue(room);
|
client.getRoom.mockReturnValue(room);
|
||||||
|
@ -933,12 +933,7 @@ describe("<PowerLevelEditor />", () => {
|
|||||||
// firing the event will raise a dialog warning about self demotion, wait for this to appear then click on it
|
// firing the event will raise a dialog warning about self demotion, wait for this to appear then click on it
|
||||||
await userEvent.click(await screen.findByText("Demote", { exact: true }));
|
await userEvent.click(await screen.findByText("Demote", { exact: true }));
|
||||||
expect(mockClient.setPowerLevel).toHaveBeenCalledTimes(1);
|
expect(mockClient.setPowerLevel).toHaveBeenCalledTimes(1);
|
||||||
expect(mockClient.setPowerLevel).toHaveBeenCalledWith(
|
expect(mockClient.setPowerLevel).toHaveBeenCalledWith(mockRoom.roomId, defaultMember.userId, changedPowerLevel);
|
||||||
mockRoom.roomId,
|
|
||||||
defaultMember.userId,
|
|
||||||
changedPowerLevel,
|
|
||||||
powerLevelEvent,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ describe("createRoom", () => {
|
|||||||
// widget should be immutable for admins
|
// widget should be immutable for admins
|
||||||
expect(widgetPower).toBeGreaterThan(100);
|
expect(widgetPower).toBeGreaterThan(100);
|
||||||
// and we should have been reset back to admin
|
// and we should have been reset back to admin
|
||||||
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100, null);
|
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sets up Element video rooms correctly", async () => {
|
it("sets up Element video rooms correctly", async () => {
|
||||||
@ -99,7 +99,7 @@ describe("createRoom", () => {
|
|||||||
// call should be immutable for admins
|
// call should be immutable for admins
|
||||||
expect(callPower).toBeGreaterThan(100);
|
expect(callPower).toBeGreaterThan(100);
|
||||||
// and we should have been reset back to admin
|
// and we should have been reset back to admin
|
||||||
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100, null);
|
expect(client.setPowerLevel).toHaveBeenCalledWith(roomId, userId, 100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("doesn't create calls in non-video-rooms", async () => {
|
it("doesn't create calls in non-video-rooms", async () => {
|
||||||
|
@ -14,9 +14,11 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { Room } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { VoiceBroadcastPreview } from "../../../../src/stores/room-list/previews/VoiceBroadcastPreview";
|
import { VoiceBroadcastPreview } from "../../../../src/stores/room-list/previews/VoiceBroadcastPreview";
|
||||||
import { VoiceBroadcastInfoState } from "../../../../src/voice-broadcast";
|
import { VoiceBroadcastInfoState } from "../../../../src/voice-broadcast";
|
||||||
import { mkEvent } from "../../../test-utils";
|
import { mkEvent, stubClient } from "../../../test-utils";
|
||||||
import { mkVoiceBroadcastInfoStateEvent } from "../../../voice-broadcast/utils/test-utils";
|
import { mkVoiceBroadcastInfoStateEvent } from "../../../voice-broadcast/utils/test-utils";
|
||||||
|
|
||||||
describe("VoiceBroadcastPreview.getTextFor", () => {
|
describe("VoiceBroadcastPreview.getTextFor", () => {
|
||||||
@ -51,7 +53,10 @@ describe("VoiceBroadcastPreview.getTextFor", () => {
|
|||||||
|
|
||||||
it("when passing a redacted broadcast stopped event, it should return null", () => {
|
it("when passing a redacted broadcast stopped event, it should return null", () => {
|
||||||
const event = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Stopped, userId, deviceId);
|
const event = mkVoiceBroadcastInfoStateEvent(roomId, VoiceBroadcastInfoState.Stopped, userId, deviceId);
|
||||||
event.makeRedacted(mkEvent({ event: true, content: {}, user: userId, type: "m.room.redaction" }));
|
event.makeRedacted(
|
||||||
|
mkEvent({ event: true, content: {}, user: userId, type: "m.room.redaction" }),
|
||||||
|
new Room(roomId, stubClient(), userId),
|
||||||
|
);
|
||||||
expect(preview.getTextFor(event)).toBeNull();
|
expect(preview.getTextFor(event)).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -73,7 +73,10 @@ describe("EventUtils", () => {
|
|||||||
type: EventType.RoomMessage,
|
type: EventType.RoomMessage,
|
||||||
sender: userId,
|
sender: userId,
|
||||||
});
|
});
|
||||||
redactedEvent.makeRedacted(redactedEvent);
|
redactedEvent.makeRedacted(
|
||||||
|
redactedEvent,
|
||||||
|
new Room(redactedEvent.getRoomId()!, mockClient, mockClient.getUserId()!),
|
||||||
|
);
|
||||||
|
|
||||||
const stateEvent = new MatrixEvent({
|
const stateEvent = new MatrixEvent({
|
||||||
type: EventType.RoomTopic,
|
type: EventType.RoomTopic,
|
||||||
|
@ -14,10 +14,10 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
|
import { EventType, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
|
||||||
|
|
||||||
import { shouldDisplayAsBeaconTile } from "../../../src/utils/beacon/timeline";
|
import { shouldDisplayAsBeaconTile } from "../../../src/utils/beacon/timeline";
|
||||||
import { makeBeaconInfoEvent } from "../../test-utils";
|
import { makeBeaconInfoEvent, stubClient } from "../../test-utils";
|
||||||
|
|
||||||
describe("shouldDisplayAsBeaconTile", () => {
|
describe("shouldDisplayAsBeaconTile", () => {
|
||||||
const userId = "@user:server";
|
const userId = "@user:server";
|
||||||
@ -26,7 +26,7 @@ describe("shouldDisplayAsBeaconTile", () => {
|
|||||||
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
const notLiveBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
||||||
const memberEvent = new MatrixEvent({ type: EventType.RoomMember });
|
const memberEvent = new MatrixEvent({ type: EventType.RoomMember });
|
||||||
const redactedBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
const redactedBeacon = makeBeaconInfoEvent(userId, roomId, { isLive: false });
|
||||||
redactedBeacon.makeRedacted(redactedBeacon);
|
redactedBeacon.makeRedacted(redactedBeacon, new Room(roomId, stubClient(), userId));
|
||||||
|
|
||||||
it("returns true for a beacon with live property set to true", () => {
|
it("returns true for a beacon with live property set to true", () => {
|
||||||
expect(shouldDisplayAsBeaconTile(liveBeacon)).toBe(true);
|
expect(shouldDisplayAsBeaconTile(liveBeacon)).toBe(true);
|
||||||
|
@ -454,7 +454,7 @@ describe("VoiceBroadcastPlayback", () => {
|
|||||||
|
|
||||||
describe("and the info event is deleted", () => {
|
describe("and the info event is deleted", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
infoEvent.makeRedacted(new MatrixEvent({}));
|
infoEvent.makeRedacted(new MatrixEvent({}), room);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should stop and destroy the playback", () => {
|
it("should stop and destroy the playback", () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user