diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index e77a3d5e8..404f7fcd7 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -28,7 +28,6 @@ import { UNSTABLE_MSC3088_ENABLED, UNSTABLE_MSC3088_PURPOSE, UNSTABLE_MSC3089_TREE_SUBTYPE, - MSC3912_RELATION_BASED_REDACTIONS_PROP, } from "../../src/@types/event"; import { MEGOLM_ALGORITHM } from "../../src/crypto/olmlib"; import { Crypto } from "../../src/crypto"; @@ -181,9 +180,7 @@ describe("MatrixClient", function () { data: SYNC_DATA, }; - const unstableFeatures: Record = { - "org.matrix.msc3440.stable": true, - }; + let unstableFeatures: Record = {}; // items are popped off when processed and block if no items left. let httpLookups: HttpLookup[] = []; @@ -342,6 +339,12 @@ describe("MatrixClient", function () { store.getClientOptions = jest.fn().mockReturnValue(Promise.resolve(null)); store.storeClientOptions = jest.fn().mockReturnValue(Promise.resolve(null)); store.isNewlyCreated = jest.fn().mockReturnValue(Promise.resolve(true)); + + // set unstableFeatures to a defined state before each test + unstableFeatures = { + "org.matrix.msc3440.stable": true, + }; + makeClient(); // set reasonable working defaults @@ -1373,10 +1376,10 @@ describe("MatrixClient", function () { await client.redactEvent(roomId, eventId, txnId, { reason }); }); - describe("when calling with with_relations", () => { + describe("when calling with 'with_rel_types'", () => { const eventId = "$event42:example.org"; - it("should raise an error if server has no support for relation based redactions", async () => { + it("should raise an error if the server has no support for relation based redactions", async () => { // load supported features await client.getVersions(); @@ -1384,7 +1387,7 @@ describe("MatrixClient", function () { expect(() => { client.redactEvent(roomId, eventId, txnId, { - with_relations: [RelationType.Reference], + with_rel_types: [RelationType.Reference], }); }).toThrow( new Error( @@ -1394,34 +1397,30 @@ describe("MatrixClient", function () { ); }); - describe("and the server supports relation based redactions (unstable)", () => { - beforeEach(async () => { - unstableFeatures["org.matrix.msc3912"] = true; - // load supported features - await client.getVersions(); - }); + it("and the server has unstable support for relation based redactions, it should send 'org.matrix.msc3912.with_relations' in the request body", async () => { + unstableFeatures["org.matrix.msc3912"] = true; + // load supported features + await client.getVersions(); - it("should send with_relations in the request body", async () => { - const txnId = client.makeTxnId(); + const txnId = client.makeTxnId(); - httpLookups = [ - { - method: "PUT", - path: - `/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}` + - `/${encodeURIComponent(txnId)}`, - expectBody: { - reason: "redaction test", - [MSC3912_RELATION_BASED_REDACTIONS_PROP.unstable!]: [RelationType.Reference], - }, - data: { event_id: eventId }, + httpLookups = [ + { + method: "PUT", + path: + `/rooms/${encodeURIComponent(roomId)}/redact/${encodeURIComponent(eventId)}` + + `/${encodeURIComponent(txnId)}`, + expectBody: { + reason: "redaction test", + ["org.matrix.msc3912.with_relations"]: ["m.reference"], }, - ]; + data: { event_id: eventId }, + }, + ]; - await client.redactEvent(roomId, eventId, txnId, { - reason: "redaction test", - with_relations: [RelationType.Reference], - }); + await client.redactEvent(roomId, eventId, txnId, { + reason: "redaction test", + with_rel_types: [RelationType.Reference], }); }); }); diff --git a/src/@types/event.ts b/src/@types/event.ts index a0eca5cc0..14b5b6402 100644 --- a/src/@types/event.ts +++ b/src/@types/event.ts @@ -168,11 +168,11 @@ export const UNSTABLE_MSC3089_BRANCH = new UnstableValue("m.branch", "org.matrix export const UNSTABLE_MSC2716_MARKER = new UnstableValue("m.room.marker", "org.matrix.msc2716.marker"); /** - * Name of the "with_relations" request property for relation based redactions. + * Name of the request property for relation based redactions. * {@link https://github.com/matrix-org/matrix-spec-proposals/pull/3912} */ export const MSC3912_RELATION_BASED_REDACTIONS_PROP = new UnstableValue( - "with_relations", + "with_rel_types", "org.matrix.msc3912.with_relations", ); diff --git a/src/@types/requests.ts b/src/@types/requests.ts index 364b9f12c..f5b0efbea 100644 --- a/src/@types/requests.ts +++ b/src/@types/requests.ts @@ -48,17 +48,16 @@ export interface IJoinRoomOpts { export interface IRedactOpts { reason?: string; /** - * Whether events related to the redacted event should be redacted. - * * If specified, then any events which relate to the event being redacted with * any of the relationship types listed will also be redacted. + * Provide a "*" list item to tell the server to redact relations of any type. * * Raises an Error if the server does not support it. * Check for server-side support before using this param with * client.canSupport.get(Feature.RelationBasedRedactions). * {@link https://github.com/matrix-org/matrix-spec-proposals/pull/3912} */ - with_relations?: Array; + with_rel_types?: Array; } export interface ISendEventResponse { diff --git a/src/client.ts b/src/client.ts index 3877cb713..d7abcdae9 100644 --- a/src/client.ts +++ b/src/client.ts @@ -4593,10 +4593,10 @@ export class MatrixClient extends TypedEventEmitter