1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-31 15:24:23 +03:00

Pre-lint format

This commit is contained in:
Travis Ralston
2021-06-09 21:55:06 -06:00
parent b3a11030f2
commit bcccc909c5
4 changed files with 34 additions and 34 deletions

View File

@ -128,10 +128,10 @@ describe("MSC3089Branch", () => {
it('should be able to return event information', async () => { it('should be able to return event information', async () => {
const mxcLatter = "example.org/file"; const mxcLatter = "example.org/file";
const fileContent = {isFile: "not quite", url: "mxc://" + mxcLatter}; const fileContent = { isFile: "not quite", url: "mxc://" + mxcLatter };
const eventsArr = [ const eventsArr = [
{getId: () => "$not-file", getContent: () => ({})}, { getId: () => "$not-file", getContent: () => ({}) },
{getId: () => fileEventId, getContent: () => ({file: fileContent})}, { getId: () => fileEventId, getContent: () => ({ file: fileContent }) },
]; ];
client.getEventTimeline = () => Promise.resolve({ client.getEventTimeline = () => Promise.resolve({
getEvents: () => eventsArr, getEvents: () => eventsArr,

View File

@ -21,7 +21,7 @@ import { EventType, MsgType, UNSTABLE_MSC3089_BRANCH, UNSTABLE_MSC3089_LEAF } fr
import { import {
DEFAULT_TREE_POWER_LEVELS_TEMPLATE, DEFAULT_TREE_POWER_LEVELS_TEMPLATE,
MSC3089TreeSpace, MSC3089TreeSpace,
TreePermissions TreePermissions,
} from "../../../src/models/MSC3089TreeSpace"; } from "../../../src/models/MSC3089TreeSpace";
import { DEFAULT_ALPHABET } from "../../../src/utils"; import { DEFAULT_ALPHABET } from "../../../src/utils";
import { MockBlob } from "../../MockBlob"; import { MockBlob } from "../../MockBlob";
@ -87,7 +87,7 @@ describe("MSC3089TreeSpace", () => {
expect(stateRoomId).toEqual(roomId); expect(stateRoomId).toEqual(roomId);
expect(eventType).toEqual(EventType.RoomName); expect(eventType).toEqual(EventType.RoomName);
expect(stateKey).toEqual(""); expect(stateKey).toEqual("");
expect(content).toMatchObject({name: newName}); expect(content).toMatchObject({ name: newName });
return Promise.resolve(); return Promise.resolve();
}); });
client.sendStateEvent = fn; client.sendStateEvent = fn;
@ -208,7 +208,7 @@ describe("MSC3089TreeSpace", () => {
expect(eventType).toEqual(EventType.SpaceChild); expect(eventType).toEqual(EventType.SpaceChild);
expect(stateKey).toEqual(subspaceId); expect(stateKey).toEqual(subspaceId);
} }
expect(content).toMatchObject({via: [domain]}); expect(content).toMatchObject({ via: [domain] });
// return value not used // return value not used
}); });
@ -223,7 +223,7 @@ describe("MSC3089TreeSpace", () => {
expect(createFn).toHaveBeenCalledTimes(1); expect(createFn).toHaveBeenCalledTimes(1);
expect(sendStateFn).toHaveBeenCalledTimes(2); expect(sendStateFn).toHaveBeenCalledTimes(2);
const content = expect.objectContaining({via: [domain]}); const content = expect.objectContaining({ via: [domain] });
expect(sendStateFn).toHaveBeenCalledWith(subspaceId, EventType.SpaceParent, content, tree.roomId); expect(sendStateFn).toHaveBeenCalledWith(subspaceId, EventType.SpaceParent, content, tree.roomId);
expect(sendStateFn).toHaveBeenCalledWith(tree.roomId, EventType.SpaceChild, content, subspaceId); expect(sendStateFn).toHaveBeenCalledWith(tree.roomId, EventType.SpaceChild, content, subspaceId);
}); });
@ -238,9 +238,9 @@ describe("MSC3089TreeSpace", () => {
expect(stateKey).toBeUndefined(); expect(stateKey).toBeUndefined();
return [ return [
// Partial implementations of Room // Partial implementations of Room
{getStateKey: () => firstChildRoom}, { getStateKey: () => firstChildRoom },
{getStateKey: () => secondChildRoom}, { getStateKey: () => secondChildRoom },
{getStateKey: () => thirdChildRoom}, { getStateKey: () => thirdChildRoom },
]; ];
}, },
}; };
@ -270,9 +270,9 @@ describe("MSC3089TreeSpace", () => {
client.getRoom = () => ({} as Room); // to appease the TreeSpace constructor client.getRoom = () => ({} as Room); // to appease the TreeSpace constructor
// Only mocking used API // Only mocking used API
const firstSubdirectory = {roomId: "!first:example.org"} as any as MSC3089TreeSpace; const firstSubdirectory = { roomId: "!first:example.org" } as any as MSC3089TreeSpace;
const searchedSubdirectory = {roomId: "!find_me:example.org"} as any as MSC3089TreeSpace; const searchedSubdirectory = { roomId: "!find_me:example.org" } as any as MSC3089TreeSpace;
const thirdSubdirectory = {roomId: "!third:example.org"} as any as MSC3089TreeSpace; const thirdSubdirectory = { roomId: "!third:example.org" } as any as MSC3089TreeSpace;
tree.getDirectories = () => [firstSubdirectory, searchedSubdirectory, thirdSubdirectory]; tree.getDirectories = () => [firstSubdirectory, searchedSubdirectory, thirdSubdirectory];
let result = tree.getDirectory(searchedSubdirectory.roomId); let result = tree.getDirectory(searchedSubdirectory.roomId);
@ -284,10 +284,10 @@ describe("MSC3089TreeSpace", () => {
it('should be able to delete itself', async () => { it('should be able to delete itself', async () => {
const delete1 = jest.fn().mockImplementation(() => Promise.resolve()); const delete1 = jest.fn().mockImplementation(() => Promise.resolve());
const subdir1 = {delete: delete1} as any as MSC3089TreeSpace; // mock tested bits const subdir1 = { delete: delete1 } as any as MSC3089TreeSpace; // mock tested bits
const delete2 = jest.fn().mockImplementation(() => Promise.resolve()); const delete2 = jest.fn().mockImplementation(() => Promise.resolve());
const subdir2 = {delete: delete2} as any as MSC3089TreeSpace; // mock tested bits const subdir2 = { delete: delete2 } as any as MSC3089TreeSpace; // mock tested bits
const joinMemberId = "@join:example.org"; const joinMemberId = "@join:example.org";
const knockMemberId = "@knock:example.org"; const knockMemberId = "@knock:example.org";
@ -303,14 +303,14 @@ describe("MSC3089TreeSpace", () => {
expect(stateKey).toBeUndefined(); expect(stateKey).toBeUndefined();
return [ return [
// Partial implementations // Partial implementations
{getContent: () => ({membership: "join"}), getStateKey: () => joinMemberId}, { getContent: () => ({ membership: "join" }), getStateKey: () => joinMemberId },
{getContent: () => ({membership: "knock"}), getStateKey: () => knockMemberId}, { getContent: () => ({ membership: "knock" }), getStateKey: () => knockMemberId },
{getContent: () => ({membership: "invite"}), getStateKey: () => inviteMemberId}, { getContent: () => ({ membership: "invite" }), getStateKey: () => inviteMemberId },
{getContent: () => ({membership: "leave"}), getStateKey: () => leaveMemberId}, { getContent: () => ({ membership: "leave" }), getStateKey: () => leaveMemberId },
{getContent: () => ({membership: "ban"}), getStateKey: () => banMemberId}, { getContent: () => ({ membership: "ban" }), getStateKey: () => banMemberId },
// ensure we don't kick ourselves // ensure we don't kick ourselves
{getContent: () => ({membership: "join"}), getStateKey: () => selfUserId}, { getContent: () => ({ membership: "join" }), getStateKey: () => selfUserId },
] ]
}, },
}; };
@ -337,12 +337,12 @@ describe("MSC3089TreeSpace", () => {
// Danger: these are partial implementations for testing purposes only // Danger: these are partial implementations for testing purposes only
// @ts-ignore - "MatrixEvent is a value but used as a type", which is true but not important // @ts-ignore - "MatrixEvent is a value but used as a type", which is true but not important
let childState: {[roomId: string]: MatrixEvent[]} = {}; let childState: { [roomId: string]: MatrixEvent[] } = {};
// @ts-ignore - "MatrixEvent is a value but used as a type", which is true but not important // @ts-ignore - "MatrixEvent is a value but used as a type", which is true but not important
let parentState: MatrixEvent[] = []; let parentState: MatrixEvent[] = [];
let parentRoom: Room; let parentRoom: Room;
let childTrees: MSC3089TreeSpace[]; let childTrees: MSC3089TreeSpace[];
let rooms: {[roomId: string]: Room}; let rooms: { [roomId: string]: Room };
let clientSendStateFn: jest.MockedFunction<typeof client.sendStateEvent>; let clientSendStateFn: jest.MockedFunction<typeof client.sendStateEvent>;
const staticDomain = "static.example.org"; const staticDomain = "static.example.org";
@ -771,7 +771,7 @@ describe("MSC3089TreeSpace", () => {
[UNSTABLE_MSC3089_LEAF.unstable]: {}, // test to ensure we're definitely using unstable [UNSTABLE_MSC3089_LEAF.unstable]: {}, // test to ensure we're definitely using unstable
}); });
return Promise.resolve({event_id: fileEventId}); // eslint-disable-line camelcase return Promise.resolve({ event_id: fileEventId }); // eslint-disable-line camelcase
}); });
client.sendMessage = sendMsgFn; client.sendMessage = sendMsgFn;
@ -800,7 +800,7 @@ describe("MSC3089TreeSpace", () => {
it('should support getting files', () => { it('should support getting files', () => {
const fileEventId = "$file"; const fileEventId = "$file";
const fileEvent = {forTest: true}; // MatrixEvent mock const fileEvent = { forTest: true }; // MatrixEvent mock
room.currentState = { room.currentState = {
getStateEvents: (eventType: string, stateKey?: string) => { getStateEvents: (eventType: string, stateKey?: string) => {
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable
@ -829,8 +829,8 @@ describe("MSC3089TreeSpace", () => {
}); });
it('should list files', () => { it('should list files', () => {
const firstFile = {getContent: () => ({active: true})}; const firstFile = { getContent: () => ({ active: true }) };
const secondFile = {getContent: () => ({active: false})}; // deliberately inactive const secondFile = { getContent: () => ({ active: false }) }; // deliberately inactive
room.currentState = { room.currentState = {
getStateEvents: (eventType: string, stateKey?: string) => { getStateEvents: (eventType: string, stateKey?: string) => {
expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable expect(eventType).toEqual(UNSTABLE_MSC3089_BRANCH.unstable); // test to ensure we're definitely using unstable

View File

@ -92,7 +92,7 @@ export class MSC3089Branch {
if (!event) throw new Error("Failed to find event"); if (!event) throw new Error("Failed to find event");
// Sometimes the event context doesn't decrypt for us, so do that. // Sometimes the event context doesn't decrypt for us, so do that.
await this.client.decryptEventIfNeeded(event, {emit: false, isRetry: false}); await this.client.decryptEventIfNeeded(event, { emit: false, isRetry: false });
const file = event.getContent()['file']; const file = event.getContent()['file'];
const httpUrl = this.client.mxcUrlToHttp(file['url']); const httpUrl = this.client.mxcUrlToHttp(file['url']);

View File

@ -101,7 +101,7 @@ export class MSC3089TreeSpace {
* @returns {Promise<void>} Resolves when complete. * @returns {Promise<void>} Resolves when complete.
*/ */
public setName(name: string): Promise<void> { public setName(name: string): Promise<void> {
return this.client.sendStateEvent(this.roomId, EventType.RoomName, {name}, ""); return this.client.sendStateEvent(this.roomId, EventType.RoomName, { name }, "");
} }
/** /**
@ -220,9 +220,9 @@ export class MSC3089TreeSpace {
await this.client.leave(this.roomId); await this.client.leave(this.roomId);
} }
private getOrderedChildren(children: MatrixEvent[]): {roomId: string, order: string}[] { private getOrderedChildren(children: MatrixEvent[]): { roomId: string, order: string }[] {
const ordered: {roomId: string, order: string}[] = children const ordered: { roomId: string, order: string }[] = children
.map(c => ({roomId: c.getStateKey(), order: c.getContent()['order']})); .map(c => ({ roomId: c.getStateKey(), order: c.getContent()['order'] }));
ordered.sort((a, b) => { ordered.sort((a, b) => {
if (a.order && !b.order) { if (a.order && !b.order) {
return -1; return -1;
@ -357,7 +357,7 @@ export class MSC3089TreeSpace {
// XXX: We should be creating gaps to avoid conflicts // XXX: We should be creating gaps to avoid conflicts
lastOrder = lastOrder ? nextString(lastOrder) : DEFAULT_ALPHABET[0]; lastOrder = lastOrder ? nextString(lastOrder) : DEFAULT_ALPHABET[0];
const currentChild = parentRoom.currentState.getStateEvents(EventType.SpaceChild, target.roomId); const currentChild = parentRoom.currentState.getStateEvents(EventType.SpaceChild, target.roomId);
const content = currentChild?.getContent() ?? {via: [this.client.getDomain()]}; const content = currentChild?.getContent() ?? { via: [this.client.getDomain()] };
await this.client.sendStateEvent(parentRoom.roomId, EventType.SpaceChild, { await this.client.sendStateEvent(parentRoom.roomId, EventType.SpaceChild, {
...content, ...content,
order: lastOrder, order: lastOrder,
@ -373,7 +373,7 @@ export class MSC3089TreeSpace {
// Now we can finally update our own order state // Now we can finally update our own order state
const currentChild = parentRoom.currentState.getStateEvents(EventType.SpaceChild, this.roomId); const currentChild = parentRoom.currentState.getStateEvents(EventType.SpaceChild, this.roomId);
const content = currentChild?.getContent() ?? {via: [this.client.getDomain()]}; const content = currentChild?.getContent() ?? { via: [this.client.getDomain()] };
await this.client.sendStateEvent(parentRoom.roomId, EventType.SpaceChild, { await this.client.sendStateEvent(parentRoom.roomId, EventType.SpaceChild, {
...content, ...content,
order: newOrder, order: newOrder,