Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Avoid using deprecated exports & methods from matrix-js-sdk #12359

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/ContentMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ limitations under the License.
import {
MatrixClient,
MsgType,
IImageInfo,
HTTPError,
IEventRelation,
ISendEventResponse,
Expand Down Expand Up @@ -390,7 +389,7 @@ export default class ContentMessages {
url: string,
roomId: string,
threadId: string | null,
info: IImageInfo,
info: ImageInfo,
text: string,
matrixClient: MatrixClient,
): Promise<ISendEventResponse> {
Expand Down
10 changes: 1 addition & 9 deletions src/ScalarMessaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,15 +608,7 @@ async function setBotPower(
});
}
}
await client.setPowerLevel(
roomId,
userId,
level,
new MatrixEvent({
type: "m.room.power_levels",
content: powerLevels,
}),
);
await client.setPowerLevel(roomId, userId, level);
return sendResponse(event, {
success: true,
});
Expand Down
8 changes: 4 additions & 4 deletions src/components/structures/InteractiveAuth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import React, { createRef } from "react";
import {
AuthType,
IAuthData,
IAuthDict,
AuthDict,
IInputs,
InteractiveAuth,
IStageStatus,
Expand Down Expand Up @@ -64,7 +64,7 @@ export interface InteractiveAuthProps<T> {
continueText?: string;
continueKind?: ContinueKind;
// callback
makeRequest(auth: IAuthDict | null): Promise<T>;
makeRequest(auth: AuthDict | null): Promise<T>;
// callback called when the auth process has finished,
// successfully or unsuccessfully.
// @param {boolean} status True if the operation requiring
Expand Down Expand Up @@ -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
// 'busy' param for backwards compat. This throws the tests off
// so discard it here.
Expand Down Expand Up @@ -246,7 +246,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
this.stageComponent.current?.focus?.();
}

private submitAuthDict = (authData: IAuthDict): void => {
private submitAuthDict = (authData: AuthDict): void => {
this.authLogic.submitAuthDict(authData);
};

Expand Down
4 changes: 2 additions & 2 deletions src/components/structures/auth/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
AuthType,
createClient,
IAuthData,
IAuthDict,
AuthDict,
IInputs,
MatrixError,
IRegisterRequestParams,
Expand Down Expand Up @@ -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");

const registerParams: IRegisterRequestParams = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ limitations under the License.

import classNames from "classnames";
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 React, { ChangeEvent, createRef, FormEvent, Fragment } from "react";

Expand Down Expand Up @@ -89,7 +89,7 @@ interface IAuthEntryProps {
// Is the auth logic currently waiting for something to happen?
busy?: boolean;
onPhaseChange: (phase: number) => void;
submitAuthDict: (auth: IAuthDict) => void;
submitAuthDict: (auth: AuthDict) => void;
requestEmailToken?: () => Promise<void>;
fail: (error: Error) => void;
clientSecret: string;
Expand Down
13 changes: 4 additions & 9 deletions src/components/views/right_panel/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ const MuteToggleButton: React.FC<IBaseRoomProps> = ({
return;
}

cli.setPowerLevel(roomId, target, level, powerLevelEvent)
cli.setPowerLevel(roomId, target, level)
.then(
() => {
// NO-OP; rely on the m.room.member event coming down else we could
Expand Down Expand Up @@ -1158,13 +1158,8 @@ export const PowerLevelEditor: React.FC<{
async (powerLevel: number) => {
setSelectedPowerLevel(powerLevel);

const applyPowerChange = (
roomId: string,
target: string,
powerLevel: number,
powerLevelEvent: MatrixEvent,
): Promise<unknown> => {
return cli.setPowerLevel(roomId, target, powerLevel, powerLevelEvent).then(
const applyPowerChange = (roomId: string, target: string, powerLevel: number): Promise<unknown> => {
return cli.setPowerLevel(roomId, target, powerLevel).then(
function () {
// NO-OP; rely on the m.room.member event coming down else we could
// get out of sync if we force setState here!
Expand Down Expand Up @@ -1212,7 +1207,7 @@ export const PowerLevelEditor: React.FC<{
}
}

await applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
await applyPowerChange(roomId, target, powerLevel);
},
[user.roomId, user.userId, cli, room],
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/views/settings/AddPrivilegedUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const AddPrivilegedUsers: React.FC<AddPrivilegedUsersProps> = ({ room, de
}

try {
await client.setPowerLevel(room.roomId, userIds, powerLevel, powerLevelEvent);
await client.setPowerLevel(room.roomId, userIds, powerLevel);
setSelectedUsers([]);
setPowerLevel(defaultUserLevel);
} catch (error) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/views/settings/devices/deleteDevices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

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 Modal from "../../../../Modal";
Expand All @@ -25,7 +25,7 @@ import InteractiveAuthDialog from "../../dialogs/InteractiveAuthDialog";

const makeDeleteRequest =
(matrixClient: MatrixClient, deviceIds: string[]) =>
async (auth: IAuthDict | null): Promise<IAuthData> => {
async (auth: AuthDict | null): Promise<IAuthData> => {
return matrixClient.deleteMultipleDevices(deviceIds, auth ?? undefined);
};

Expand Down
6 changes: 2 additions & 4 deletions src/createRoom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,15 +347,13 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro
await JitsiCall.create(await room);

// 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, plEvent);
await client.setPowerLevel(roomId, client.getUserId()!, 100);
} else if (opts.roomType === RoomType.UnstableCall) {
// Set up this video room with an Element call
await ElementCall.create(await room);

// 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, plEvent);
await client.setPowerLevel(roomId, client.getUserId()!, 100);
}
})
.then(
Expand Down
4 changes: 1 addition & 3 deletions src/utils/exportUtils/JSONExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ export default class JSONExporter extends Exporter {
logger.log("Error fetching file: " + err);
}
}
const jsonEvent: any = mxEv.toJSON();
const clearEvent = mxEv.isEncrypted() ? jsonEvent.decrypted : jsonEvent;
return clearEvent;
return mxEv.getEffectiveEvent();
}

protected async createOutput(events: MatrixEvent[]): Promise<string> {
Expand Down
5 changes: 3 additions & 2 deletions test/ContentMessages-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ limitations under the License.
*/

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 encrypt, { IEncryptedFile } from "matrix-encrypt-attachment";

Expand Down Expand Up @@ -43,7 +44,7 @@ const createElement = document.createElement.bind(document);
describe("ContentMessages", () => {
const stickerUrl = "https://example.com/sticker";
const roomId = "!room:example.com";
const imageInfo = {} as unknown as IImageInfo;
const imageInfo = {} as unknown as ImageInfo;
const text = "test sticker";
let client: MatrixClient;
let contentMessages: ContentMessages;
Expand Down
7 changes: 4 additions & 3 deletions test/Reply-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
LocationAssetType,
M_ASSET,
M_POLL_END,
Room,
} from "matrix-js-sdk/src/matrix";

import {
Expand All @@ -31,7 +32,7 @@ import {
stripHTMLReply,
stripPlainReply,
} from "../src/utils/Reply";
import { makePollStartEvent, mkEvent } from "./test-utils";
import { makePollStartEvent, mkEvent, stubClient } from "./test-utils";
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";

function makeTestEvent(type: string, content: IContent): MatrixEvent {
Expand Down Expand Up @@ -66,7 +67,7 @@ describe("Reply", () => {
room: "!room1:server",
content: {},
});
event.makeRedacted(event);
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));

expect(getParentEventId(event)).toBeUndefined();
});
Expand Down Expand Up @@ -182,7 +183,7 @@ But this is not
room: "!room1:server",
content: {},
});
event.makeRedacted(event);
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));

expect(shouldDisplayReply(event)).toBe(false);
});
Expand Down
7 changes: 5 additions & 2 deletions test/TextForEvent-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ describe("TextForEvent", () => {
});

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");
});
Expand All @@ -444,7 +444,10 @@ describe("TextForEvent", () => {
});

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");
});
Expand Down
4 changes: 2 additions & 2 deletions test/Unread-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe("Unread", () => {
type: EventType.RoomMessage,
sender: aliceId,
});
redactedEvent.makeRedacted(redactedEvent);
redactedEvent.makeRedacted(redactedEvent, new Room(redactedEvent.getRoomId()!, client, aliceId));

beforeEach(() => {
jest.clearAllMocks();
Expand Down Expand Up @@ -408,7 +408,7 @@ describe("Unread", () => {
content: {},
});
console.log("Event Id", redactedEvent.getId());
redactedEvent.makeRedacted(redactedEvent);
redactedEvent.makeRedacted(redactedEvent, room);
console.log("Event Id", redactedEvent.getId());
// Only for timeline events.
room.addLiveEvents([redactedEvent]);
Expand Down
4 changes: 2 additions & 2 deletions test/components/structures/ViewSource-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ limitations under the License.
*/

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 ViewSource from "../../../src/components/structures/ViewSource";
Expand Down Expand Up @@ -43,7 +43,7 @@ describe("ViewSource", () => {
content: {},
state_key: undefined,
});
redactedMessageEvent.makeRedacted(redactionEvent);
redactedMessageEvent.makeRedacted(redactionEvent, new Room(ROOM_ID, stubClient(), SENDER));
});

beforeEach(stubClient);
Expand Down
16 changes: 9 additions & 7 deletions test/components/views/messages/MBeaconBody-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
EventType,
Relations,
M_BEACON,
Room,
} from "matrix-js-sdk/src/matrix";

import MBeaconBody from "../../../../src/components/views/messages/MBeaconBody";
Expand Down Expand Up @@ -304,10 +305,11 @@ describe("<MBeaconBody />", () => {

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 beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent))!;
beaconInstance.addLocations(locationEvents);
return room;
};
const mockGetRelationsForEvent = (locationEvents: MatrixEvent[] = []) => {
const relations = new Relations(RelationType.Reference, M_BEACON.name, mockClient);
Expand All @@ -320,12 +322,12 @@ describe("<MBeaconBody />", () => {

it("does nothing when getRelationsForEvent is falsy", () => {
const { beaconInfoEvent, location1, location2 } = makeEvents();
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);

getComponent({ mxEvent: beaconInfoEvent });

act(() => {
beaconInfoEvent.makeRedacted(redactionEvent);
beaconInfoEvent.makeRedacted(redactionEvent, room);
});

// no error, no redactions
Expand All @@ -349,13 +351,13 @@ describe("<MBeaconBody />", () => {
it("does nothing when beacon has no related locations", async () => {
const { beaconInfoEvent } = makeEvents();
// no locations
setupRoomWithBeacon(beaconInfoEvent, []);
const room = setupRoomWithBeacon(beaconInfoEvent, []);
const getRelationsForEvent = await mockGetRelationsForEvent();

getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });

act(() => {
beaconInfoEvent.makeRedacted(redactionEvent);
beaconInfoEvent.makeRedacted(redactionEvent, room);
});

expect(getRelationsForEvent).toHaveBeenCalledWith(
Expand All @@ -368,14 +370,14 @@ describe("<MBeaconBody />", () => {

it("redacts related locations on beacon redaction", async () => {
const { beaconInfoEvent, location1, location2 } = makeEvents();
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);

const getRelationsForEvent = await mockGetRelationsForEvent([location1, location2]);

getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });

act(() => {
beaconInfoEvent.makeRedacted(redactionEvent);
beaconInfoEvent.makeRedacted(redactionEvent, room);
});

expect(getRelationsForEvent).toHaveBeenCalledWith(
Expand Down
2 changes: 1 addition & 1 deletion test/components/views/messages/MPollEndBody-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ describe("<MPollEndBody />", () => {
mockClient.relations.mockResolvedValue({
events: [],
});
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.toJSON());
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.getEffectiveEvent());
});

afterEach(() => {
Expand Down
Loading
Loading