Skip to content

Commit

Permalink
Embeded mode pre-requisites
Browse files Browse the repository at this point in the history
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
  • Loading branch information
SimonBrandner committed Aug 28, 2023
1 parent 1a0718f commit 8cd7370
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/@types/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export enum EventType {
CallReplaces = "m.call.replaces",
CallAssertedIdentity = "m.call.asserted_identity",
CallAssertedIdentityPrefix = "org.matrix.call.asserted_identity",
CallEncryptionPrefix = "io.element.call.encryption_key",
KeyVerificationRequest = "m.key.verification.request",
KeyVerificationStart = "m.key.verification.start",
KeyVerificationCancel = "m.key.verification.cancel",
Expand Down
1 change: 1 addition & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -908,6 +908,7 @@ type RoomEvents =
type RoomStateEvents =
| RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NoLongerMember
| RoomStateEvent.NewMember
| RoomStateEvent.Update
| RoomStateEvent.Marker;
Expand Down
10 changes: 10 additions & 0 deletions src/models/room-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export enum RoomStateEvent {
Events = "RoomState.events",
Members = "RoomState.members",
NewMember = "RoomState.newMember",
NoLongerMember = "RoomState.noLongerMember",
Update = "RoomState.update", // signals batches of updates without specificity
BeaconLiveness = "RoomState.BeaconLiveness",
Marker = "RoomState.Marker",
Expand Down Expand Up @@ -120,6 +121,7 @@ export type RoomStateEventHandlerMap = {
* ```
*/
[RoomStateEvent.NewMember]: (event: MatrixEvent, state: RoomState, member: RoomMember) => void;
[RoomStateEvent.NoLongerMember]: (event: MatrixEvent, state: RoomState, member: RoomMember) => void;
[RoomStateEvent.Update]: (state: RoomState) => void;
[RoomStateEvent.BeaconLiveness]: (state: RoomState, hasLiveBeacons: boolean) => void;
[RoomStateEvent.Marker]: (event: MatrixEvent, setStateOptions?: IMarkerFoundOptions) => void;
Expand Down Expand Up @@ -436,8 +438,12 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
}

const member = this.getOrCreateMember(userId, event);
const oldMembership = member.membership;
member.setMembershipEvent(event, this);
this.updateMember(member);
if (oldMembership === "join" && ["leave", "ban"].includes(member.membership as string)) {
this.emit(RoomStateEvent.NoLongerMember, event, this, member);
}
this.emit(RoomStateEvent.Members, event, this, member);
} else if (event.getType() === EventType.RoomPowerLevels) {
// events with unknown state keys should be ignored
Expand Down Expand Up @@ -704,7 +710,11 @@ export class RoomState extends TypedEventEmitter<EmittedEvents, EventHandlerMap>
}

const member = this.getOrCreateMember(userId, stateEvent);
const oldMembership = member.membership;
member.setMembershipEvent(stateEvent, this);
if (oldMembership === "join" && ["leave", "ban"].includes(member.membership as string)) {
this.emit(RoomStateEvent.NoLongerMember, stateEvent, this, member);
}
// needed to know which members need to be stored seperately
// as they are not part of the sync accumulator
// this is cleared by setMembershipEvent so when it's updated through /sync
Expand Down
4 changes: 4 additions & 0 deletions src/models/room.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export type RoomEmittedEvents =
| RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NewMember
| RoomStateEvent.NoLongerMember
| RoomStateEvent.Update
| RoomStateEvent.Marker
| ThreadEvent.New
Expand Down Expand Up @@ -304,6 +305,7 @@ export type RoomEventHandlerMap = {
| RoomStateEvent.Events
| RoomStateEvent.Members
| RoomStateEvent.NewMember
| RoomStateEvent.NoLongerMember
| RoomStateEvent.Update
| RoomStateEvent.Marker
| BeaconEvent.New
Expand Down Expand Up @@ -1228,6 +1230,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
RoomStateEvent.Events,
RoomStateEvent.Members,
RoomStateEvent.NewMember,
RoomStateEvent.NoLongerMember,
RoomStateEvent.Update,
RoomStateEvent.Marker,
BeaconEvent.New,
Expand All @@ -1239,6 +1242,7 @@ export class Room extends ReadReceipt<RoomEmittedEvents, RoomEventHandlerMap> {
RoomStateEvent.Events,
RoomStateEvent.Members,
RoomStateEvent.NewMember,
RoomStateEvent.NoLongerMember,
RoomStateEvent.Update,
RoomStateEvent.Marker,
BeaconEvent.New,
Expand Down

0 comments on commit 8cd7370

Please sign in to comment.