From cb0b492d6a92155988e5ac8bd61691bb699acdfe Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 22 Feb 2022 17:54:04 +0000 Subject: [PATCH 1/2] Add new room state emit RoomStateEvent.Update for lower-frequency hits --- src/client.ts | 3 ++- src/models/room-state.ts | 5 +++++ src/sync.ts | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index 5e3b4e1e93..d230356c39 100644 --- a/src/client.ts +++ b/src/client.ts @@ -799,7 +799,8 @@ type RoomEvents = RoomEvent.Name type RoomStateEvents = RoomStateEvent.Events | RoomStateEvent.Members - | RoomStateEvent.NewMember; + | RoomStateEvent.NewMember + | RoomStateEvent.Update; type CryptoEvents = CryptoEvent.KeySignatureUploadFailure | CryptoEvent.KeyBackupStatus diff --git a/src/models/room-state.ts b/src/models/room-state.ts index 59bf1ae011..93c76df728 100644 --- a/src/models/room-state.ts +++ b/src/models/room-state.ts @@ -38,12 +38,14 @@ export enum RoomStateEvent { Events = "RoomState.events", Members = "RoomState.members", NewMember = "RoomState.newMember", + Update = "RoomState.update", // signals batches of updates without specificity } export type RoomStateEventHandlerMap = { [RoomStateEvent.Events]: (event: MatrixEvent, state: RoomState, lastStateEvent: MatrixEvent | null) => void; [RoomStateEvent.Members]: (event: MatrixEvent, state: RoomState, member: RoomMember) => void; [RoomStateEvent.NewMember]: (event: MatrixEvent, state: RoomState, member: RoomMember) => void; + [RoomStateEvent.Update]: (state: RoomState) => void; }; export class RoomState extends TypedEventEmitter { @@ -376,6 +378,8 @@ export class RoomState extends TypedEventEmitter this.setOutOfBandMember(e)); + this.emit(RoomStateEvent.Update, this); } /** diff --git a/src/sync.ts b/src/sync.ts index 043dfc62c0..f275e4f34b 100644 --- a/src/sync.ts +++ b/src/sync.ts @@ -240,6 +240,7 @@ export class SyncApi { RoomStateEvent.Events, RoomStateEvent.Members, RoomStateEvent.NewMember, + RoomStateEvent.Update, ]); room.currentState.on(RoomStateEvent.NewMember, function(event, state, member) { member.user = client.getUser(member.userId); From 1ae32790a2b1d96ef7c8f2c739f028d7357fc221 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 22 Feb 2022 20:13:11 +0000 Subject: [PATCH 2/2] Update src/client.ts Co-authored-by: Travis Ralston --- src/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index d230356c39..8bc1a62a92 100644 --- a/src/client.ts +++ b/src/client.ts @@ -800,7 +800,8 @@ type RoomEvents = RoomEvent.Name type RoomStateEvents = RoomStateEvent.Events | RoomStateEvent.Members | RoomStateEvent.NewMember - | RoomStateEvent.Update; + | RoomStateEvent.Update + ; type CryptoEvents = CryptoEvent.KeySignatureUploadFailure | CryptoEvent.KeyBackupStatus