1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

clear out of band members in store when leaving room

This commit is contained in:
Bruno Windels
2018-08-31 14:41:25 +02:00
parent f8ea1702f8
commit 7258fe4e5c
3 changed files with 28 additions and 0 deletions

View File

@@ -457,6 +457,29 @@ Room.prototype.loadMembersIfNeeded = function() {
return this._membersPromise; return this._membersPromise;
}; };
/**
* Removes the lazily loaded members from storage if needed
*/
Room.prototype.clearLoadedMembersIfNeeded = async function() {
if (this._opts.lazyLoadMembers && this._membersPromise) {
await this.loadMembersIfNeeded();
this._membersPromise = null;
await this._client.store.clearOutOfBandMembers(this.roomId);
}
};
/**
* called when sync receives this room in the leave section
* to do cleanup after leaving a room. Possibly called multiple times.
*/
Room.prototype.onLeft = function() {
this.clearLoadedMembersIfNeeded().catch((err) => {
console.error(`error after clearing loaded members from ` +
`room ${this.roomId} after leaving`);
console.dir(err);
});
};
/** /**
* Reset the live timeline of all timelineSets, and start new ones. * Reset the live timeline of all timelineSets, and start new ones.
* *

View File

@@ -272,6 +272,10 @@ StubStore.prototype = {
setOutOfBandMembers: function() { setOutOfBandMembers: function() {
return Promise.resolve(); return Promise.resolve();
}, },
clearOutOfBandMembers: function() {
return Promise.resolve();
},
}; };
/** Stub Store class. */ /** Stub Store class. */

View File

@@ -1106,6 +1106,7 @@ SyncApi.prototype._processSyncResponse = async function(
leaveRooms.forEach(function(leaveObj) { leaveRooms.forEach(function(leaveObj) {
const room = leaveObj.room; const room = leaveObj.room;
room.setSyncedMembership("leave"); room.setSyncedMembership("leave");
room.onLeft();
const stateEvents = const stateEvents =
self._mapSyncEventsFormat(leaveObj.state, room); self._mapSyncEventsFormat(leaveObj.state, room);