Skip to content

Commit

Permalink
Helper to help components spit out debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed May 5, 2022
1 parent a388fde commit 7d4bfbc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ export enum ClientEvent {
DeleteRoom = "deleteRoom",
SyncUnexpectedError = "sync.unexpectedError",
ClientWellKnown = "WellKnown.client",
DumpDebugLogs = "logging.dumpDebugLogs",
}

type RoomEvents = RoomEvent.Name
Expand Down Expand Up @@ -852,6 +853,7 @@ export type ClientEventHandlerMap = {
[ClientEvent.DeleteRoom]: (roomId: string) => void;
[ClientEvent.SyncUnexpectedError]: (error: Error) => void;
[ClientEvent.ClientWellKnown]: (data: IClientWellKnown) => void;
[ClientEvent.DumpDebugLogs]: () => void;
} & RoomEventHandlerMap
& RoomStateEventHandlerMap
& CryptoEventHandlerMap
Expand Down Expand Up @@ -8963,6 +8965,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
},
);
}

public dumpDebugLogs() {
logger.debug('matrix-js-sdk: dumping extra debug logs to the console');
this.emit(ClientEvent.DumpDebugLogs);
}
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,13 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
return Array.from(this.threads.values());
}

/**
* @experimental
*/
public getThreadsMap(): Map<string, Thread> {
return this.threads;
}

/**
* Get a member from the current room state.
* @param {string} userId The user ID of the member.
Expand Down
18 changes: 17 additions & 1 deletion src/timeline-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.

import { Direction, EventTimeline } from './models/event-timeline';
import { logger } from './logger';
import { MatrixClient } from "./client";
import { MatrixClient, ClientEvent } from "./client";
import { EventTimelineSet } from "./models/event-timeline-set";
import { MatrixEvent } from "./models/event";

Expand All @@ -41,10 +41,14 @@ const DEFAULT_PAGINATE_LOOP_LIMIT = 5;

interface IOpts {
windowLimit?: number;
// A label used in the logs to namespace and differentiate the timelines.
//ex. main timeline from the thread timeline.
contextLabel?: string;
}

export class TimelineWindow {
private readonly windowLimit: number;
private readonly contextLabel: string;
// these will be TimelineIndex objects; they delineate the 'start' and
// 'end' of the window.
//
Expand Down Expand Up @@ -80,14 +84,26 @@ export class TimelineWindow {
* in the window. If more events are retrieved via pagination requests,
* excess events will be dropped from the other end of the window.
*
* @param {number} [opts.contextLabel] A label used in the logs to namespace
* and differentiate the timelines. ex. main timeline from the thread timeline.
*
* @constructor
*/
constructor(
private readonly client: MatrixClient,
private readonly timelineSet: EventTimelineSet,
opts: IOpts = {},
) {
console.log('timeline-window', opts);
this.windowLimit = opts.windowLimit || 1000;
this.contextLabel = opts.contextLabel || '';

// TODO: Unbind this when the object is destroyed
client.on(ClientEvent.DumpDebugLogs, this.onDumpDebugLogs);
}

private onDumpDebugLogs = (): void => {
logger.debug(`timeline-window(${this.contextLabel}): TODO: dumpDebugLogs`);
}

/**
Expand Down

0 comments on commit 7d4bfbc

Please sign in to comment.