Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new room state emit RoomStateEvent.Update for lower-frequency hits #2192

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -799,7 +799,8 @@ type RoomEvents = RoomEvent.Name

type RoomStateEvents = RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NewMember;
| RoomStateEvent.NewMember
| RoomStateEvent.Update;
t3chguy marked this conversation as resolved.
Show resolved Hide resolved

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