Skip to content

Commit

Permalink
Add new room state emit RoomStateEvent.Update for lower-frequency hits (
Browse files Browse the repository at this point in the history
#2192)

Co-authored-by: Travis Ralston <travisr@matrix.org>
  • Loading branch information
t3chguy and turt2live authored Feb 24, 2022
1 parent 3d9221f commit 4de1699
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,9 @@ type RoomEvents = RoomEvent.Name

type RoomStateEvents = RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NewMember;
| RoomStateEvent.NewMember
| RoomStateEvent.Update
;

type CryptoEvents = CryptoEvent.KeySignatureUploadFailure
| CryptoEvent.KeyBackupStatus
Expand Down
5 changes: 5 additions & 0 deletions src/models/room-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RoomStateEvent, RoomStateEventHandlerMap> {
Expand Down Expand Up @@ -376,6 +378,8 @@ export class RoomState extends TypedEventEmitter<RoomStateEvent, RoomStateEventH
this.sentinels = {};
}
});

this.emit(RoomStateEvent.Update, this);
}

/**
Expand Down Expand Up @@ -485,6 +489,7 @@ export class RoomState extends TypedEventEmitter<RoomStateEvent, RoomStateEventH
logger.log(`LL: RoomState put in finished state ...`);
this.oobMemberFlags.status = OobStatus.Finished;
stateEvents.forEach((e) => this.setOutOfBandMember(e));
this.emit(RoomStateEvent.Update, this);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4de1699

Please sign in to comment.