From 7c876251575ebe0b17b97cd25ef7fe6308bca5de Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 28 May 2024 09:12:55 +0100 Subject: [PATCH] Remove more deprecated methods, fields, and exports (#4217) --- spec/integ/crypto/megolm-backup.spec.ts | 4 +- spec/integ/matrix-client-methods.spec.ts | 24 ------ .../integ/matrix-client-room-timeline.spec.ts | 2 +- spec/test-utils/test-utils.ts | 6 +- spec/unit/autodiscovery.spec.ts | 2 +- spec/unit/event-timeline-set.spec.ts | 5 -- spec/unit/matrix-client.spec.ts | 1 - spec/unit/room.spec.ts | 23 +----- src/@types/registration.ts | 18 ++--- src/autodiscovery.ts | 5 -- src/client.ts | 38 ++------- src/crypto-api/keybackup.ts | 2 +- src/crypto/index.ts | 28 +++---- src/matrix.ts | 14 ---- src/models/event-timeline-set.ts | 37 +-------- src/models/event-timeline.ts | 23 +----- src/models/event.ts | 21 +---- src/models/room.ts | 78 +------------------ src/rust-crypto/rust-crypto.ts | 2 +- src/sync-accumulator.ts | 4 +- src/utils.ts | 7 +- 21 files changed, 47 insertions(+), 297 deletions(-) diff --git a/spec/integ/crypto/megolm-backup.spec.ts b/spec/integ/crypto/megolm-backup.spec.ts index 66f7892daa5..eee0eafebc2 100644 --- a/spec/integ/crypto/megolm-backup.spec.ts +++ b/spec/integ/crypto/megolm-backup.spec.ts @@ -21,7 +21,7 @@ import { Mocked } from "jest-mock"; import { createClient, - CryptoApi, + Crypto, CryptoEvent, ICreateClientOpts, IEvent, @@ -310,7 +310,7 @@ describe.each(Object.entries(CRYPTO_BACKENDS))("megolm-keys backup (%s)", (backe }); describe("recover from backup", () => { - let aliceCrypto: CryptoApi; + let aliceCrypto: Crypto.CryptoApi; beforeEach(async () => { fetchMock.get("path:/_matrix/client/v3/room_keys/version", testData.SIGNED_BACKUP_DATA); diff --git a/spec/integ/matrix-client-methods.spec.ts b/spec/integ/matrix-client-methods.spec.ts index a66d41b3dbd..06986652d48 100644 --- a/spec/integ/matrix-client-methods.spec.ts +++ b/spec/integ/matrix-client-methods.spec.ts @@ -1825,7 +1825,6 @@ function withThreadId(event: MatrixEvent, newThreadId: string): MatrixEvent { const buildEventMessageInThread = (root: MatrixEvent) => new MatrixEvent({ - age: 80098509, content: { "algorithm": "m.megolm.v1.aes-sha2", "ciphertext": "ENCRYPTEDSTUFF", @@ -1846,12 +1845,10 @@ const buildEventMessageInThread = (root: MatrixEvent) => sender: "@andybalaam-test1:matrix.org", type: "m.room.encrypted", unsigned: { age: 80098509 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventPollResponseReference = () => new MatrixEvent({ - age: 80098509, content: { "algorithm": "m.megolm.v1.aes-sha2", "ciphertext": "ENCRYPTEDSTUFF", @@ -1869,7 +1866,6 @@ const buildEventPollResponseReference = () => sender: "@andybalaam-test1:matrix.org", type: "m.room.encrypted", unsigned: { age: 80106237 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventReaction = (event: MatrixEvent) => @@ -1909,7 +1905,6 @@ const buildEventRedaction = (event: MatrixEvent) => const buildEventPollStartThreadRoot = () => new MatrixEvent({ - age: 80108647, content: { algorithm: "m.megolm.v1.aes-sha2", ciphertext: "ENCRYPTEDSTUFF", @@ -1923,12 +1918,10 @@ const buildEventPollStartThreadRoot = () => sender: "@andybalaam-test1:matrix.org", type: "m.room.encrypted", unsigned: { age: 80108647 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventReply = (target: MatrixEvent) => new MatrixEvent({ - age: 80098509, content: { "algorithm": "m.megolm.v1.aes-sha2", "ciphertext": "ENCRYPTEDSTUFF", @@ -1947,12 +1940,10 @@ const buildEventReply = (target: MatrixEvent) => sender: "@andybalaam-test1:matrix.org", type: "m.room.encrypted", unsigned: { age: 80098509 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventRoomName = () => new MatrixEvent({ - age: 80123249, content: { name: "1 poll, 1 vote, 1 thread", }, @@ -1963,12 +1954,10 @@ const buildEventRoomName = () => state_key: "", type: "m.room.name", unsigned: { age: 80123249 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventEncryption = () => new MatrixEvent({ - age: 80123383, content: { algorithm: "m.megolm.v1.aes-sha2", }, @@ -1979,12 +1968,10 @@ const buildEventEncryption = () => state_key: "", type: "m.room.encryption", unsigned: { age: 80123383 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventGuestAccess = () => new MatrixEvent({ - age: 80123473, content: { guest_access: "can_join", }, @@ -1995,12 +1982,10 @@ const buildEventGuestAccess = () => state_key: "", type: "m.room.guest_access", unsigned: { age: 80123473 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventHistoryVisibility = () => new MatrixEvent({ - age: 80123556, content: { history_visibility: "shared", }, @@ -2011,12 +1996,10 @@ const buildEventHistoryVisibility = () => state_key: "", type: "m.room.history_visibility", unsigned: { age: 80123556 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventJoinRules = () => new MatrixEvent({ - age: 80123696, content: { join_rule: KnownMembership.Invite, }, @@ -2027,12 +2010,10 @@ const buildEventJoinRules = () => state_key: "", type: "m.room.join_rules", unsigned: { age: 80123696 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventPowerLevels = () => new MatrixEvent({ - age: 80124105, content: { ban: 50, events: { @@ -2063,12 +2044,10 @@ const buildEventPowerLevels = () => state_key: "", type: "m.room.power_levels", unsigned: { age: 80124105 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventMember = () => new MatrixEvent({ - age: 80125279, content: { avatar_url: "mxc://matrix.org/aNtbVcFfwotudypZcHsIcPOc", displayname: "andybalaam-test1", @@ -2081,12 +2060,10 @@ const buildEventMember = () => state_key: "@andybalaam-test1:matrix.org", type: "m.room.member", unsigned: { age: 80125279 }, - user_id: "@andybalaam-test1:matrix.org", }); const buildEventCreate = () => new MatrixEvent({ - age: 80126105, content: { room_version: "6", }, @@ -2097,7 +2074,6 @@ const buildEventCreate = () => state_key: "", type: "m.room.create", unsigned: { age: 80126105 }, - user_id: "@andybalaam-test1:matrix.org", }); function assertObjectContains(obj: Record, expected: any): void { diff --git a/spec/integ/matrix-client-room-timeline.spec.ts b/spec/integ/matrix-client-room-timeline.spec.ts index a5d4c220a95..1d0ed86e0d3 100644 --- a/spec/integ/matrix-client-room-timeline.spec.ts +++ b/spec/integ/matrix-client-room-timeline.spec.ts @@ -333,7 +333,7 @@ describe("MatrixClient room timelines", function () { name: userName, url: "mxc://some/url", }); - oldMshipEvent.prev_content = { + oldMshipEvent.unsigned!.prev_content = { displayname: "Old Alice", avatar_url: undefined, membership: KnownMembership.Join, diff --git a/spec/test-utils/test-utils.ts b/spec/test-utils/test-utils.ts index 965a6a08806..a6cc6445565 100644 --- a/spec/test-utils/test-utils.ts +++ b/spec/test-utils/test-utils.ts @@ -173,8 +173,10 @@ export function mkEvent(opts: IEventOpts & { event?: boolean }, client?: MatrixC room_id: opts.room, sender: opts.sender || opts.user, // opts.user for backwards-compat content: opts.content, - prev_content: opts.prev_content, - unsigned: opts.unsigned || {}, + unsigned: { + ...opts.unsigned, + prev_content: opts.prev_content, + }, event_id: "$" + testEventIndex++ + "-" + Math.random() + "-" + Math.random(), txn_id: "~" + Math.random(), redacts: opts.redacts, diff --git a/spec/unit/autodiscovery.spec.ts b/spec/unit/autodiscovery.spec.ts index ceed8be1f57..e4c7c98b293 100644 --- a/spec/unit/autodiscovery.spec.ts +++ b/spec/unit/autodiscovery.spec.ts @@ -857,7 +857,7 @@ describe("AutoDiscovery", function () { const expected = { "m.homeserver": { state: AutoDiscoveryAction.FAIL_ERROR, - error: AutoDiscovery.ERROR_HOMESERVER_TOO_OLD, + error: AutoDiscovery.ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION, base_url: "https://example.org", }, "m.identity_server": { diff --git a/spec/unit/event-timeline-set.spec.ts b/spec/unit/event-timeline-set.spec.ts index a817127569c..c89ddc4606e 100644 --- a/spec/unit/event-timeline-set.spec.ts +++ b/spec/unit/event-timeline-set.spec.ts @@ -136,11 +136,6 @@ describe("EventTimelineSet", () => { expect(eventsInLiveTimeline.length).toStrictEqual(1); expect(eventsInLiveTimeline[0]).toStrictEqual(duplicateMessageEvent); }); - - it("Make sure legacy overload passing options directly as parameters still works", () => { - expect(() => eventTimelineSet.addLiveEvent(messageEvent, DuplicateStrategy.Replace, false)).not.toThrow(); - expect(() => eventTimelineSet.addLiveEvent(messageEvent, DuplicateStrategy.Ignore, true)).not.toThrow(); - }); }); describe("addEventToTimeline", () => { diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index b83e841fcf6..fa9cd776902 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -1560,7 +1560,6 @@ describe("MatrixClient", function () { }, }, event_id: "$ev1", - user_id: "@alice:matrix.org", }); expect(rootEvent.isThreadRoot).toBe(true); diff --git a/spec/unit/room.spec.ts b/spec/unit/room.spec.ts index 6ca454ef82a..eb90b8bdfa0 100644 --- a/spec/unit/room.spec.ts +++ b/spec/unit/room.spec.ts @@ -22,7 +22,7 @@ import { mocked } from "jest-mock"; import { M_POLL_KIND_DISCLOSED, M_POLL_RESPONSE, M_POLL_START, Optional, PollStartEvent } from "matrix-events-sdk"; import * as utils from "../test-utils/test-utils"; -import { emitPromise } from "../test-utils/test-utils"; +import { emitPromise, IMessageOpts } from "../test-utils/test-utils"; import { Direction, DuplicateStrategy, @@ -54,7 +54,6 @@ import { Crypto } from "../../src/crypto"; import * as threadUtils from "../test-utils/thread"; import { getMockClientWithEventEmitter, mockClientMethodsUser } from "../test-utils/client"; import { logger } from "../../src/logger"; -import { IMessageOpts } from "../test-utils/test-utils"; import { flushPromises } from "../test-utils/flushPromises"; import { KnownMembership } from "../../src/@types/membership"; @@ -339,24 +338,6 @@ describe("Room", function () { }), ]; - it("Make sure legacy overload passing options directly as parameters still works", async () => { - await expect(room.addLiveEvents(events, DuplicateStrategy.Replace, false)).resolves.not.toThrow(); - await expect(room.addLiveEvents(events, DuplicateStrategy.Ignore, true)).resolves.not.toThrow(); - await expect( - // @ts-ignore - room.addLiveEvents(events, "shouldfailbecauseinvalidduplicatestrategy", false), - ).rejects.toThrow(); - }); - - it("should throw if duplicateStrategy isn't 'replace' or 'ignore'", async function () { - return expect( - // @ts-ignore - room.addLiveEvents(events, { - duplicateStrategy: "foo", - }), - ).rejects.toThrow(); - }); - it("should replace a timeline event if dupe strategy is 'replace'", async function () { // make a duplicate const dupe = utils.mkMessage({ @@ -387,7 +368,7 @@ describe("Room", function () { expect(room.timeline[0]).toEqual(events[0]); // @ts-ignore await room.addLiveEvents([dupe], { - duplicateStrategy: "ignore", + duplicateStrategy: DuplicateStrategy.Ignore, }); expect(room.timeline[0]).toEqual(events[0]); }); diff --git a/src/@types/registration.ts b/src/@types/registration.ts index 90fc098e482..7bfb99f7d40 100644 --- a/src/@types/registration.ts +++ b/src/@types/registration.ts @@ -52,21 +52,13 @@ export interface RegisterRequest { */ initial_device_display_name?: string; /** - * @deprecated missing in the spec + * Guest users can also upgrade their account by going through the ordinary register flow, + * but specifying the additional POST parameter guest_access_token containing the guest’s access token. + * They are also required to specify the username parameter to the value of the local part of their username, + * which is otherwise optional. + * @see https://spec.matrix.org/v1.10/client-server-api/#guest-access */ guest_access_token?: string; - /** - * @deprecated missing in the spec - */ - x_show_msisdn?: boolean; - /** - * @deprecated missing in the spec - */ - bind_msisdn?: boolean; - /** - * @deprecated missing in the spec - */ - bind_email?: boolean; } /** diff --git a/src/autodiscovery.ts b/src/autodiscovery.ts index 29dac54bdb7..8f4f196682c 100644 --- a/src/autodiscovery.ts +++ b/src/autodiscovery.ts @@ -43,8 +43,6 @@ export enum AutoDiscoveryError { InvalidJson = "Invalid JSON", UnsupportedHomeserverSpecVersion = "The homeserver does not meet the version requirements", - /** @deprecated Replaced by `UnsupportedHomeserverSpecVersion` */ - HomeserverTooOld = UnsupportedHomeserverSpecVersion, // TODO: Implement when Sydent supports the `/versions` endpoint - https://github.com/matrix-org/sydent/issues/424 //IdentityServerTooOld = "The identity server does not meet the minimum version requirements", } @@ -91,9 +89,6 @@ export class AutoDiscovery { public static readonly ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION = AutoDiscoveryError.UnsupportedHomeserverSpecVersion; - /** @deprecated Replaced by ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION */ - public static readonly ERROR_HOMESERVER_TOO_OLD = AutoDiscovery.ERROR_UNSUPPORTED_HOMESERVER_SPEC_VERSION; - public static readonly ALL_ERRORS = Object.keys(AutoDiscoveryError) as AutoDiscoveryError[]; /** diff --git a/src/client.ts b/src/client.ts index 4200a6154d9..72e28f52916 100644 --- a/src/client.ts +++ b/src/client.ts @@ -1480,13 +1480,6 @@ export class MatrixClient extends TypedEventEmitter { if (!this.crypto) { @@ -3381,7 +3374,7 @@ export class MatrixClient extends TypedEventEmitter { if (!this.crypto) { @@ -7901,16 +7894,10 @@ export class MatrixClient extends TypedEventEmitter { - // backwards compat - if (bindThreepids === true) { - bindThreepids = { email: true }; - } else if (bindThreepids === null || bindThreepids === undefined || bindThreepids === false) { - bindThreepids = {}; - } if (sessionId) { auth.session = sessionId; } @@ -7925,27 +7912,12 @@ export class MatrixClient extends TypedEventEmitter { const publicKeysOnDevice = Boolean(this.crossSigningInfo.getId()); @@ -1167,7 +1167,7 @@ export class Crypto extends TypedEventEmitter { // Delete existing ones @@ -1203,7 +1203,7 @@ export class Crypto extends TypedEventEmitter { await this.backupManager.deleteKeyBackupVersion(version); @@ -1350,7 +1350,7 @@ export class Crypto extends TypedEventEmitter { if (this.backupManager.getKeyBackupEnabled()) { @@ -1372,7 +1372,7 @@ export class Crypto extends TypedEventEmitter { const checkResult = await this.backupManager.checkKeyBackup(); @@ -1589,7 +1589,7 @@ export class Crypto extends TypedEventEmitter { return this.checkUserTrust(userId); @@ -1990,7 +1990,7 @@ export class Crypto extends TypedEventEmitter { if (!this.olmDevice.deviceCurve25519Key) { @@ -2344,7 +2344,7 @@ export class Crypto extends TypedEventEmitter { await this.setDeviceVerification(userId, deviceId, verified); @@ -2353,7 +2353,7 @@ export class Crypto extends TypedEventEmitter { await this.setDeviceVerified(this.userId, deviceId, true); @@ -2789,7 +2789,7 @@ export class Crypto extends TypedEventEmitter { const encryptionInfo = this.getEventEncryptionInfo(event); @@ -4272,7 +4272,7 @@ export class Crypto extends TypedEventEmitter { return this.isRoomEncrypted(roomId); diff --git a/src/matrix.ts b/src/matrix.ts index ed71f7dfcac..793a894e0d0 100644 --- a/src/matrix.ts +++ b/src/matrix.ts @@ -114,20 +114,6 @@ export { LocationAssetType } from "./@types/location"; */ export * as Crypto from "./crypto-api"; -/** - * Backwards compatibility re-export - * @internal - * @deprecated use {@link Crypto.CryptoApi} - */ -export type { CryptoApi } from "./crypto-api"; - -/** - * Backwards compatibility re-export - * @internal - * @deprecated use {@link Crypto.DeviceVerificationStatus} - */ -export { DeviceVerificationStatus } from "./crypto-api"; - let cryptoStoreFactory = (): CryptoStore => new MemoryCryptoStore(); /** diff --git a/src/models/event-timeline-set.ts b/src/models/event-timeline-set.ts index 38d47cd2147..e64d118fdd5 100644 --- a/src/models/event-timeline-set.ts +++ b/src/models/event-timeline-set.ts @@ -592,43 +592,8 @@ export class EventTimelineSet extends TypedEventEmitter { */ private threads = new Map(); - /** - * @deprecated This value is unreliable. It may not contain the last thread. - * Use {@link Room.getLastThread} instead. - */ - public lastThread?: Thread; - /** * A mapping of eventId to all visibility changes to apply * to the event, by chronological order, as per @@ -1382,32 +1376,6 @@ export class Room extends ReadReceipt { } } - /** - * Returns whether there are any devices in the room that are unverified - * - * Note: Callers should first check if crypto is enabled on this device. If it is - * disabled, then we aren't tracking room devices at all, so we can't answer this, and an - * error will be thrown. - * - * @returns the result - * - * @deprecated Not supported under rust crypto. Instead, call {@link Room.getEncryptionTargetMembers}, - * {@link CryptoApi.getUserDeviceInfo}, and {@link CryptoApi.getDeviceVerificationStatus}. - */ - public async hasUnverifiedDevices(): Promise { - if (!this.hasEncryptionStateEvent()) { - return false; - } - const e2eMembers = await this.getEncryptionTargetMembers(); - for (const member of e2eMembers) { - const devices = this.client.getStoredDevicesForUser(member.userId); - if (devices.some((device) => device.isUnverified())) { - return true; - } - } - return false; - } - /** * Return the timeline sets for this room. * @returns array of timeline sets for this room @@ -2458,15 +2426,6 @@ export class Room extends ReadReceipt { // and pass the event through this. thread.addEvents(events, false); - const isNewer = - this.lastThread?.rootEvent && - rootEvent?.localTimestamp && - this.lastThread.rootEvent?.localTimestamp < rootEvent?.localTimestamp; - - if (!this.lastThread || isNewer) { - this.lastThread = thread; - } - // We need to update the thread root events, but the thread may not be ready yet. // If it isn't, it will fire ThreadEvent.Update when it is and we'll call updateThreadRootEvents then. if (this.threadsReady && thread.initialEventsFetched) { @@ -2896,39 +2855,8 @@ export class Room extends ReadReceipt { * @param addLiveEventOptions - addLiveEvent options * @throws If `duplicateStrategy` is not falsey, 'replace' or 'ignore'. */ - public async addLiveEvents(events: MatrixEvent[], addLiveEventOptions?: IAddLiveEventOptions): Promise; - /** - * @deprecated In favor of the overload with `IAddLiveEventOptions` - */ - public async addLiveEvents( - events: MatrixEvent[], - duplicateStrategy?: DuplicateStrategy, - fromCache?: boolean, - ): Promise; - public async addLiveEvents( - events: MatrixEvent[], - duplicateStrategyOrOpts?: DuplicateStrategy | IAddLiveEventOptions, - fromCache = false, - ): Promise { - let duplicateStrategy: DuplicateStrategy | undefined = duplicateStrategyOrOpts as DuplicateStrategy; - let timelineWasEmpty: boolean | undefined = false; - if (typeof duplicateStrategyOrOpts === "object") { - ({ - duplicateStrategy, - fromCache = false, - /* roomState, (not used here) */ - timelineWasEmpty, - } = duplicateStrategyOrOpts); - } else if (duplicateStrategyOrOpts !== undefined) { - // Deprecation warning - // FIXME: Remove after 2023-06-01 (technical debt) - logger.warn( - "Overload deprecated: " + - "`Room.addLiveEvents(events, duplicateStrategy?, fromCache?)` " + - "is deprecated in favor of the overload with `Room.addLiveEvents(events, IAddLiveEventOptions)`", - ); - } - + public async addLiveEvents(events: MatrixEvent[], addLiveEventOptions?: IAddLiveEventOptions): Promise { + const { duplicateStrategy, fromCache, timelineWasEmpty = false } = addLiveEventOptions ?? {}; if (duplicateStrategy && ["replace", "ignore"].indexOf(duplicateStrategy) === -1) { throw new Error("duplicateStrategy MUST be either 'replace' or 'ignore'"); } @@ -3229,7 +3157,7 @@ export class Room extends ReadReceipt { content: strippedEvent.content, event_id: "$fake" + Date.now(), room_id: this.roomId, - user_id: this.myUserId, // technically a lie + sender: this.myUserId, // technically a lie }), ]); } diff --git a/src/rust-crypto/rust-crypto.ts b/src/rust-crypto/rust-crypto.ts index 555ada8b354..8cbfba4b0c5 100644 --- a/src/rust-crypto/rust-crypto.ts +++ b/src/rust-crypto/rust-crypto.ts @@ -865,7 +865,7 @@ export class RustCrypto extends TypedEventEmitter { return this.eventDecryptor.getEncryptionInfoForEvent(event); diff --git a/src/sync-accumulator.ts b/src/sync-accumulator.ts index 67d5e1d6802..eec811577b8 100644 --- a/src/sync-accumulator.ts +++ b/src/sync-accumulator.ts @@ -58,8 +58,6 @@ export interface IRoomEvent extends IMinimalEvent { event_id: string; sender: string; origin_server_ts: number; - /** @deprecated - legacy field */ - age?: number; } export interface IStateEvent extends IRoomEvent { @@ -498,7 +496,7 @@ export class SyncAccumulator { if (transformedEvent.unsigned !== undefined) { transformedEvent.unsigned = Object.assign({}, transformedEvent.unsigned); } - const age = e.unsigned ? e.unsigned.age : e.age; + const age = e.unsigned?.age; if (age !== undefined) transformedEvent._localTs = Date.now() - age; } else { transformedEvent = e; diff --git a/src/utils.ts b/src/utils.ts index 28e867eeda0..f3ad18d5735 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -748,12 +748,7 @@ export function safeSet, K extends keyof O>(obj: O, p } export function noUnsafeEventProps(event: Partial): boolean { - return !( - unsafeProp(event.room_id) || - unsafeProp(event.sender) || - unsafeProp(event.user_id) || - unsafeProp(event.event_id) - ); + return !(unsafeProp(event.room_id) || unsafeProp(event.sender) || unsafeProp(event.event_id)); } export class MapWithDefault extends Map {