do all collection removal from sync rather than hand callbacks to invite

This commit is contained in:
Bruno Windels 2021-05-05 16:50:45 +02:00
parent 12da71f731
commit 89461bf69a
3 changed files with 14 additions and 7 deletions

View file

@ -55,7 +55,6 @@ export class Session {
this._rooms = new ObservableMap();
this._roomUpdateCallback = (room, params) => this._rooms.update(room.id, params);
this._invites = new ObservableMap();
this._inviteRemoveCallback = invite => this._invites.remove(invite.id);
this._inviteUpdateCallback = (invite, params) => this._invites.update(invite.id, params);
this._user = new User(sessionInfo.userId);
this._deviceMessageHandler = new DeviceMessageHandler({storage});
@ -410,7 +409,6 @@ export class Session {
return new Invite({
roomId,
hsApi: this._hsApi,
emitCollectionRemove: this._inviteRemoveCallback,
emitCollectionUpdate: this._inviteUpdateCallback,
mediaRepository: this._mediaRepository,
user: this._user,
@ -423,6 +421,11 @@ export class Session {
this._invites.add(invite.id, invite);
}
/** @internal */
removeInviteAfterSync(invite) {
this._invites.remove(invite.id);
}
async obtainSyncLock(syncResponse) {
const toDeviceEvents = syncResponse.to_device?.events;
if (Array.isArray(toDeviceEvents) && toDeviceEvents.length) {

View file

@ -299,7 +299,15 @@ export class Sync {
}
// emit invite related events after txn has been closed
for(let is of inviteStates) {
log.wrap("invite", () => is.invite.afterSync(is.changes), log.level.Detail);
log.wrap("invite", () => {
// important to remove before emitting change in afterSync
// so code checking session.invites.get(id) won't
// find the invite anymore on update
if (is.membership !== "invite") {
this._session.removeInviteAfterSync(is.invite);
}
is.invite.afterSync(is.changes);
}, log.level.Detail);
if (is.isNewInvite) {
this._session.addInviteAfterSync(is.invite);
}

View file

@ -162,10 +162,6 @@ export class Invite extends EventEmitter {
} else {
this._rejected = true;
}
// important to remove before emitting change
// so code checking session.invites.get(id) won't
// find the invite anymore on update
this._emitCollectionRemove(this);
this.emit("change");
} else {
this._inviteData = changes.inviteData;