From 1f9fab9a0c1ef6c0530f148108bce3372818a1d9 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 11 Aug 2021 15:11:13 -0600 Subject: [PATCH 1/2] Fix conditional on returning file tree spaces If a tree space was deleted then it'll still hold a Room object for us, which is not much help if we're effectively trying to get the joined trees. --- spec/unit/matrix-client.spec.js | 23 +++++++++++++++++++++++ src/client.ts | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index 090ffeed14d..755abfb10ee 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -270,6 +270,29 @@ describe("MatrixClient", function() { expect(tree.room).toBe(mockRoom); }); + it("should not get (unstable) file trees if not joined", async () => { + const roomId = "!room:example.org"; + const mockRoom = { + getMyMembership: () => "leave", // "not join" + }; + client.getRoom = (getRoomId) => { + expect(getRoomId).toEqual(roomId); + return mockRoom; + }; + const tree = client.unstableGetFileTreeSpace(roomId); + expect(tree).toBeFalsy(); + }); + + it("should not get (unstable) file trees for unknown rooms", async () => { + const roomId = "!room:example.org"; + client.getRoom = (getRoomId) => { + expect(getRoomId).toEqual(roomId); + return null; // imply unknown + }; + const tree = client.unstableGetFileTreeSpace(roomId); + expect(tree).toBeFalsy(); + }); + it("should not get (unstable) file trees with invalid create contents", async () => { const roomId = "!room:example.org"; const mockRoom = { diff --git a/src/client.ts b/src/client.ts index 2bcda09e44e..83b484c44e6 100644 --- a/src/client.ts +++ b/src/client.ts @@ -8060,7 +8060,7 @@ export class MatrixClient extends EventEmitter { */ public unstableGetFileTreeSpace(roomId: string): MSC3089TreeSpace { const room = this.getRoom(roomId); - if (!room) return null; + if (room?.getMyMembership() !== 'join') return null; const createEvent = room.currentState.getStateEvents(EventType.RoomCreate, ""); const purposeEvent = room.currentState.getStateEvents( From 4e2ee3b3a817d457d35ca9f487f574a066c679cc Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 11 Aug 2021 15:18:24 -0600 Subject: [PATCH 2/2] It helps to fix the other tests too --- spec/unit/matrix-client.spec.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/unit/matrix-client.spec.js b/spec/unit/matrix-client.spec.js index 755abfb10ee..82e166f67e1 100644 --- a/spec/unit/matrix-client.spec.js +++ b/spec/unit/matrix-client.spec.js @@ -237,6 +237,7 @@ describe("MatrixClient", function() { it("should get (unstable) file trees with valid state", async () => { const roomId = "!room:example.org"; const mockRoom = { + getMyMembership: () => "join", currentState: { getStateEvents: (eventType, stateKey) => { if (eventType === EventType.RoomCreate) { @@ -296,6 +297,7 @@ describe("MatrixClient", function() { it("should not get (unstable) file trees with invalid create contents", async () => { const roomId = "!room:example.org"; const mockRoom = { + getMyMembership: () => "join", currentState: { getStateEvents: (eventType, stateKey) => { if (eventType === EventType.RoomCreate) { @@ -330,6 +332,7 @@ describe("MatrixClient", function() { it("should not get (unstable) file trees with invalid purpose/subtype contents", async () => { const roomId = "!room:example.org"; const mockRoom = { + getMyMembership: () => "join", currentState: { getStateEvents: (eventType, stateKey) => { if (eventType === EventType.RoomCreate) {