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

Commit 4941327

Browse files
authored
Avoid using deprecated exports & methods from matrix-js-sdk (#12359)
1 parent 11912a0 commit 4941327

24 files changed

+73
-80
lines changed

src/ContentMessages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ limitations under the License.
1919
import {
2020
MatrixClient,
2121
MsgType,
22-
IImageInfo,
2322
HTTPError,
2423
IEventRelation,
2524
ISendEventResponse,
@@ -390,7 +389,7 @@ export default class ContentMessages {
390389
url: string,
391390
roomId: string,
392391
threadId: string | null,
393-
info: IImageInfo,
392+
info: ImageInfo,
394393
text: string,
395394
matrixClient: MatrixClient,
396395
): Promise<ISendEventResponse> {

src/ScalarMessaging.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -612,15 +612,7 @@ async function setBotPower(
612612
});
613613
}
614614
}
615-
await client.setPowerLevel(
616-
roomId,
617-
userId,
618-
level,
619-
new MatrixEvent({
620-
type: "m.room.power_levels",
621-
content: powerLevels,
622-
}),
623-
);
615+
await client.setPowerLevel(roomId, userId, level);
624616
return sendResponse(event, {
625617
success: true,
626618
});

src/components/structures/InteractiveAuth.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React, { createRef } from "react";
1818
import {
1919
AuthType,
2020
IAuthData,
21-
IAuthDict,
21+
AuthDict,
2222
IInputs,
2323
InteractiveAuth,
2424
IStageStatus,
@@ -64,7 +64,7 @@ export interface InteractiveAuthProps<T> {
6464
continueText?: string;
6565
continueKind?: ContinueKind;
6666
// callback
67-
makeRequest(auth: IAuthDict | null): Promise<T>;
67+
makeRequest(auth: AuthDict | null): Promise<T>;
6868
// callback called when the auth process has finished,
6969
// successfully or unsuccessfully.
7070
// @param {boolean} status True if the operation requiring
@@ -213,7 +213,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
213213
);
214214
};
215215

216-
private requestCallback = (auth: IAuthDict | null, background: boolean): Promise<T> => {
216+
private requestCallback = (auth: AuthDict | null, background: boolean): Promise<T> => {
217217
// This wrapper just exists because the js-sdk passes a second
218218
// 'busy' param for backwards compat. This throws the tests off
219219
// so discard it here.
@@ -246,7 +246,7 @@ export default class InteractiveAuthComponent<T> extends React.Component<Interac
246246
this.stageComponent.current?.focus?.();
247247
}
248248

249-
private submitAuthDict = (authData: IAuthDict): void => {
249+
private submitAuthDict = (authData: AuthDict): void => {
250250
this.authLogic.submitAuthDict(authData);
251251
};
252252

src/components/structures/auth/Registration.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
AuthType,
1919
createClient,
2020
IAuthData,
21-
IAuthDict,
21+
AuthDict,
2222
IInputs,
2323
MatrixError,
2424
IRegisterRequestParams,
@@ -478,7 +478,7 @@ export default class Registration extends React.Component<IProps, IState> {
478478
});
479479
};
480480

481-
private makeRegisterRequest = (auth: IAuthDict | null): Promise<RegisterResponse> => {
481+
private makeRegisterRequest = (auth: AuthDict | null): Promise<RegisterResponse> => {
482482
if (!this.state.matrixClient) throw new Error("Matrix client has not yet been loaded");
483483

484484
const registerParams: IRegisterRequestParams = {

src/components/views/auth/InteractiveAuthEntryComponents.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ limitations under the License.
1616

1717
import classNames from "classnames";
1818
import { MatrixClient } from "matrix-js-sdk/src/matrix";
19-
import { AuthType, IAuthDict, IInputs, IStageStatus } from "matrix-js-sdk/src/interactive-auth";
19+
import { AuthType, AuthDict, IInputs, IStageStatus } from "matrix-js-sdk/src/interactive-auth";
2020
import { logger } from "matrix-js-sdk/src/logger";
2121
import React, { ChangeEvent, createRef, FormEvent, Fragment } from "react";
2222

@@ -89,7 +89,7 @@ interface IAuthEntryProps {
8989
// Is the auth logic currently waiting for something to happen?
9090
busy?: boolean;
9191
onPhaseChange: (phase: number) => void;
92-
submitAuthDict: (auth: IAuthDict) => void;
92+
submitAuthDict: (auth: AuthDict) => void;
9393
requestEmailToken?: () => Promise<void>;
9494
fail: (error: Error) => void;
9595
clientSecret: string;

src/components/views/right_panel/UserInfo.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ const MuteToggleButton: React.FC<IBaseRoomProps> = ({
932932
return;
933933
}
934934

935-
cli.setPowerLevel(roomId, target, level, powerLevelEvent)
935+
cli.setPowerLevel(roomId, target, level)
936936
.then(
937937
() => {
938938
// NO-OP; rely on the m.room.member event coming down else we could
@@ -1159,13 +1159,8 @@ export const PowerLevelEditor: React.FC<{
11591159
async (powerLevel: number) => {
11601160
setSelectedPowerLevel(powerLevel);
11611161

1162-
const applyPowerChange = (
1163-
roomId: string,
1164-
target: string,
1165-
powerLevel: number,
1166-
powerLevelEvent: MatrixEvent,
1167-
): Promise<unknown> => {
1168-
return cli.setPowerLevel(roomId, target, powerLevel, powerLevelEvent).then(
1162+
const applyPowerChange = (roomId: string, target: string, powerLevel: number): Promise<unknown> => {
1163+
return cli.setPowerLevel(roomId, target, powerLevel).then(
11691164
function () {
11701165
// NO-OP; rely on the m.room.member event coming down else we could
11711166
// get out of sync if we force setState here!
@@ -1213,7 +1208,7 @@ export const PowerLevelEditor: React.FC<{
12131208
}
12141209
}
12151210

1216-
await applyPowerChange(roomId, target, powerLevel, powerLevelEvent);
1211+
await applyPowerChange(roomId, target, powerLevel);
12171212
},
12181213
[user.roomId, user.userId, cli, room],
12191214
);

src/components/views/settings/AddPrivilegedUsers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const AddPrivilegedUsers: React.FC<AddPrivilegedUsersProps> = ({ room, de
6262
}
6363

6464
try {
65-
await client.setPowerLevel(room.roomId, userIds, powerLevel, powerLevelEvent);
65+
await client.setPowerLevel(room.roomId, userIds, powerLevel);
6666
setSelectedUsers([]);
6767
setPowerLevel(defaultUserLevel);
6868
} catch (error) {

src/components/views/settings/devices/deleteDevices.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import { MatrixClient, MatrixError } from "matrix-js-sdk/src/matrix";
18-
import { IAuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
18+
import { AuthDict, IAuthData } from "matrix-js-sdk/src/interactive-auth";
1919

2020
import { _t } from "../../../../languageHandler";
2121
import Modal from "../../../../Modal";
@@ -25,7 +25,7 @@ import InteractiveAuthDialog from "../../dialogs/InteractiveAuthDialog";
2525

2626
const makeDeleteRequest =
2727
(matrixClient: MatrixClient, deviceIds: string[]) =>
28-
async (auth: IAuthDict | null): Promise<IAuthData> => {
28+
async (auth: AuthDict | null): Promise<IAuthData> => {
2929
return matrixClient.deleteMultipleDevices(deviceIds, auth ?? undefined);
3030
};
3131

src/createRoom.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,15 +347,13 @@ export default async function createRoom(client: MatrixClient, opts: IOpts): Pro
347347
await JitsiCall.create(await room);
348348

349349
// Reset our power level back to admin so that the widget becomes immutable
350-
const plEvent = (await room).currentState.getStateEvents(EventType.RoomPowerLevels, "");
351-
await client.setPowerLevel(roomId, client.getUserId()!, 100, plEvent);
350+
await client.setPowerLevel(roomId, client.getUserId()!, 100);
352351
} else if (opts.roomType === RoomType.UnstableCall) {
353352
// Set up this video room with an Element call
354353
await ElementCall.create(await room);
355354

356355
// Reset our power level back to admin so that the call becomes immutable
357-
const plEvent = (await room).currentState.getStateEvents(EventType.RoomPowerLevels, "");
358-
await client.setPowerLevel(roomId, client.getUserId()!, 100, plEvent);
356+
await client.setPowerLevel(roomId, client.getUserId()!, 100);
359357
}
360358
})
361359
.then(

src/utils/exportUtils/JSONExport.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,7 @@ export default class JSONExporter extends Exporter {
7474
logger.log("Error fetching file: " + err);
7575
}
7676
}
77-
const jsonEvent: any = mxEv.toJSON();
78-
const clearEvent = mxEv.isEncrypted() ? jsonEvent.decrypted : jsonEvent;
79-
return clearEvent;
77+
return mxEv.getEffectiveEvent();
8078
}
8179

8280
protected async createOutput(events: MatrixEvent[]): Promise<string> {

test/ContentMessages-test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ limitations under the License.
1515
*/
1616

1717
import { mocked } from "jest-mock";
18-
import { IImageInfo, ISendEventResponse, MatrixClient, RelationType, UploadResponse } from "matrix-js-sdk/src/matrix";
18+
import { ISendEventResponse, MatrixClient, RelationType, UploadResponse } from "matrix-js-sdk/src/matrix";
19+
import { ImageInfo } from "matrix-js-sdk/src/types";
1920
import { defer } from "matrix-js-sdk/src/utils";
2021
import encrypt, { IEncryptedFile } from "matrix-encrypt-attachment";
2122

@@ -43,7 +44,7 @@ const createElement = document.createElement.bind(document);
4344
describe("ContentMessages", () => {
4445
const stickerUrl = "https://example.com/sticker";
4546
const roomId = "!room:example.com";
46-
const imageInfo = {} as unknown as IImageInfo;
47+
const imageInfo = {} as unknown as ImageInfo;
4748
const text = "test sticker";
4849
let client: MatrixClient;
4950
let contentMessages: ContentMessages;

test/Reply-test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
LocationAssetType,
2323
M_ASSET,
2424
M_POLL_END,
25+
Room,
2526
} from "matrix-js-sdk/src/matrix";
2627

2728
import {
@@ -31,7 +32,7 @@ import {
3132
stripHTMLReply,
3233
stripPlainReply,
3334
} from "../src/utils/Reply";
34-
import { makePollStartEvent, mkEvent } from "./test-utils";
35+
import { makePollStartEvent, mkEvent, stubClient } from "./test-utils";
3536
import { RoomPermalinkCreator } from "../src/utils/permalinks/Permalinks";
3637

3738
function makeTestEvent(type: string, content: IContent): MatrixEvent {
@@ -66,7 +67,7 @@ describe("Reply", () => {
6667
room: "!room1:server",
6768
content: {},
6869
});
69-
event.makeRedacted(event);
70+
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));
7071

7172
expect(getParentEventId(event)).toBeUndefined();
7273
});
@@ -182,7 +183,7 @@ But this is not
182183
room: "!room1:server",
183184
content: {},
184185
});
185-
event.makeRedacted(event);
186+
event.makeRedacted(event, new Room(event.getRoomId()!, stubClient(), event.getSender()!));
186187

187188
expect(shouldDisplayReply(event)).toBe(false);
188189
});

test/TextForEvent-test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ describe("TextForEvent", () => {
419419
});
420420

421421
it("returns correct message for redacted poll start", () => {
422-
pollEvent.makeRedacted(pollEvent);
422+
pollEvent.makeRedacted(pollEvent, new Room(pollEvent.getRoomId()!, mockClient, mockClient.getSafeUserId()));
423423

424424
expect(textForEvent(pollEvent, mockClient)).toEqual("@a: Message deleted");
425425
});
@@ -445,7 +445,10 @@ describe("TextForEvent", () => {
445445
});
446446

447447
it("returns correct message for redacted message", () => {
448-
messageEvent.makeRedacted(messageEvent);
448+
messageEvent.makeRedacted(
449+
messageEvent,
450+
new Room(messageEvent.getRoomId()!, mockClient, mockClient.getSafeUserId()),
451+
);
449452

450453
expect(textForEvent(messageEvent, mockClient)).toEqual("@a: Message deleted");
451454
});

test/Unread-test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe("Unread", () => {
6363
type: EventType.RoomMessage,
6464
sender: aliceId,
6565
});
66-
redactedEvent.makeRedacted(redactedEvent);
66+
redactedEvent.makeRedacted(redactedEvent, new Room(redactedEvent.getRoomId()!, client, aliceId));
6767

6868
beforeEach(() => {
6969
jest.clearAllMocks();
@@ -408,7 +408,7 @@ describe("Unread", () => {
408408
content: {},
409409
});
410410
console.log("Event Id", redactedEvent.getId());
411-
redactedEvent.makeRedacted(redactedEvent);
411+
redactedEvent.makeRedacted(redactedEvent, room);
412412
console.log("Event Id", redactedEvent.getId());
413413
// Only for timeline events.
414414
room.addLiveEvents([redactedEvent]);

test/components/structures/ViewSource-test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ limitations under the License.
1515
*/
1616

1717
import { render } from "@testing-library/react";
18-
import { EventType, MatrixEvent } from "matrix-js-sdk/src/matrix";
18+
import { EventType, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
1919
import React from "react";
2020

2121
import ViewSource from "../../../src/components/structures/ViewSource";
@@ -43,7 +43,7 @@ describe("ViewSource", () => {
4343
content: {},
4444
state_key: undefined,
4545
});
46-
redactedMessageEvent.makeRedacted(redactionEvent);
46+
redactedMessageEvent.makeRedacted(redactionEvent, new Room(ROOM_ID, stubClient(), SENDER));
4747
});
4848

4949
beforeEach(stubClient);

test/components/views/messages/MBeaconBody-test.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
EventType,
2626
Relations,
2727
M_BEACON,
28+
Room,
2829
} from "matrix-js-sdk/src/matrix";
2930

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

305306
const redactionEvent = new MatrixEvent({ type: EventType.RoomRedaction, content: { reason: "test reason" } });
306307

307-
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []) => {
308+
const setupRoomWithBeacon = (beaconInfoEvent: MatrixEvent, locationEvents: MatrixEvent[] = []): Room => {
308309
const room = makeRoomWithStateEvents([beaconInfoEvent], { roomId, mockClient });
309310
const beaconInstance = room.currentState.beacons.get(getBeaconInfoIdentifier(beaconInfoEvent))!;
310311
beaconInstance.addLocations(locationEvents);
312+
return room;
311313
};
312314
const mockGetRelationsForEvent = (locationEvents: MatrixEvent[] = []) => {
313315
const relations = new Relations(RelationType.Reference, M_BEACON.name, mockClient);
@@ -320,12 +322,12 @@ describe("<MBeaconBody />", () => {
320322

321323
it("does nothing when getRelationsForEvent is falsy", () => {
322324
const { beaconInfoEvent, location1, location2 } = makeEvents();
323-
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
325+
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
324326

325327
getComponent({ mxEvent: beaconInfoEvent });
326328

327329
act(() => {
328-
beaconInfoEvent.makeRedacted(redactionEvent);
330+
beaconInfoEvent.makeRedacted(redactionEvent, room);
329331
});
330332

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

355357
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
356358

357359
act(() => {
358-
beaconInfoEvent.makeRedacted(redactionEvent);
360+
beaconInfoEvent.makeRedacted(redactionEvent, room);
359361
});
360362

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

369371
it("redacts related locations on beacon redaction", async () => {
370372
const { beaconInfoEvent, location1, location2 } = makeEvents();
371-
setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
373+
const room = setupRoomWithBeacon(beaconInfoEvent, [location1, location2]);
372374

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

375377
getComponent({ mxEvent: beaconInfoEvent, getRelationsForEvent });
376378

377379
act(() => {
378-
beaconInfoEvent.makeRedacted(redactionEvent);
380+
beaconInfoEvent.makeRedacted(redactionEvent, room);
379381
});
380382

381383
expect(getRelationsForEvent).toHaveBeenCalledWith(

test/components/views/messages/MPollEndBody-test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe("<MPollEndBody />", () => {
9696
mockClient.relations.mockResolvedValue({
9797
events: [],
9898
});
99-
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.toJSON());
99+
mockClient.fetchRoomEvent.mockResolvedValue(pollStartEvent.getEffectiveEvent());
100100
});
101101

102102
afterEach(() => {

0 commit comments

Comments
 (0)