diff --git a/deno.json b/deno.json index f1b2cee..f72ff52 100644 --- a/deno.json +++ b/deno.json @@ -2,6 +2,7 @@ "imports": { "nanoid": "https://deno.land/x/nanoid@v3.0.0/mod.ts", "events": "https://deno.land/x/events@v1.0.0/mod.ts", - "typed-emitter": "npm:typed-emitter" + "typed-emitter": "npm:typed-emitter", + "@matrix-org/matrix-sdk-crypto-wasm": "npm:@matrix-org/matrix-sdk-crypto-wasm" } } diff --git a/dist/src/api.js b/dist/src/api.js index 6d3aca4..e6a3dd7 100644 --- a/dist/src/api.js +++ b/dist/src/api.js @@ -1,3 +1,24 @@ // all the types for the api export {}; +// export interface WellKnownClient { +// baseUrl: string, +// } +// export interface ServerConfig { +// components: { +// api: string, +// sync: string, +// media: string, +// voip: string, +// }, +// server: { +// name: string, +// version: string, +// url: string, +// }, +// admins: Array<{ +// user_id: string, +// email_address?: string, +// purposes: Array<"m.admin" | "m.moderation" | "m.security">, +// }>, +// } //# sourceMappingURL=api.js.map \ No newline at end of file diff --git a/dist/src/api.js.map b/dist/src/api.js.map index 219ea5e..f2a830c 100644 --- a/dist/src/api.js.map +++ b/dist/src/api.js.map @@ -1 +1 @@ -{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,4BAA4B"} \ No newline at end of file +{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings":"AAAA,4BAA4B;;AAwP5B,qCAAqC;AACrC,qBAAqB;AACrB,IAAI;AAEJ,kCAAkC;AAClC,kBAAkB;AAClB,mBAAmB;AACnB,oBAAoB;AACpB,qBAAqB;AACrB,oBAAoB;AACpB,OAAO;AACP,cAAc;AACd,oBAAoB;AACpB,uBAAuB;AACvB,mBAAmB;AACnB,OAAO;AACP,oBAAoB;AACpB,uBAAuB;AACvB,8BAA8B;AAC9B,kEAAkE;AAClE,QAAQ;AACR,IAAI"} \ No newline at end of file diff --git a/dist/src/client.d.ts b/dist/src/client.d.ts index 3be41e1..7efa324 100644 --- a/dist/src/client.d.ts +++ b/dist/src/client.d.ts @@ -3,13 +3,13 @@ import { Network } from "./net.js"; import { Room } from "./room.js"; import { Connection } from "./sync.js"; import TypedEmitter from "typed-emitter"; -interface ClientConfig { +export interface ClientConfig { baseUrl: string; token: string; userId: string; deviceId: string; } -type ClientState = { +export type ClientState = { state: "stop"; } | { state: "sync"; @@ -21,6 +21,9 @@ type ClientState = { } | { state: "retry"; backoff: number; +} | { + state: "logout"; + soft: boolean; }; type ClientEvents = { state: (state: ClientState) => void; @@ -30,7 +33,7 @@ type ClientEvents = { accountData: (type: string, content: string) => void; toDevice: (event: ApiDeviceEvent) => void; }; -type RoomList = { +export type RoomList = { count: number; rooms: Array; }; @@ -69,5 +72,6 @@ export declare class Client extends Client_base { private setState; start(): void; stop(): void; + logout(): Promise; } export {}; diff --git a/dist/src/client.js b/dist/src/client.js index d4744f4..5006550 100644 --- a/dist/src/client.js +++ b/dist/src/client.js @@ -119,9 +119,14 @@ export class Client extends EventEmitter { } // Stop receiving events from /sync. stop() { - this.conn.abort(); + this.conn.abort("stop sync"); this.conn = new Connection(this); this.setState({ state: "stop" }); } + async logout() { + this.stop(); + await this.net.authLogout(); + this.setState({ state: "logout", soft: false }); + } } //# sourceMappingURL=client.js.map \ No newline at end of file diff --git a/dist/src/client.js.map b/dist/src/client.js.map index 4df06cf..4a58a40 100644 --- a/dist/src/client.js.map +++ b/dist/src/client.js.map @@ -1 +1 @@ -{"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAG7D,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAqDlC,MAAM,KAAM,SAAQ,GAAiB;IACnC,YAAmB,MAAc;QAC/B,KAAK,EAAE,CAAC;QADE;;;;mBAAO,MAAM;WAAQ;IAEjC,CAAC;IA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/dist/src/index.d.ts +++ b/dist/src/index.d.ts @@ -1,6 +1,8 @@ export { Client } from "./client.js"; +export { Setup } from "./setup.js"; export { ThreadPaginator } from "./room.js"; -export type { Event, StateEvent } from "./event.js"; -export type { Room } from "./room.js"; -export type { Thread } from "./thread.js"; -export type { Timeline } from "./timeline.js"; +export { Event, StateEvent } from "./event.js"; +export { Room } from "./room.js"; +export { Thread } from "./thread.js"; +export type { RoomList, ClientState } from "./client.js"; +export type { UserId, RoomId, EventId } from "./api.js"; diff --git a/dist/src/index.js b/dist/src/index.js index c4414a3..f43b4c9 100644 --- a/dist/src/index.js +++ b/dist/src/index.js @@ -1,3 +1,7 @@ export { Client } from "./client.js"; +export { Setup } from "./setup.js"; export { ThreadPaginator } from "./room.js"; +export { Event, StateEvent } from "./event.js"; +export { Room } from "./room.js"; +export { Thread } from "./thread.js"; //# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/src/index.js.map b/dist/src/index.js.map index 4e5adab..8296ab4 100644 --- a/dist/src/index.js.map +++ b/dist/src/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC"} \ No newline at end of file +{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC"} \ No newline at end of file diff --git a/dist/src/net.d.ts b/dist/src/net.d.ts index 4ebfa9f..b9e7070 100644 --- a/dist/src/net.d.ts +++ b/dist/src/net.d.ts @@ -47,5 +47,8 @@ export declare class Network { sendEvent(roomId: t.RoomId, type: string, txnId: string, content: any): Promise; sendState(roomId: t.RoomId, type: string, stateKey: string, content: any): Promise; ack(acks: t.AckRequest): Promise; + authLogin(): Promise; + authRegister(): Promise; + authLogout(): Promise; } export {}; diff --git a/dist/src/net.js b/dist/src/net.js index cb0030f..2dd47a2 100644 --- a/dist/src/net.js +++ b/dist/src/net.js @@ -76,8 +76,19 @@ export class Network { body: (isJson ? JSON.stringify(options.body) : options.body), ...options.extra, }); - if (!req.ok) - throw new Error(`Request failed: ${await req.text()}`); + // FIXME: handle uiaa and make this less awful + if (!req.ok) { + // const response = await req.json(); + // throw { response, error: new Error(`Request failed: ${await req.text()}`) }; + if (req.status === 401) { + this.client.stop(); + this.client.setState({ state: "logout" }); + throw new Error(`Request failed: ${await req.text()}`); + } + else { + throw new Error(`Request failed: ${await req.text()}`); + } + } if (options.raw) return req.body; return req.json(); @@ -188,5 +199,36 @@ export class Network { body: acks, }); } + async authLogin() { + throw new Error("todo!"); + // return this.fetch({ + // method: "POST", + // path: `/_matrix/client/v3/login`, + // body: {}, + // }); + } + async authRegister() { + throw new Error("todo!"); + // return this.fetch({ + // method: "POST", + // path: `/_matrix/client/v3/login`, + // body: {}, + // }); + } + // public async authGuest() { + // throw new Error("todo!") + // // return this.fetch({ + // // method: "POST", + // // path: `/_matrix/client/v3/login`, + // // body: {}, + // // }); + // } + async authLogout() { + return this.fetch({ + method: "POST", + path: `/_matrix/client/v3/logout`, + body: {}, + }); + } } //# sourceMappingURL=net.js.map \ No newline at end of file diff --git a/dist/src/net.js.map b/dist/src/net.js.map index 0370185..7d6f3fd 100644 --- a/dist/src/net.js.map +++ b/dist/src/net.js.map @@ -1 +1 @@ -{"version":3,"file":"net.js","sourceRoot":"","sources":["../../src/net.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,GAAG,CA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AAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,SAAS,CAAC,MAAgB,EAAE,IAAY,EAAE,QAAgB,EAAE,OAAY;QACnF,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,4BAA4B,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE;YAC7E,IAAI,EAAE,OAAO;SACd,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,GAAG,CAAC,IAAkB;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,wBAAwB;YAC9B,IAAI,EAAE,IAAI;SACX,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,SAAS;QACpB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;QACxB,sBAAsB;QACtB,oBAAoB;QACpB,sCAAsC;QACtC,cAAc;QACd,MAAM;IACR,CAAC;IAEM,KAAK,CAAC,YAAY;QACvB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAA;QACxB,sBAAsB;QACtB,oBAAoB;QACpB,sCAAsC;QACtC,cAAc;QACd,MAAM;IACR,CAAC;IAED,6BAA6B;IAC7B,6BAA6B;IAC7B,2BAA2B;IAC3B,yBAAyB;IACzB,2CAA2C;IAC3C,mBAAmB;IACnB,WAAW;IACX,IAAI;IAEG,KAAK,CAAC,UAAU;QACrB,OAAO,IAAI,CAAC,KAAK,CAAC;YAChB,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,2BAA2B;YACjC,IAAI,EAAE,EAAE;SACT,CAAC,CAAC;IACL,CAAC;CACF"} \ No newline at end of file diff --git a/dist/src/room.d.ts b/dist/src/room.d.ts index 95801d4..0b63e14 100644 --- a/dist/src/room.d.ts +++ b/dist/src/room.d.ts @@ -1,12 +1,10 @@ import TypedEmitter from "typed-emitter"; -import { ApiEphemeralEvent, EventId, IncludeThreads, SyncResponseRoom, Unreads } from "./api.js"; +import { EventId, IncludeThreads, SyncResponseRoom, Unreads } from "./api.js"; import { Client } from "./client.js"; import { Event, StateEvent } from "./event.js"; -import { TimelineSet } from "./timeline.js"; +import { RoomTimelineSet } from "./timeline.js"; import { Thread } from "./thread.js"; type RoomEvents = { - timeline: (event: Event) => void; - ephemeral: (event: ApiEphemeralEvent) => void; thread: (thread: Thread) => void; state: (event: StateEvent) => void; notifications: (notifs: Unreads) => void; @@ -21,7 +19,7 @@ export declare class Room extends Room_base { client: Client; id: string; private state; - timelines: TimelineSet; + timelines: RoomTimelineSet; events: Map; threads: RoomThreads; constructor(client: Client, id: string, data: SyncResponseRoom); diff --git a/dist/src/room.js b/dist/src/room.js index 6984e29..b22407b 100644 --- a/dist/src/room.js +++ b/dist/src/room.js @@ -1,6 +1,6 @@ import EventEmitter from "events"; import { Event, StateEvent } from "./event.js"; -import { TimelineSet } from "./timeline.js"; +import { RoomTimelineSet } from "./timeline.js"; import { nanoid } from "nanoid"; import { Thread } from "./thread.js"; export class Room extends EventEmitter { @@ -43,7 +43,7 @@ export class Room extends EventEmitter { enumerable: true, configurable: true, writable: true, - value: new TimelineSet(this) + value: new RoomTimelineSet(this) }); Object.defineProperty(this, "events", { enumerable: true, @@ -76,7 +76,20 @@ export class Room extends EventEmitter { const events = data.timeline .filter(raw => !this.events.has(raw.event_id)) .map(raw => new Event(this, raw)); - this.timelines._appendEvents(events); + for (const event of events) { + this.events.set(event.id, event); + this.timelines.live._eventList.push(...events); + for (const event of events) + this.timelines.live.emit("timelineAppend", event); + const threadId = event.content["m.relations"]?.find((rel) => rel.rel_type === "m.thread")?.event_id; + const thread = this.threads.get(threadId); + if (thread) { + thread.messageCount++; + thread.latestEvent = event; + thread.timelines.live._eventList.push(event); + thread.timelines.live.emit("timelineAppend", event); + } + } } } getState(type, stateKey = "") { @@ -97,11 +110,11 @@ export class Room extends EventEmitter { return new Promise((res) => { const sub = (event) => { if (event.unsigned.transaction_id === txn) { - this.off("timeline", sub); + this.timelines.live.off("timelineAppend", sub); res(event); } }; - this.on("timeline", sub); + this.timelines.live.on("timelineAppend", sub); }); } async leave(reason) { diff --git a/dist/src/room.js.map b/dist/src/room.js.map index 001b1be..9f8de8a 100644 --- a/dist/src/room.js.map +++ b/dist/src/room.js.map @@ -1 +1 @@ -{"version":3,"file":"room.js","sourceRoot":"","sources":["../../src/room.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAC;AAIlC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA2BrC,MAAM,OAAO,IAAK,SAAS,YAA8D;IAOvF,2BAA2B;IAE3B;;;;;;;;;;;;MAYE;IAEF,YACS,MAAc,EACd,EAAU,EACjB,IAAsB;QAEtB,KAAK,EAAE,CAAC;QAJR;;;;mBAAO,MAAM;WAAQ;QACrB;;;;mBAAO,EAAE;WAAQ;QAxBnB,+CAA+C;QACvC;;;;mBAA8C,IAAI,GAAG,EAAE;WAAC;QAEzD;;;;mBAAY,IAAI,WAAW,CAAC,IAAI,CAAC;WAAC;QAClC;;;;mBAA8B,IAAI,GAAG,EAAE;WAAC;QACxC;;;;mBAAU,IAAI,WAAW,CAAC,IAAI,CAAC;WAAC;QAuBrC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,IAAsB;QAC3B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,cAAc,IAAI,EAAE,EAAE,CAAC;YAC5C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AAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;gBACpC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;IAC3B,CAAC;CACF"} \ No newline at end of file diff --git a/dist/src/setup.d.ts b/dist/src/setup.d.ts index bb523dc..1db941e 100644 --- a/dist/src/setup.d.ts +++ b/dist/src/setup.d.ts @@ -1,2 +1,32 @@ -declare class Setup { +import { Client } from "./client.js"; +type Flows = { + "m.login.password": { + password: string; + }; + "m.login.recaptcha": { + response: string; + }; +}; +type Identifier = { + type: "m.id.user"; + user: string; +} | { + type: string; + [key: string]: any; +}; +export declare class Setup { + target: "login" | "register" | "guest"; + deviceName: string; + baseUrl: string | null; + endpoint: string | null; + session: string | null; + flows: Array | null; + params: Record | null; + identifier: Identifier | null; + constructor(target: "login" | "register" | "guest", deviceName?: string); + useDomain(_domain: string): Promise; + useBaseUrl(baseUrl: string): Promise; + useIdentifier(id: Identifier): void; + exec(type: K, options: Flows[K]): Promise; } +export {}; diff --git a/dist/src/setup.js b/dist/src/setup.js index b479971..9586f70 100644 --- a/dist/src/setup.js +++ b/dist/src/setup.js @@ -1,5 +1,118 @@ -"use strict"; // Used for initiating a client, handling well-known and authentication. -class Setup { +/* +I'd love to rip this out and replace this with oidc a la "matrix 2.0", +but I'm not sure if that's a good idea yet. + +Benefits: + +1. It will be more secure since users won't enter credentials into random clients. +2. It separates concerns. + 2.1 client and server devs can focus on matrix instead of security best practices + 2.2 server admins can add new auth mechanisms without needing spec changes +3. I can use existing sdks and libraries to do authentication - rolling your own auth is a bad idea. + +Drawbacks: + +1. The ux will be worse since there's now a separtate place to do auth (login, register, manage sessions). +2. It will be much more complex. Server admins now have extra stuff to setup, maintain, and debug. Arguably, it's more difficult for client devs to use as well. +3. It forces users to have some kind of web browser to login. +*/ +// TODO: properly integrate with net.js +import { Client } from "./client.js"; +export class Setup { + constructor(target, deviceName = "unnamed (sdk-ts)") { + Object.defineProperty(this, "target", { + enumerable: true, + configurable: true, + writable: true, + value: target + }); + Object.defineProperty(this, "deviceName", { + enumerable: true, + configurable: true, + writable: true, + value: deviceName + }); + Object.defineProperty(this, "baseUrl", { + enumerable: true, + configurable: true, + writable: true, + value: null + }); + Object.defineProperty(this, "endpoint", { + enumerable: true, + configurable: true, + writable: true, + value: null + }); + Object.defineProperty(this, "session", { + enumerable: true, + configurable: true, + writable: true, + value: null + }); + Object.defineProperty(this, "flows", { + enumerable: true, + configurable: true, + writable: true, + value: null + }); + Object.defineProperty(this, "params", { + enumerable: true, + configurable: true, + writable: true, + value: null + }); + Object.defineProperty(this, "identifier", { + enumerable: true, + configurable: true, + writable: true, + value: null + }); + } + async useDomain(_domain) { + throw new Error("todo!"); + } + async useBaseUrl(baseUrl) { + this.baseUrl = baseUrl; + this.endpoint = `${baseUrl}/_matrix/client/v3/${this.target === "login" ? "login" : "register"}${this.target === "guest" ? "?kind=guest" : ""}`; + const res = await fetch(this.endpoint).then(res => res.json()); + this.flows = res.flows; + this.params = res.params; + } + useIdentifier(id) { + this.identifier = id; + } + async exec(type, options) { + if (!this.endpoint) + throw new Error("you need to call useBaseUrl first"); + const res = await fetch(this.endpoint, { + body: JSON.stringify({ + identifier: this.identifier, + initial_device_display_name: this.deviceName, + session: this.session ?? undefined, + type: type, + ...options, + }), + method: "POST", + }).then(res => res.json()); + if (res.status === 400) { + this.session = res.session; + return null; + } + else { + return new Client({ + baseUrl: this.baseUrl, + token: res.access_token, + deviceId: res.device_id, + userId: res.user_id, + }); + } + } } +// const setup = new Setup("login"); +// // setup.useIdentifier({ type: "m.id.user", user: "@localpart:server.tld" }); +// setup.useIdentifier({ type: "m.id.user", user: "localpart" }); +// await setup.useBaseUrl("http://localhost:6167"); +// await setup.exec("m.login.password", { password: "a" }); //# sourceMappingURL=setup.js.map \ No newline at end of file diff --git a/dist/src/setup.js.map b/dist/src/setup.js.map index de642a8..6ed59d2 100644 --- a/dist/src/setup.js.map +++ b/dist/src/setup.js.map @@ -1 +1 @@ -{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":";AAAA,wEAAwE;AAExE,MAAM,KAAK;CACV"} \ No newline at end of file +{"version":3,"file":"setup.js","sourceRoot":"","sources":["../../src/setup.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE;;;;;;;;;;;;;;;;;EAiBE;AAEF,uCAAuC;AAEvC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC,MAAM,OAAO,KAAK;IAQhB,YACS,MAAsC,EACtC,aAAqB,kBAAkB;QAD9C;;;;mBAAO,MAAM;WAAgC;QAC7C;;;;mBAAO,UAAU;WAA6B;QATzC;;;;mBAAyB,IAAI;WAAC;QAC9B;;;;mBAA0B,IAAI;WAAC;QAC/B;;;;mBAAyB,IAAI;WAAC;QAC9B;;;;mBAA8B,IAAI;WAAC;QACnC;;;;mBAAwC,IAAI;WAAC;QAC7C;;;;mBAAgC,IAAI;WAAC;IAKzC,CAAC;IAEJ,KAAK,CAAC,SAAS,CAAC,OAAe;QAC7B,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,GAAG,OAAO,sBAAsB,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,GAAG,IAAI,CAAC,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;QAChJ,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CA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at end of file diff --git a/dist/src/sync.js b/dist/src/sync.js index d694e95..11ddf11 100644 --- a/dist/src/sync.js +++ b/dist/src/sync.js @@ -52,6 +52,8 @@ export class Connection { }, this.controller.signal).catch((reason) => { if (reason === "update query") return null; + if (reason === "stop sync") + return null; throw reason; }); if (!json) diff --git a/dist/src/sync.js.map b/dist/src/sync.js.map index 87c9c99..2d8749f 100644 --- a/dist/src/sync.js.map +++ b/dist/src/sync.js.map @@ -1 +1 @@ -{"version":3,"file":"sync.js","sourceRoot":"","sources":["../../src/sync.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,6DAA6D;AAG7D,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,MAAM,OAAO,UAAU;IAOrB,YAAoB,MAAc;QAAtB;;;;mBAAQ,MAAM;WAAQ;QAN1B;;;;mBAAS,MAAM,EAAE;WAAC;QAClB;;;;mBAAa,IAAI,eAAe,EAAE;WAAC;QACnC;;;;mBAAc,GAAG;WAAC;QAClB;;;;;WAA0B;QAC1B;;;;mBAAqB,EAAE;WAAC;IAEK,CAAC;IAEtC,gBAAgB;IAChB,KAAK,CAAC,IAAI,CAAC,UAAkB,KAAK;QAChC,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC;YACtC,OAAO,EAAE,IAAI,CAAC,MAAM;YACpB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,WAAW,EAAE,IAAI,CAAC,KAAK,IAAI,SAAS;YACpC,OAAO;YACP,GAAG,IAAI,CAAC,KAAK;SACd,EAAE,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,IAAI,MAAM,KAAK,cAAc;gBAAE,OAAO,IAAI,CAAC;YAC3C,MAAM,MAAM,CAAC;QACf,CAAC,CAAC,CAAC;QACH,IAAI,CAA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AAY,CAAC;QACxC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,eAAe,CAAC,MAAc;QAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,EAAE,CAAC;QAC7C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;QAChC,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,MAAe;QACnB,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;CACF"} \ No newline at end of file diff --git a/dist/src/thread.d.ts b/dist/src/thread.d.ts index ecb4660..fa97cd4 100644 --- a/dist/src/thread.d.ts +++ b/dist/src/thread.d.ts @@ -2,6 +2,7 @@ import TypedEmitter from "typed-emitter"; import { EventId, Unreads } from "./api.js"; import { Room } from "./room.js"; import { Event } from "./event.js"; +import { ThreadTimelineSet } from "./timeline.js"; type ThreadEvents = { timeline: (event: Event) => void; notifications: (notifs: Unreads) => void; @@ -11,6 +12,7 @@ export declare class Thread extends Thread_base { baseEvent: Event; room: Room; id: string; + timelines: ThreadTimelineSet; participation: string; messageCount: number; latestEvent: Event; diff --git a/dist/src/thread.js b/dist/src/thread.js index 05840d1..d2b8574 100644 --- a/dist/src/thread.js +++ b/dist/src/thread.js @@ -1,5 +1,6 @@ import EventEmitter from "events"; import { Event } from "./event.js"; +import { ThreadTimelineSet } from "./timeline.js"; export class Thread extends EventEmitter { constructor(baseEvent) { const threadRel = baseEvent.unsigned["m.relations"]?.["m.thread"]; @@ -24,6 +25,12 @@ export class Thread extends EventEmitter { writable: true, value: this.baseEvent.id }); + Object.defineProperty(this, "timelines", { + enumerable: true, + configurable: true, + writable: true, + value: new ThreadTimelineSet(this) + }); Object.defineProperty(this, "participation", { enumerable: true, configurable: true, diff --git a/dist/src/thread.js.map b/dist/src/thread.js.map index 64236a8..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,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACpE,IAAI,CAAC,YAAY;YAAE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,WAAW,CAAC,CAAC;QACrE,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC,KAAK,CAAC;IACtC,CAAC;IAED,uCAAuC;IACvC,gDAAgD;IAChD,uEAAuE;IACvE,IAAI;IAEJ,sDAAsD;IACtD,sDAAsD;IACtD,IAAI;IAEJ,KAAK,CAAC,GAAG,CAAC,OAAiB;QACzB,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;YAC7B,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;SACnF,CAAC,CAAC;IACL,CAAC;CACF"} \ No newline at end of file diff --git a/dist/src/timeline.d.ts b/dist/src/timeline.d.ts index f6a500c..1effef6 100644 --- a/dist/src/timeline.d.ts +++ b/dist/src/timeline.d.ts @@ -3,49 +3,55 @@ import { Room } from "./room.js"; import { Event } from "./event.js"; import { Thread } from "./thread.js"; import TypedEmitter from "typed-emitter"; -type TimelineEvents = { +type TimelineEvents = { timelineUpdate: (batch: Array, toBeginning: boolean) => void; timelineAppend: (event: Event) => void; - timelineReplace: (timeine: Timeline) => void; + timelineReplace: (timeine: T) => void; ephemeral: (event: ApiEphemeralEvent) => void; }; -export interface Timeline extends TypedEmitter { - isAtBeginning: boolean; - isAtEnd: boolean; - getEvents(): Array; - paginate(dir: "f" | "b", limit: number): Promise; -} -declare const RoomTimeline_base: new () => TypedEmitter; -export declare class RoomTimeline extends RoomTimeline_base implements Timeline { - room: Room; +declare const Timeline_base: new () => TypedEmitter>; +declare abstract class Timeline extends Timeline_base { isAtBeginning: boolean; isAtEnd: boolean; _eventList: Array; prevBatch: string | undefined; nextBatch: string | undefined; - constructor(room: Room); getEvents(): Array; + abstract paginate(dir: "f" | "b", limit: number): Promise; +} +export declare class RoomTimeline extends Timeline implements TypedEmitter> { + private timelineSet; + room: Room; + constructor(timelineSet: RoomTimelineSet, room: Room); paginate(dir: "f" | "b", limit?: number): Promise; } -declare const ThreadTimeline_base: new () => TypedEmitter; -export declare class ThreadTimeline extends ThreadTimeline_base implements Timeline { +export declare class ThreadTimeline extends Timeline implements TypedEmitter> { + private timelineSet; thread: Thread; - isAtBeginning: boolean; - isAtEnd: boolean; - _eventList: Array; - prevBatch: string | undefined; - nextBatch: string | undefined; - constructor(thread: Thread); - getEvents(): Array; + constructor(timelineSet: ThreadTimelineSet, thread: Thread); paginate(dir: "f" | "b", limit?: number): Promise; } -export declare class TimelineSet { +declare abstract class TimelineSet { + abstract timelines: Set; + abstract timelineMap: Map; + merge(events: Array): Timeline | null; +} +export declare class ThreadTimelineSet extends TimelineSet { + thread: Thread; + client: import("./client.js").Client; + live: ThreadTimeline; + timelines: Set; + timelineMap: Map; + constructor(thread: Thread); + fetch(at: EventId | "start" | "end", limit?: number): Promise; +} +export declare class RoomTimelineSet extends TimelineSet { room: Room; + client: import("./client.js").Client; live: RoomTimeline; - timelines: Set; + timelines: Set; + timelineMap: Map; constructor(room: Room); - forThread(thread: Thread, at: EventId | "start" | "end"): Promise; - forEvent(eventId: EventId): Promise; - _appendEvents(events: Array): void; + fetch(at: EventId | "start" | "end", limit?: number): Promise; } export {}; diff --git a/dist/src/timeline.js b/dist/src/timeline.js index dcf4fb0..c72b67e 100644 --- a/dist/src/timeline.js +++ b/dist/src/timeline.js @@ -9,15 +9,9 @@ const intoEvent = (room) => (raw) => { room.events.set(raw.event_id, event); return event; }; -export class RoomTimeline extends EventEmitter { - constructor(room) { - super(); - Object.defineProperty(this, "room", { - enumerable: true, - configurable: true, - writable: true, - value: room - }); +class Timeline extends EventEmitter { + constructor() { + super(...arguments); Object.defineProperty(this, "isAtBeginning", { enumerable: true, configurable: true, @@ -53,6 +47,23 @@ export class RoomTimeline extends EventEmitter { getEvents() { return this._eventList; } +} +export class RoomTimeline extends Timeline { + constructor(timelineSet, room) { + super(); + Object.defineProperty(this, "timelineSet", { + enumerable: true, + configurable: true, + writable: true, + value: timelineSet + }); + Object.defineProperty(this, "room", { + enumerable: true, + configurable: true, + writable: true, + value: room + }); + } async paginate(dir, limit = 50) { if (dir === "b" && this.isAtBeginning) return false; @@ -87,57 +98,38 @@ export class RoomTimeline extends EventEmitter { this.isAtBeginning = true; } this._eventList.unshift(...events); - for (const event of events) - this.room.events.set(event.id, event); + for (const event of events) { + const existing = this.timelineSet.timelineMap.get(event.id); + if (existing) { + const otherIdx = existing.getEvents().indexOf(event); + if (otherIdx === -1) + continue; + } + else { + this.timelineSet.timelineMap.set(event.id, this); + this.room.events.set(event.id, event); + } + } this.emit("timelineUpdate", events, true); } return true; } } -export class ThreadTimeline extends EventEmitter { - constructor(thread) { +export class ThreadTimeline extends Timeline { + constructor(timelineSet, thread) { super(); + Object.defineProperty(this, "timelineSet", { + enumerable: true, + configurable: true, + writable: true, + value: timelineSet + }); Object.defineProperty(this, "thread", { enumerable: true, configurable: true, writable: true, value: thread }); - Object.defineProperty(this, "isAtBeginning", { - enumerable: true, - configurable: true, - writable: true, - value: false - }); - Object.defineProperty(this, "isAtEnd", { - enumerable: true, - configurable: true, - writable: true, - value: false - }); - // private eventIdToTimeline: Map = new Map(); - // These should be private, but typescript doesn't have "private to module" - Object.defineProperty(this, "_eventList", { - enumerable: true, - configurable: true, - writable: true, - value: [] - }); - Object.defineProperty(this, "prevBatch", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - Object.defineProperty(this, "nextBatch", { - enumerable: true, - configurable: true, - writable: true, - value: void 0 - }); - } - getEvents() { - return this._eventList; } async paginate(dir, limit = 50) { if (dir === "b" && this.isAtBeginning) @@ -175,36 +167,50 @@ export class ThreadTimeline extends EventEmitter { this.isAtBeginning = true; } this._eventList.unshift(...events); - for (const event of events) - room.events.set(event.id, event); - // TODO: make more performant - // const timelines = [...this.thread.room.timelines.timelines].filter(i => i instanceof ThreadTimeline && i.thread === this.thread) as Array; - // triple loops! - // this only definitely merges once backwards and once forwards, but that's fine since it would've already been merged anyways if there's multiple overlaps - // for (const timeline of timelines) { - // for (const event of events) { - // // this: [1, 2, 3, 4, 5] - // // other: [3, 4, 5, 6, 7, 8] - // const otherIdx = timeline.getEvents().indexOf(event); - // if (otherIdx === -1) continue; - // // const thisIdx = this._eventList.indexOf(event); - // // this._eventList - // } - // } + for (const event of events) { + const existing = this.timelineSet.timelineMap.get(event.id); + if (existing) { + const otherIdx = existing.getEvents().indexOf(event); + if (otherIdx === -1) + continue; + } + else { + this.timelineSet.timelineMap.set(event.id, this); + room.events.set(event.id, event); + } + } this.emit("timelineUpdate", events, true); return !!data.prev_batch; } } } -export class TimelineSet { - constructor(room) { - Object.defineProperty(this, "room", { +class TimelineSet { + merge(events) { + for (const event of events) { + const tl = this.timelineMap.get(event.id); + if (!tl) + continue; + return tl; + } + return null; + } +} +export class ThreadTimelineSet extends TimelineSet { + constructor(thread) { + super(); + Object.defineProperty(this, "thread", { enumerable: true, configurable: true, writable: true, - value: room + value: thread + }); + // This is the one live timeline + Object.defineProperty(this, "client", { + enumerable: true, + configurable: true, + writable: true, + value: this.thread.room.client }); - // Other timelines *may* be live, but this one is guaranteed to be live Object.defineProperty(this, "live", { enumerable: true, configurable: true, @@ -217,79 +223,147 @@ export class TimelineSet { writable: true, value: new Set() }); - this.live = new RoomTimeline(room); + Object.defineProperty(this, "timelineMap", { + enumerable: true, + configurable: true, + writable: true, + value: new Map() + }); + this.live = new ThreadTimeline(this, thread); this.live.isAtEnd = true; this.timelines.add(this.live); } - // Get a timeline for a thread. Becomes a live timeline if `atEnd = true`. - async forThread(thread, at) { + async fetch(at, limit = 50) { if (at === "end") { - const existing = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.isAtEnd); - if (existing) - return existing; - const tl = new ThreadTimeline(thread); - await tl.paginate("b"); - tl.isAtEnd = true; - return tl; + const fetchCount = limit - this.live.getEvents().length; + if (fetchCount > 0) + await this.live.paginate("b", fetchCount); + return this.live; } else if (at === "start") { - const existing = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.isAtBeginning); - if (existing) + const existing = [...this.timelines].find(i => i.isAtBeginning); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) + await existing.paginate("f", fetchCount); return existing; - const tl = new ThreadTimeline(thread); - await tl.paginate("b"); - this.timelines.add(tl); - return tl; + } + else { + const tl = new ThreadTimeline(this, this.thread); + await tl.paginate("b", limit); + this.timelines.add(tl); + return tl; + } } else { - const existing = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.getEvents().some(ev => ev.id === at)); - if (existing) + // TODO: respect limit? + const existing = this.timelineMap.get(at); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) + await existing.paginate("f", fetchCount); return existing; - const tl = new ThreadTimeline(thread); - const context = await this.room.client.net.fetchContext(this.room.id, at, 0); - tl._eventList = [intoEvent(this.room)(context.event)]; - tl.prevBatch = context.start; - tl.nextBatch = context.end; - this.timelines.add(tl); - return tl; + } + else { + const tl = new ThreadTimeline(this, this.thread); + const context = await this.client.net.fetchContext(this.thread.room.id, at, 0); + const event = intoEvent(this.thread.room)(context.event); + tl._eventList = [event]; + tl.prevBatch = context.start; + tl.nextBatch = context.end; + this.timelineMap.set(event.id, tl); + this.timelines.add(tl); + return tl; + } } } - // Get a timeline for an event (context). - async forEvent(eventId) { - const existing = [...this.timelines].find(tl => tl instanceof RoomTimeline && tl.getEvents().some(ev => ev.id === eventId)); - if (existing) - return existing; - const context = await this.room.client.net.fetchContext(this.room.id, eventId); - const tl = new RoomTimeline(this.room); - const events = context.events_before - .reverse() - .concat([context.event]) - .concat(context.events_after) - .map(intoEvent(this.room)); - tl._eventList = events; - tl.prevBatch = context.start; - tl.nextBatch = context.end; - this.timelines.add(tl); - return tl; +} +export class RoomTimelineSet extends TimelineSet { + constructor(room) { + super(); + Object.defineProperty(this, "room", { + enumerable: true, + configurable: true, + writable: true, + value: room + }); + // Other timelines *may* be live, but this one is guaranteed to be live + Object.defineProperty(this, "client", { + enumerable: true, + configurable: true, + writable: true, + value: this.room.client + }); + Object.defineProperty(this, "live", { + enumerable: true, + configurable: true, + writable: true, + value: void 0 + }); + Object.defineProperty(this, "timelines", { + enumerable: true, + configurable: true, + writable: true, + value: new Set() + }); + Object.defineProperty(this, "timelineMap", { + enumerable: true, + configurable: true, + writable: true, + value: new Map() + }); + this.live = new RoomTimeline(this, room); + this.live.isAtEnd = true; + this.timelines.add(this.live); } - _appendEvents(events) { - // FIXME: there should only be one live timeline for each room and - // thread, they need to be merged together - for (const event of events) { - this.room.events.set(event.id, event); - this.live._eventList.push(...events); - for (const event of events) - this.live.emit("timelineAppend", event); - const threadId = event.content["m.relations"]?.find((rel) => rel.rel_type === "m.thread")?.event_id; - const thread = this.room.threads.get(threadId); - if (thread) { - thread.messageCount++; - thread.latestEvent = event; - const tl = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.isAtEnd); - if (tl) { - tl._eventList.push(event); - tl.emit("timelineAppend", event); - } + // Get a timeline for an event (context). + async fetch(at, limit = 50) { + if (at === "end") { + const fetchCount = limit - this.live.getEvents().length; + if (fetchCount > 0) + await this.live.paginate("b", fetchCount); + return this.live; + } + else if (at === "start") { + const existing = [...this.timelines].find(i => i.isAtBeginning); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) + await existing.paginate("f", fetchCount); + return existing; + } + else { + const tl = new RoomTimeline(this, this.room); + await tl.paginate("b", limit); + this.timelines.add(tl); + return tl; + } + } + else { + // TODO: respect limit? + const existing = this.timelineMap.get(at); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) + await existing.paginate("f", fetchCount); + return existing; + } + else { + const context = await this.client.net.fetchContext(this.room.id, at); + const tl = new RoomTimeline(this, this.room); + const events = context.events_before + .reverse() + .concat([context.event]) + .concat(context.events_after) + .map(intoEvent(this.room)); + tl._eventList = events; + tl.prevBatch = context.start; + tl.nextBatch = context.end; + this.timelines.add(tl); + // FIXME: merge timelines + for (const event of events) + this.timelineMap.set(event.id, tl); + return tl; } } } diff --git a/dist/src/timeline.js.map b/dist/src/timeline.js.map index 787612b..4ad8b4d 100644 --- a/dist/src/timeline.js.map +++ b/dist/src/timeline.js.map @@ -1 +1 @@ -{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../../src/timeline.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAK7C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGnC,OAAO,YAAY,MAAM,QAAQ,CAAC;AAoClC,MAAM,SAAS,GAAG,CAAC,IAAU,EAAE,EAAE,CAAC,CAAC,GAAa,EAAS,EAAE;IACzD,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC9B,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,KAAK,CAAC;AACf,CAAC,CAAC;AAEF,MAAM,OAAO,YAAa,SAAS,YAAkE;IASnG,YAAmB,IAAU;QAC3B,KAAK,EAAE,CAAC;QADE;;;;mBAAO,IAAI;WAAM;QARtB;;;;mBAAyB,KAAK;WAAC;QAC/B;;;;mBAAmB,KAAK;WAAC;QAEhC,2EAA2E;QAC3E;;;;mBAA2B,EAAE;WAAC;QAC9B;;;;;WAA8B;QAC9B;;;;;WAA8B;IAI9B,CAA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C,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;qBACvB,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC;qBAC5B,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC7B,EAAE,CAAC,UAAU,GAAG,MAAM,CAAC;gBACvB,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC;gBAC7B,EAAE,CAAC,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC;gBAC3B,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACvB,yBAAyB;gBACzB,KAAK,MAAM,KAAK,IAAI,MAAM;oBAAE,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;gBAC/D,OAAO,EAAE,CAAC;YACZ,CAAC;QACH,CAAC;IACH,CAAC;CACF"} \ No newline at end of file diff --git a/dist/tsconfig.tsbuildinfo b/dist/tsconfig.tsbuildinfo index e6fa436..b70b6bf 100644 --- a/dist/tsconfig.tsbuildinfo +++ b/dist/tsconfig.tsbuildinfo @@ -1 +1 @@ -{"program":{"fileNames":["../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es5.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.dom.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/api.ts","../src/net.ts","../node_modules/.pnpm/@types+events@3.0.3/node_modules/@types/events/index.d.ts","../node_modules/.pnpm/typed-emitter@2.1.0/node_modules/typed-emitter/index.d.ts","../src/event.ts","../src/thread.ts","../src/timeline.ts","../node_modules/.pnpm/nanoid@5.0.4/node_modules/nanoid/index.d.ts","../src/room.ts","../src/index.ts","../src/sync.ts","../src/client.ts","../src/setup.ts","../src/utils.ts"],"fileInfos":[{"version":"f33e5332b24c3773e930e212cbb8b6867c8ba3ec4492064ea78e55a524d57450","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","26f2f787e82c4222710f3b676b4d83eb5ad0a72fa7b746f03449e7a026ce5073","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc",{"version":"21e41a76098aa7a191028256e52a726baafd45a925ea5cf0222eb430c96c1d83","affectsGlobalScope":true},{"version":"35299ae4a62086698444a5aaee27fc7aa377c68cbb90b441c9ace246ffd05c97","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"e0275cd0e42990dc3a16f0b7c8bca3efe87f1c8ad404f80c6db1c7c0b828c59f","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"acae90d417bee324b1372813b5a00829d31c7eb670d299cd7f8f9a648ac05688","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"62a4966981264d1f04c44eb0f4b5bdc3d81c1a54725608861e44755aa24ad6a5","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"86a34c7a13de9cabc43161348f663624b56871ed80986e41d214932ddd8d6719","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"a10cadc903feb7f4c2336ba8aa3f4f611df6f8ba760114b0a0c3e39bcaf155fb","signature":"1230d499af44ac7431072efa5643f44ec443b82ab90adceb2402e40b7db53ca1"},{"version":"e361a708dca4e8f188b404ad53bac6fa4e3e1bf3cc748057d77ca1e158b830ec","signature":"977b9cc5510fbe08bf3b1e8b9418ccdcc48916d10411c76233f71f719f22eb7c"},"93d28b4eb12c68fccc1f2fc04a4ef83ea3b2a03b18055d3bf29cab267aa7042e","6c27d4b5ba01295ef334456d9af4366aca789f228eee70fcb874b903a59b0e5b",{"version":"5f58bf022e7d045085a3a0d3399b885c3bfba7b367186c96c89ce1738d3148ac","signature":"3c730ad1c3d733f2fbf8d4ed34ac7458155e789c3dec6a7b03d220a1a492391b"},{"version":"4a07d3b58d6cf0a0e8b1d3027f2c895eb17ffaf4583bf6f96482dbaa713aff6a","signature":"df6887063a33dbf2bb5070e2cf3843a3e8844c6ec04d2347babdd19d674d42ae"},{"version":"9c1a33fc9b82bed7b2ae41185bb3536c491647de79255734e21d69de5e73e9da","signature":"d3f6105c09c617aec45fb10fd9424b4f470200b052ac84065173b63ac1dd66fb"},"a45ee7555d019a67fbe092898d1aef0b1d02a9f6679ab84461ff515b4460d706",{"version":"a41315d6066f036b0d080827fd67114595f1d9592d3ce60728c41e0657a8ad85","signature":"63be9cac173649ecc8dcb79b8e10cdadb350bd15151ad1cf75fbf2aaac41aab9"},"fdb7841ac7f0ad247f9c75a512d9272fc4048bae2c630b3a6f42eba37bfee3ee",{"version":"d84e7ceebdf0ca5666019c1a7d69110326993ede96347b6e40eeaef36047d492","signature":"72848e8c0680b2f2b81304c45137ce94af346b19ba084a90eb37437b8f14a163"},{"version":"982a4b70445a3da991403adeccb39ecd006845f3ba2f09c9cbb8613209351af9","signature":"c3c3fa5db7ca7720886f27a109786c1e47d591c9fef0fc16b9f2cad4178ef1be"},{"version":"8f8d0bf3babdb97438eb27caaae3fb6186208704a82446d03971e185c1f5f009","signature":"16f4188a578c2e2a5278d75399ac88b039a9a0c08f852c221d3b03410dff08ff","affectsGlobalScope":true},{"version":"00732cfad7bfbc344b48cebb977fb5c06b7394f3008488947d27383cccfb4e54","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}],"root":[59,60,[63,65],[67,72]],"options":{"composite":true,"module":99,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":true,"strictNullChecks":true,"target":7,"useDefineForClassFields":true},"fileIdsList":[[59,60,61,62,67,69],[59,67,70],[63,64,65,67,70],[59,70],[59,61,62,63,64,65,66,70],[59,66,67,68],[59,61,62,63,67],[59,61,62,63,64,67],[59,60,62,67,69],[59,62,63,64,65,70],[59,68],[59,62,63,67],[59,62,63,64,67]],"referencedMap":[[70,1],[63,2],[68,3],[60,4],[67,5],[69,6],[64,7],[65,8]],"exportedModulesMap":[[70,9],[63,2],[68,3],[60,4],[67,10],[69,11],[64,12],[65,13]],"semanticDiagnosticsPerFile":[61,66,62,57,58,10,11,13,12,2,14,15,16,17,18,19,20,21,3,4,22,26,23,24,25,27,28,29,5,30,31,32,33,6,37,34,35,36,38,7,39,44,45,40,41,42,43,8,49,46,47,48,50,9,51,52,53,56,54,55,1,59,70,63,68,60,67,71,69,64,65,72],"latestChangedDtsFile":"./src/timeline.d.ts"},"version":"5.3.2"} \ No newline at end of file +{"program":{"fileNames":["../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es5.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2016.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.dom.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.dom.iterable.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.core.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.collection.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.generator.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.iterable.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.proxy.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.reflect.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.symbol.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2016.array.include.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.date.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.object.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2018.regexp.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.array.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.object.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.symbol.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2019.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.bigint.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.date.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2020.number.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.promise.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.weakref.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2021.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.array.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.error.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.intl.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.object.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.string.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.es2022.regexp.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.decorators.d.ts","../node_modules/.pnpm/typescript@5.3.2/node_modules/typescript/lib/lib.decorators.legacy.d.ts","../src/api.ts","../src/net.ts","../node_modules/.pnpm/@types+events@3.0.3/node_modules/@types/events/index.d.ts","../node_modules/.pnpm/typed-emitter@2.1.0/node_modules/typed-emitter/index.d.ts","../src/event.ts","../src/thread.ts","../src/timeline.ts","../node_modules/.pnpm/nanoid@5.0.4/node_modules/nanoid/index.d.ts","../src/room.ts","../src/setup.ts","../src/index.ts","../src/sync.ts","../src/client.ts","../src/utils.ts"],"fileInfos":[{"version":"f33e5332b24c3773e930e212cbb8b6867c8ba3ec4492064ea78e55a524d57450","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","26f2f787e82c4222710f3b676b4d83eb5ad0a72fa7b746f03449e7a026ce5073","9a68c0c07ae2fa71b44384a839b7b8d81662a236d4b9ac30916718f7510b1b2d","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc",{"version":"21e41a76098aa7a191028256e52a726baafd45a925ea5cf0222eb430c96c1d83","affectsGlobalScope":true},{"version":"35299ae4a62086698444a5aaee27fc7aa377c68cbb90b441c9ace246ffd05c97","affectsGlobalScope":true},{"version":"138fb588d26538783b78d1e3b2c2cc12d55840b97bf5e08bca7f7a174fbe2f17","affectsGlobalScope":true},{"version":"dc2df20b1bcdc8c2d34af4926e2c3ab15ffe1160a63e58b7e09833f616efff44","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"bc47685641087c015972a3f072480889f0d6c65515f12bd85222f49a98952ed7","affectsGlobalScope":true},{"version":"0dc1e7ceda9b8b9b455c3a2d67b0412feab00bd2f66656cd8850e8831b08b537","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"4ff2a353abf8a80ee399af572debb8faab2d33ad38c4b4474cff7f26e7653b8d","affectsGlobalScope":true},{"version":"93495ff27b8746f55d19fcbcdbaccc99fd95f19d057aed1bd2c0cafe1335fbf0","affectsGlobalScope":true},{"version":"6fc23bb8c3965964be8c597310a2878b53a0306edb71d4b5a4dfe760186bcc01","affectsGlobalScope":true},{"version":"38f0219c9e23c915ef9790ab1d680440d95419ad264816fa15009a8851e79119","affectsGlobalScope":true},{"version":"bb42a7797d996412ecdc5b2787720de477103a0b2e53058569069a0e2bae6c7e","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"4de680d5bb41c17f7f68e0419412ca23c98d5749dcaaea1896172f06435891fc","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"b541a838a13f9234aba650a825393ffc2292dc0fc87681a5d81ef0c96d281e7a","affectsGlobalScope":true},{"version":"e0275cd0e42990dc3a16f0b7c8bca3efe87f1c8ad404f80c6db1c7c0b828c59f","affectsGlobalScope":true},{"version":"811ec78f7fefcabbda4bfa93b3eb67d9ae166ef95f9bff989d964061cbf81a0c","affectsGlobalScope":true},{"version":"717937616a17072082152a2ef351cb51f98802fb4b2fdabd32399843875974ca","affectsGlobalScope":true},{"version":"d7e7d9b7b50e5f22c915b525acc5a49a7a6584cf8f62d0569e557c5cfc4b2ac2","affectsGlobalScope":true},{"version":"71c37f4c9543f31dfced6c7840e068c5a5aacb7b89111a4364b1d5276b852557","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"49ed889be54031e1044af0ad2c603d627b8bda8b50c1a68435fe85583901d072","affectsGlobalScope":true},{"version":"e93d098658ce4f0c8a0779e6cab91d0259efb88a318137f686ad76f8410ca270","affectsGlobalScope":true},{"version":"063600664504610fe3e99b717a1223f8b1900087fab0b4cad1496a114744f8df","affectsGlobalScope":true},{"version":"934019d7e3c81950f9a8426d093458b65d5aff2c7c1511233c0fd5b941e608ab","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"acae90d417bee324b1372813b5a00829d31c7eb670d299cd7f8f9a648ac05688","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"af3dd424cf267428f30ccfc376f47a2c0114546b55c44d8c0f1d57d841e28d74","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"51e547984877a62227042850456de71a5c45e7fe86b7c975c6e68896c86fa23b","affectsGlobalScope":true},{"version":"62a4966981264d1f04c44eb0f4b5bdc3d81c1a54725608861e44755aa24ad6a5","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"e6633e05da3ff36e6da2ec170d0d03ccf33de50ca4dc6f5aeecb572cedd162fb","affectsGlobalScope":true},{"version":"86a34c7a13de9cabc43161348f663624b56871ed80986e41d214932ddd8d6719","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"caccc56c72713969e1cfe5c3d44e5bab151544d9d2b373d7dbe5a1e4166652be","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"33358442698bb565130f52ba79bfd3d4d484ac85fe33f3cb1759c54d18201393","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},{"version":"d3bf30f10d5e66dc8752029d07bff1287e5d9f4731cb42aec33ad7d0d17c3389","signature":"1230d499af44ac7431072efa5643f44ec443b82ab90adceb2402e40b7db53ca1"},{"version":"081d37f1caf02414641bc793d7dbf905c23317b2683a8fd8c90cbd1e7d5900a7","signature":"ce36b9e7617fd59ebe437198b00bba16c3ee8decf675314638f1440897e96c47"},"93d28b4eb12c68fccc1f2fc04a4ef83ea3b2a03b18055d3bf29cab267aa7042e","6c27d4b5ba01295ef334456d9af4366aca789f228eee70fcb874b903a59b0e5b",{"version":"5f58bf022e7d045085a3a0d3399b885c3bfba7b367186c96c89ce1738d3148ac","signature":"3c730ad1c3d733f2fbf8d4ed34ac7458155e789c3dec6a7b03d220a1a492391b"},{"version":"6c494f251c24785b209b3cabb5b482ccf61dbf094d0da7383c7220a3401b6152","signature":"7277284f8ec8b0a8a8189ca3e9bf22a9e7c0f877935887398cbc875838a6eda5"},{"version":"787884cc65969b29238c7ba6f6be6d70a980188dc13e9faf54019be907698620","signature":"d5505aaa5f330646f8a9193570df24b9bc8b9e3b7744494c63f3a0114675a8e2"},"a45ee7555d019a67fbe092898d1aef0b1d02a9f6679ab84461ff515b4460d706",{"version":"aebff6d25231f2c12888ae42e2d18449e5de6c8a98a28179cf9dcf062d6da8f9","signature":"0a34343b3af627efd2b0ca68f3ce9ac77ba65b10e64666a2af3bcb3d03def70c"},{"version":"5681e44ea9ec05beaf1d10b4c3b195900878ed22eb6570a202db01cbffadee8b","signature":"c7fda10b2b469752cc34729106adcc0e2a5f478d0f168198cbf77cc9fb79efef"},"5d1e06113fcc0d9fe107463d91012dd143b72673ccd624c3476a6024fcf1f390",{"version":"e3e26a12aaf138fbe45eaaeea173785f71a7ac4f9f97e784fb2df7efcc3529be","signature":"72848e8c0680b2f2b81304c45137ce94af346b19ba084a90eb37437b8f14a163"},{"version":"3327041da29cea31fcf6586e76b8cecc35ef64f3f69288b093326beb8f15f585","signature":"6c2e6f1ddc05fe8b7697336ee0ec1f6f3cf809c6fcdb7f34e890752a6d73f926"},{"version":"00732cfad7bfbc344b48cebb977fb5c06b7394f3008488947d27383cccfb4e54","signature":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"}],"root":[59,60,[63,65],[67,72]],"options":{"composite":true,"module":99,"noFallthroughCasesInSwitch":true,"noUnusedLocals":true,"noUnusedParameters":true,"outDir":"./","skipLibCheck":true,"sourceMap":true,"strict":true,"strictNullChecks":true,"target":7,"useDefineForClassFields":true},"fileIdsList":[[59,60,61,62,67,70],[59,67,71],[59,63,64,67,68,71],[59,71],[59,61,62,63,64,65,66,71],[71],[59,66,67,69],[59,61,62,63,65,67],[59,61,62,63,64,67],[59,60,62,67,70],[59,62,63,64,65,71],[59,69],[59,62,63,65,67],[59,62,63,64,67,71]],"referencedMap":[[71,1],[63,2],[69,3],[60,4],[67,5],[68,6],[70,7],[64,8],[65,9]],"exportedModulesMap":[[71,10],[63,2],[69,3],[60,4],[67,11],[68,6],[70,12],[64,13],[65,14]],"semanticDiagnosticsPerFile":[61,66,62,57,58,10,11,13,12,2,14,15,16,17,18,19,20,21,3,4,22,26,23,24,25,27,28,29,5,30,31,32,33,6,37,34,35,36,38,7,39,44,45,40,41,42,43,8,49,46,47,48,50,9,51,52,53,56,54,55,1,59,71,63,69,60,67,68,70,64,65,72],"latestChangedDtsFile":"./src/index.d.ts"},"version":"5.3.2"} \ No newline at end of file diff --git a/package.json b/package.json index 3b2bb85..a69b910 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "typescript": "^5.3.2" }, "dependencies": { + "@matrix-org/matrix-sdk-crypto-wasm": "^3.4.0", "events": "^3.3.0", "nanoid": "^5.0.4" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5d14d6e..5cabc38 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + '@matrix-org/matrix-sdk-crypto-wasm': + specifier: ^3.4.0 + version: 3.4.0 events: specifier: ^3.3.0 version: 3.3.0 @@ -25,6 +28,11 @@ devDependencies: packages: + /@matrix-org/matrix-sdk-crypto-wasm@3.4.0: + resolution: {integrity: sha512-noO6QnH+ypT//CxewoQdlK/z2iuyQo1Ecp1PDaYyr/NV5yXkWvGfGIIcShXqrQJfL5kuWxg/14edNplXsaXoDQ==} + engines: {node: '>= 10'} + dev: false + /@types/events@3.0.3: resolution: {integrity: sha512-trOc4AAUThEz9hapPtSd7wf5tiQKvTtu5b371UxXdTuqzIh0ArcRspRP0i0Viu+LXstIQ1z96t1nsPxT9ol01g==} dev: true diff --git a/src/api.ts b/src/api.ts index 95e00ac..7cf1de6 100644 --- a/src/api.ts +++ b/src/api.ts @@ -245,3 +245,26 @@ export interface AckRequest { thread_id?: EventId, }> } + +// export interface WellKnownClient { +// baseUrl: string, +// } + +// export interface ServerConfig { +// components: { +// api: string, +// sync: string, +// media: string, +// voip: string, +// }, +// server: { +// name: string, +// version: string, +// url: string, +// }, +// admins: Array<{ +// user_id: string, +// email_address?: string, +// purposes: Array<"m.admin" | "m.moderation" | "m.security">, +// }>, +// } diff --git a/src/client.ts b/src/client.ts index 4cbc9c5..0c00084 100644 --- a/src/client.ts +++ b/src/client.ts @@ -7,18 +7,19 @@ import { Connection } from "./sync.js"; import EventEmitter from "events"; import TypedEmitter from "typed-emitter"; -interface ClientConfig { +export interface ClientConfig { baseUrl: string, token: string, userId: string, deviceId: string, } -type ClientState = { state: "stop" } // The client is stopped and inactive +export type ClientState = { state: "stop" } // The client is stopped and inactive | { state: "sync" } // The client is active and syncing | { state: "catchup" } // The client is catching up after a `retry` | { state: "error", reason: any } // The client failed and will not retry | { state: "retry", backoff: number } // The client failed and is retrying + | { state: "logout", soft: boolean } // The client isn't logged in type ClientEvents = { // The client's state changed. @@ -43,7 +44,7 @@ type ClientEvents = { toDevice: (event: ApiDeviceEvent) => void, }; -type RoomList = { +export type RoomList = { // The total number of rooms in this list count: number, @@ -144,8 +145,14 @@ export class Client extends (EventEmitter as unknown as new () => TypedEmitter void, - - // an ephemeral event was received - // @deprecated: use timelines.live - ephemeral: (event: ApiEphemeralEvent) => void, - // A thread was created thread: (thread: Thread) => void, @@ -36,7 +28,7 @@ export class Room extends (EventEmitter as unknown as new () => TypedEmitter> = new Map(); - public timelines = new TimelineSet(this); + public timelines = new RoomTimelineSet(this); public events: Map = new Map(); public threads = new RoomThreads(this); // public members: Members; @@ -80,7 +72,21 @@ room.unban(userid) const events = data.timeline .filter(raw => !this.events.has(raw.event_id)) .map(raw => new Event(this, raw)); - this.timelines._appendEvents(events); + + for (const event of events) { + this.events.set(event.id, event); + this.timelines.live._eventList.push(...events); + for (const event of events) this.timelines.live.emit("timelineAppend", event); + + const threadId = event.content["m.relations"]?.find((rel: any) => rel.rel_type === "m.thread")?.event_id; + const thread = this.threads.get(threadId); + if (thread) { + thread.messageCount++; + thread.latestEvent = event; + thread.timelines.live._eventList.push(event); + thread.timelines.live.emit("timelineAppend", event); + } + } } } @@ -105,12 +111,12 @@ room.unban(userid) return new Promise((res) => { const sub = (event: Event) => { if (event.unsigned.transaction_id === txn) { - this.off("timeline", sub); + this.timelines.live.off("timelineAppend", sub); res(event); } }; - this.on("timeline", sub); + this.timelines.live.on("timelineAppend", sub); }) } diff --git a/src/setup.ts b/src/setup.ts index 66c1ca9..b3b7b4f 100644 --- a/src/setup.ts +++ b/src/setup.ts @@ -1,4 +1,94 @@ // Used for initiating a client, handling well-known and authentication. -class Setup { +/* +I'd love to rip this out and replace this with oidc a la "matrix 2.0", +but I'm not sure if that's a good idea yet. + +Benefits: + +1. It will be more secure since users won't enter credentials into random clients. +2. It separates concerns. + 2.1 client and server devs can focus on matrix instead of security best practices + 2.2 server admins can add new auth mechanisms without needing spec changes +3. I can use existing sdks and libraries to do authentication - rolling your own auth is a bad idea. + +Drawbacks: + +1. The ux will be worse since there's now a separtate place to do auth (login, register, manage sessions). +2. It will be much more complex. Server admins now have extra stuff to setup, maintain, and debug. Arguably, it's more difficult for client devs to use as well. +3. It forces users to have some kind of web browser to login. +*/ + +// TODO: properly integrate with net.js + +import { Client } from "./client.js"; + +type Flows = { + "m.login.password": { password: string, }, + "m.login.recaptcha": { response: string }, } + +type Identifier = + { type: "m.id.user", user: string } | + { type: string, [key: string]: any } + +export class Setup { + public baseUrl: string | null = null; + public endpoint: string | null = null; + public session: string | null = null; + public flows: Array | null = null; + public params: Record | null = null; + public identifier: Identifier | null = null; + + constructor( + public target: "login" | "register" | "guest", + public deviceName: string = "unnamed (sdk-ts)", + ) {} + + async useDomain(_domain: string) { + throw new Error("todo!"); + } + + async useBaseUrl(baseUrl: string) { + this.baseUrl = baseUrl; + this.endpoint = `${baseUrl}/_matrix/client/v3/${this.target === "login" ? "login" : "register"}${this.target === "guest" ? "?kind=guest" : ""}`; + const res = await fetch(this.endpoint).then(res => res.json()); + this.flows = res.flows; + this.params = res.params; + } + + useIdentifier(id: Identifier) { + this.identifier = id; + } + + async exec(type: K, options: Flows[K]): Promise { + if (!this.endpoint) throw new Error("you need to call useBaseUrl first"); + const res = await fetch(this.endpoint, { + body: JSON.stringify({ + identifier: this.identifier, + initial_device_display_name: this.deviceName, + session: this.session ?? undefined, + type: type, + ...options, + }), + method: "POST", + }).then(res => res.json()); + if (res.status === 400) { + this.session = res.session; + return null; + } else { + return new Client({ + baseUrl: this.baseUrl!, + token: res.access_token, + deviceId: res.device_id, + userId: res.user_id, + }); + } + } +} + +// const setup = new Setup("login"); +// // setup.useIdentifier({ type: "m.id.user", user: "@localpart:server.tld" }); +// setup.useIdentifier({ type: "m.id.user", user: "localpart" }); +// await setup.useBaseUrl("http://localhost:6167"); +// await setup.exec("m.login.password", { password: "a" }); diff --git a/src/sync.ts b/src/sync.ts index fd029d5..b44579f 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -25,6 +25,7 @@ export class Connection { ...this.query, }, this.controller.signal).catch((reason) => { if (reason === "update query") return null; + if (reason === "stop sync") return null; throw reason; }); if (!json) return; diff --git a/src/thread.ts b/src/thread.ts index f3485c9..241abfd 100644 --- a/src/thread.ts +++ b/src/thread.ts @@ -3,6 +3,7 @@ import TypedEmitter from "typed-emitter"; import { EventId, Unreads } from "./api.js"; import { Room } from "./room.js"; import { Event } from "./event.js"; +import { ThreadTimelineSet } from "./timeline.js"; type ThreadEvents = { // an event is appended to this thread's live timeline @@ -15,6 +16,7 @@ type ThreadEvents = { export class Thread extends (EventEmitter as unknown as new () => TypedEmitter) { public room: Room = this.baseEvent.room; public id = this.baseEvent.id; + public timelines = new ThreadTimelineSet(this); public participation = "participating"; public messageCount: number; diff --git a/src/timeline.ts b/src/timeline.ts index 7a8740e..b70f8a4 100644 --- a/src/timeline.ts +++ b/src/timeline.ts @@ -8,7 +8,7 @@ import { Thread } from "./thread.js"; import TypedEmitter from "typed-emitter"; import EventEmitter from "events"; -type TimelineEvents = { +type TimelineEvents = { // This room's live timeline is updated, usually via pagination. timelineUpdate: (batch: Array, toBeginning: boolean) => void, @@ -17,31 +17,12 @@ type TimelineEvents = { timelineAppend: (event: Event) => void, // This timeline has been merged with another timeline. - timelineReplace: (timeine: Timeline) => void, + timelineReplace: (timeine: T) => void, // An ephemeral event was received ephemeral: (event: ApiEphemeralEvent) => void, } -export interface Timeline extends TypedEmitter { - // if this timeline has reached the beginning (earliest event) - isAtBeginning: boolean, - - // if this timeline has reached the end (latest event) - // this timeline will also be live and receive new events - isAtEnd: boolean, - - // isPaginating: boolean, - - // Get the events in this timeline - getEvents(): Array, - - // Paginate a timeline for more events - // TODO: fuse two neighboring timelines together - // TODO: don't bother paginating if a timeline is at the end - paginate(dir: "f" | "b", limit: number): Promise; -} - const intoEvent = (room: Room) => (raw: ApiEvent): Event => { const existing = room.events.get(raw.event_id); if (existing) return existing; @@ -50,7 +31,7 @@ const intoEvent = (room: Room) => (raw: ApiEvent): Event => { return event; }; -export class RoomTimeline extends (EventEmitter as unknown as new () => TypedEmitter) implements Timeline { +abstract class Timeline extends (EventEmitter as unknown as new () => TypedEmitter>) { public isAtBeginning: boolean = false; public isAtEnd: boolean = false; @@ -59,14 +40,21 @@ export class RoomTimeline extends (EventEmitter as unknown as new () => TypedEmi prevBatch: string | undefined; nextBatch: string | undefined; - constructor(public room: Room) { - super(); - } - public getEvents(): Array { return this._eventList; } + public abstract paginate(dir: "f" | "b", limit: number): Promise; +} + +export class RoomTimeline extends Timeline implements TypedEmitter> { + constructor( + private timelineSet: RoomTimelineSet, + public room: Room, + ) { + super(); + } + public async paginate(dir: "f" | "b", limit: number = 50): Promise { if (dir === "b" && this.isAtBeginning) return false; if (dir === "f" && this.isAtEnd) return false; @@ -96,31 +84,29 @@ export class RoomTimeline extends (EventEmitter as unknown as new () => TypedEmi this.isAtBeginning = true; } this._eventList.unshift(...events); - for (const event of events) this.room.events.set(event.id, event); + for (const event of events) { + const existing = this.timelineSet.timelineMap.get(event.id); + if (existing) { + const otherIdx = existing.getEvents().indexOf(event); + if (otherIdx === -1) continue; + } else { + this.timelineSet.timelineMap.set(event.id, this); + this.room.events.set(event.id, event); + } + } this.emit("timelineUpdate", events, true); } return true; } } -export class ThreadTimeline extends (EventEmitter as unknown as new () => TypedEmitter) implements Timeline { - public isAtBeginning: boolean = false; - public isAtEnd: boolean = false; - - // private eventIdToTimeline: Map = new Map(); - - // These should be private, but typescript doesn't have "private to module" - _eventList: Array = []; - prevBatch: string | undefined; - nextBatch: string | undefined; - - constructor(public thread: Thread) { +export class ThreadTimeline extends Timeline implements TypedEmitter> { + constructor( + private timelineSet: ThreadTimelineSet, + public thread: Thread, + ) { super(); } - - public getEvents(): Array { - return this._eventList; - } public async paginate(dir: "f" | "b", limit: number = 50): Promise { if (dir === "b" && this.isAtBeginning) return false; @@ -153,107 +139,143 @@ export class ThreadTimeline extends (EventEmitter as unknown as new () => TypedE this.isAtBeginning = true; } this._eventList.unshift(...events); - for (const event of events) room.events.set(event.id, event); - - // TODO: make more performant - // const timelines = [...this.thread.room.timelines.timelines].filter(i => i instanceof ThreadTimeline && i.thread === this.thread) as Array; - // triple loops! - // this only definitely merges once backwards and once forwards, but that's fine since it would've already been merged anyways if there's multiple overlaps - // for (const timeline of timelines) { - // for (const event of events) { - // // this: [1, 2, 3, 4, 5] - // // other: [3, 4, 5, 6, 7, 8] - // const otherIdx = timeline.getEvents().indexOf(event); - // if (otherIdx === -1) continue; - // // const thisIdx = this._eventList.indexOf(event); - // // this._eventList - // } - // } - + for (const event of events) { + const existing = this.timelineSet.timelineMap.get(event.id); + if (existing) { + const otherIdx = existing.getEvents().indexOf(event); + if (otherIdx === -1) continue; + } else { + this.timelineSet.timelineMap.set(event.id, this); + room.events.set(event.id, event); + } + } this.emit("timelineUpdate", events, true); return !!data.prev_batch; } } } -export class TimelineSet { - // Other timelines *may* be live, but this one is guaranteed to be live - public live: RoomTimeline; - timelines: Set = new Set(); +abstract class TimelineSet { + abstract timelines: Set; + abstract timelineMap: Map; - constructor(public room: Room) { - this.live = new RoomTimeline(room); + merge(events: Array): Timeline | null { + for (const event of events) { + const tl = this.timelineMap.get(event.id); + if (!tl) continue; + return tl; + } + return null; + } +} + +export class ThreadTimelineSet extends TimelineSet { + // This is the one live timeline + public client = this.thread.room.client; + public live: ThreadTimeline; + timelines: Set = new Set(); + timelineMap: Map = new Map(); + + constructor(public thread: Thread) { + super(); + this.live = new ThreadTimeline(this, thread); this.live.isAtEnd = true; this.timelines.add(this.live); } - // Get a timeline for a thread. Becomes a live timeline if `atEnd = true`. - public async forThread(thread: Thread, at: EventId | "start" | "end"): Promise { + public async fetch(at: EventId | "start" | "end", limit = 50): Promise { if (at === "end") { - const existing = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.isAtEnd) as ThreadTimeline | undefined; - if (existing) return existing; - const tl = new ThreadTimeline(thread); - await tl.paginate("b"); - tl.isAtEnd = true; - return tl; + const fetchCount = limit - this.live.getEvents().length; + if (fetchCount > 0) await this.live.paginate("b", fetchCount); + return this.live; } else if (at === "start") { - const existing = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.isAtBeginning) as ThreadTimeline | undefined; - if (existing) return existing; - const tl = new ThreadTimeline(thread); - await tl.paginate("b"); - this.timelines.add(tl); - return tl; + const existing = [...this.timelines].find(i => i.isAtBeginning); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) await existing.paginate("f", fetchCount); + return existing; + } else { + const tl = new ThreadTimeline(this, this.thread); + await tl.paginate("b", limit); + this.timelines.add(tl); + return tl; + } } else { - const existing = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.getEvents().some(ev => ev.id === at)) as ThreadTimeline | undefined; - if (existing) return existing; - const tl = new ThreadTimeline(thread); - const context = await this.room.client.net.fetchContext(this.room.id, at, 0); - tl._eventList = [intoEvent(this.room)(context.event)]; - tl.prevBatch = context.start; - tl.nextBatch = context.end; - this.timelines.add(tl); - return tl; - } - } - - // Get a timeline for an event (context). - public async forEvent(eventId: EventId): Promise { - const existing = [...this.timelines].find(tl => tl instanceof RoomTimeline && tl.getEvents().some(ev => ev.id === eventId)) as RoomTimeline | undefined; - if (existing) return existing; - const context = await this.room.client.net.fetchContext(this.room.id, eventId); - const tl = new RoomTimeline(this.room); - const events = context.events_before - .reverse() - .concat([context.event]) - .concat(context.events_after) - .map(intoEvent(this.room)); - tl._eventList = events; - tl.prevBatch = context.start; - tl.nextBatch = context.end; - this.timelines.add(tl); - return tl; - } - - _appendEvents(events: Array) { - // FIXME: there should only be one live timeline for each room and - // thread, they need to be merged together - for (const event of events) { - this.room.events.set(event.id, event); - - this.live._eventList.push(...events); - for (const event of events) this.live.emit("timelineAppend", event); - - const threadId = event.content["m.relations"]?.find((rel: any) => rel.rel_type === "m.thread")?.event_id; - const thread = this.room.threads.get(threadId); - if (thread) { - thread.messageCount++; - thread.latestEvent = event; - - const tl = [...this.timelines].find(i => i instanceof ThreadTimeline && i.thread === thread && i.isAtEnd) as ThreadTimeline | undefined; - if (tl) { - tl._eventList.push(event); - tl.emit("timelineAppend", event); - } + // TODO: respect limit? + const existing = this.timelineMap.get(at); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) await existing.paginate("f", fetchCount); + return existing; + } else { + const tl = new ThreadTimeline(this, this.thread); + const context = await this.client.net.fetchContext(this.thread.room.id, at, 0); + const event = intoEvent(this.thread.room)(context.event); + tl._eventList = [event]; + tl.prevBatch = context.start; + tl.nextBatch = context.end; + this.timelineMap.set(event.id, tl); + this.timelines.add(tl); + return tl; + } + } + } +} + +export class RoomTimelineSet extends TimelineSet { + // Other timelines *may* be live, but this one is guaranteed to be live + public client = this.room.client; + public live: RoomTimeline; + timelines: Set = new Set(); + timelineMap: Map = new Map(); + + constructor(public room: Room) { + super(); + this.live = new RoomTimeline(this, room); + this.live.isAtEnd = true; + this.timelines.add(this.live); + } + + // Get a timeline for an event (context). + public async fetch(at: EventId | "start" | "end", limit = 50): Promise { + if (at === "end") { + const fetchCount = limit - this.live.getEvents().length; + if (fetchCount > 0) await this.live.paginate("b", fetchCount); + return this.live; + } else if (at === "start") { + const existing = [...this.timelines].find(i => i.isAtBeginning); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) await existing.paginate("f", fetchCount); + return existing; + } else { + const tl = new RoomTimeline(this, this.room); + await tl.paginate("b", limit); + this.timelines.add(tl); + return tl; + } + } else { + // TODO: respect limit? + const existing = this.timelineMap.get(at); + if (existing) { + const fetchCount = limit - existing.getEvents().length; + if (fetchCount > 0) await existing.paginate("f", fetchCount); + return existing; + } else { + const context = await this.client.net.fetchContext(this.room.id, at); + const tl = new RoomTimeline(this, this.room); + const events = context.events_before + .reverse() + .concat([context.event]) + .concat(context.events_after) + .map(intoEvent(this.room)); + tl._eventList = events; + tl.prevBatch = context.start; + tl.nextBatch = context.end; + this.timelines.add(tl); + // FIXME: merge timelines + for (const event of events) this.timelineMap.set(event.id, tl); + return tl; } } }