Skip to content

Commit 696b3ef

Browse files
authored
Merge pull request #1841 from matrix-org/travis/fsdk/fix-delete
Fix conditional on returning file tree spaces
2 parents 946dcd0 + 4e2ee3b commit 696b3ef

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

spec/unit/matrix-client.spec.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ describe("MatrixClient", function() {
237237
it("should get (unstable) file trees with valid state", async () => {
238238
const roomId = "!room:example.org";
239239
const mockRoom = {
240+
getMyMembership: () => "join",
240241
currentState: {
241242
getStateEvents: (eventType, stateKey) => {
242243
if (eventType === EventType.RoomCreate) {
@@ -270,9 +271,33 @@ describe("MatrixClient", function() {
270271
expect(tree.room).toBe(mockRoom);
271272
});
272273

274+
it("should not get (unstable) file trees if not joined", async () => {
275+
const roomId = "!room:example.org";
276+
const mockRoom = {
277+
getMyMembership: () => "leave", // "not join"
278+
};
279+
client.getRoom = (getRoomId) => {
280+
expect(getRoomId).toEqual(roomId);
281+
return mockRoom;
282+
};
283+
const tree = client.unstableGetFileTreeSpace(roomId);
284+
expect(tree).toBeFalsy();
285+
});
286+
287+
it("should not get (unstable) file trees for unknown rooms", async () => {
288+
const roomId = "!room:example.org";
289+
client.getRoom = (getRoomId) => {
290+
expect(getRoomId).toEqual(roomId);
291+
return null; // imply unknown
292+
};
293+
const tree = client.unstableGetFileTreeSpace(roomId);
294+
expect(tree).toBeFalsy();
295+
});
296+
273297
it("should not get (unstable) file trees with invalid create contents", async () => {
274298
const roomId = "!room:example.org";
275299
const mockRoom = {
300+
getMyMembership: () => "join",
276301
currentState: {
277302
getStateEvents: (eventType, stateKey) => {
278303
if (eventType === EventType.RoomCreate) {
@@ -307,6 +332,7 @@ describe("MatrixClient", function() {
307332
it("should not get (unstable) file trees with invalid purpose/subtype contents", async () => {
308333
const roomId = "!room:example.org";
309334
const mockRoom = {
335+
getMyMembership: () => "join",
310336
currentState: {
311337
getStateEvents: (eventType, stateKey) => {
312338
if (eventType === EventType.RoomCreate) {

src/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8060,7 +8060,7 @@ export class MatrixClient extends EventEmitter {
80608060
*/
80618061
public unstableGetFileTreeSpace(roomId: string): MSC3089TreeSpace {
80628062
const room = this.getRoom(roomId);
8063-
if (!room) return null;
8063+
if (room?.getMyMembership() !== 'join') return null;
80648064

80658065
const createEvent = room.currentState.getStateEvents(EventType.RoomCreate, "");
80668066
const purposeEvent = room.currentState.getStateEvents(

0 commit comments

Comments
 (0)