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 5e3b4e1e939..d230356c394 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 59bf1ae0115..93c76df7289 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 043dfc62c04..f275e4f34b3 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 d230356c394..8bc1a62a92b 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