Skip to content

Commit

Permalink
Merge pull request #1841 from matrix-org/travis/fsdk/fix-delete
Browse files Browse the repository at this point in the history
Fix conditional on returning file tree spaces
  • Loading branch information
turt2live authored Aug 11, 2021
2 parents 946dcd0 + 4e2ee3b commit 696b3ef
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions spec/unit/matrix-client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -270,9 +271,33 @@ 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 = {
getMyMembership: () => "join",
currentState: {
getStateEvents: (eventType, stateKey) => {
if (eventType === EventType.RoomCreate) {
Expand Down Expand Up @@ -307,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) {
Expand Down
2 changes: 1 addition & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 696b3ef

Please sign in to comment.