diff --git a/spec/unit/matrix-client.spec.ts b/spec/unit/matrix-client.spec.ts index fbe8c67d7e7..3fc8cd5274f 100644 --- a/spec/unit/matrix-client.spec.ts +++ b/spec/unit/matrix-client.spec.ts @@ -1297,4 +1297,37 @@ describe("MatrixClient", function() { expect(result!.aliases).toEqual(response.aliases); }); }); + + describe("ignoring invites", () => { + it('stores ignored invites', async function() { + // Mockup account data storage. + const dataStore = new Map(); + client.setAccountData = function(eventType, content) { + dataStore.set(eventType, content); + return Promise.resolve(); + }; + client.getAccountData = function(eventType) { + const data = dataStore.get(eventType); + return new MatrixEvent({ + content: data, + }); + }; + + // Initially, the invite list should be empty but not `null`. + expect(await client.getIgnoredInvites()).toEqual({}); + + // Insert something, we should be able to recover it. + const SAMPLE = { + ignored_rooms: { + "12345": { + ts: Date.now(), + }, + }, + }; + await client.setIgnoredInvites(SAMPLE); + + // Check that it was (mock)stored on the client. + expect(await client.getIgnoredInvites()).toEqual(SAMPLE); + }); + }); }); diff --git a/src/@types/event.ts b/src/@types/event.ts index dac2770ade3..3a68f5378d3 100644 --- a/src/@types/event.ts +++ b/src/@types/event.ts @@ -81,6 +81,7 @@ export enum EventType { PushRules = "m.push_rules", Direct = "m.direct", IgnoredUserList = "m.ignored_user_list", + IgnoredInvites = "org.matrix.msc3840.ignored_invites", // to_device events RoomKey = "m.room_key", diff --git a/src/client.ts b/src/client.ts index 3058bca8658..b35162b11e5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -3424,6 +3424,23 @@ export class MatrixClient extends TypedEventEmitter { + return this.setAccountData(EventType.IgnoredInvites, invites); + } + /** * Join a room. If you have already joined the room, this will no-op. * @param {string} roomIdOrAlias The room ID or room alias to join. @@ -9320,3 +9337,35 @@ export class MatrixClient extends TypedEventEmitter metadata for rooms the user does not wish to be invited to. + */ + readonly ignored_rooms?: Record; +}