Skip to content

Commit 7d4bfbc

Browse files
committed
Helper to help components spit out debug logs
Part of matrix-org/matrix-react-sdk#8502
1 parent a388fde commit 7d4bfbc

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/client.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ export enum ClientEvent {
784784
DeleteRoom = "deleteRoom",
785785
SyncUnexpectedError = "sync.unexpectedError",
786786
ClientWellKnown = "WellKnown.client",
787+
DumpDebugLogs = "logging.dumpDebugLogs",
787788
}
788789

789790
type RoomEvents = RoomEvent.Name
@@ -852,6 +853,7 @@ export type ClientEventHandlerMap = {
852853
[ClientEvent.DeleteRoom]: (roomId: string) => void;
853854
[ClientEvent.SyncUnexpectedError]: (error: Error) => void;
854855
[ClientEvent.ClientWellKnown]: (data: IClientWellKnown) => void;
856+
[ClientEvent.DumpDebugLogs]: () => void;
855857
} & RoomEventHandlerMap
856858
& RoomStateEventHandlerMap
857859
& CryptoEventHandlerMap
@@ -8963,6 +8965,11 @@ export class MatrixClient extends TypedEventEmitter<EmittedEvents, ClientEventHa
89638965
},
89648966
);
89658967
}
8968+
8969+
public dumpDebugLogs() {
8970+
logger.debug('matrix-js-sdk: dumping extra debug logs to the console');
8971+
this.emit(ClientEvent.DumpDebugLogs);
8972+
}
89668973
}
89678974

89688975
/**

src/models/room.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,13 @@ export class Room extends TypedEventEmitter<EmittedEvents, RoomEventHandlerMap>
12161216
return Array.from(this.threads.values());
12171217
}
12181218

1219+
/**
1220+
* @experimental
1221+
*/
1222+
public getThreadsMap(): Map<string, Thread> {
1223+
return this.threads;
1224+
}
1225+
12191226
/**
12201227
* Get a member from the current room state.
12211228
* @param {string} userId The user ID of the member.

src/timeline-window.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ limitations under the License.
1818

1919
import { Direction, EventTimeline } from './models/event-timeline';
2020
import { logger } from './logger';
21-
import { MatrixClient } from "./client";
21+
import { MatrixClient, ClientEvent } from "./client";
2222
import { EventTimelineSet } from "./models/event-timeline-set";
2323
import { MatrixEvent } from "./models/event";
2424

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

4242
interface IOpts {
4343
windowLimit?: number;
44+
// A label used in the logs to namespace and differentiate the timelines.
45+
//ex. main timeline from the thread timeline.
46+
contextLabel?: string;
4447
}
4548

4649
export class TimelineWindow {
4750
private readonly windowLimit: number;
51+
private readonly contextLabel: string;
4852
// these will be TimelineIndex objects; they delineate the 'start' and
4953
// 'end' of the window.
5054
//
@@ -80,14 +84,26 @@ export class TimelineWindow {
8084
* in the window. If more events are retrieved via pagination requests,
8185
* excess events will be dropped from the other end of the window.
8286
*
87+
* @param {number} [opts.contextLabel] A label used in the logs to namespace
88+
* and differentiate the timelines. ex. main timeline from the thread timeline.
89+
*
8390
* @constructor
8491
*/
8592
constructor(
8693
private readonly client: MatrixClient,
8794
private readonly timelineSet: EventTimelineSet,
8895
opts: IOpts = {},
8996
) {
97+
console.log('timeline-window', opts);
9098
this.windowLimit = opts.windowLimit || 1000;
99+
this.contextLabel = opts.contextLabel || '';
100+
101+
// TODO: Unbind this when the object is destroyed
102+
client.on(ClientEvent.DumpDebugLogs, this.onDumpDebugLogs);
103+
}
104+
105+
private onDumpDebugLogs = (): void => {
106+
logger.debug(`timeline-window(${this.contextLabel}): TODO: dumpDebugLogs`);
91107
}
92108

93109
/**

0 commit comments

Comments
 (0)