From 7258fe4e5c16ed889296dbe00d0d2694fdc4b98c Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Fri, 31 Aug 2018 14:41:25 +0200 Subject: [PATCH] clear out of band members in store when leaving room --- src/models/room.js | 23 +++++++++++++++++++++++ src/store/stub.js | 4 ++++ src/sync.js | 1 + 3 files changed, 28 insertions(+) diff --git a/src/models/room.js b/src/models/room.js index 705e86bfc..2d253d64e 100644 --- a/src/models/room.js +++ b/src/models/room.js @@ -457,6 +457,29 @@ Room.prototype.loadMembersIfNeeded = function() { 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. * diff --git a/src/store/stub.js b/src/store/stub.js index 9c628b287..d0c2cabc5 100644 --- a/src/store/stub.js +++ b/src/store/stub.js @@ -272,6 +272,10 @@ StubStore.prototype = { setOutOfBandMembers: function() { return Promise.resolve(); }, + + clearOutOfBandMembers: function() { + return Promise.resolve(); + }, }; /** Stub Store class. */ diff --git a/src/sync.js b/src/sync.js index 4aa2d2482..b500ff316 100644 --- a/src/sync.js +++ b/src/sync.js @@ -1106,6 +1106,7 @@ SyncApi.prototype._processSyncResponse = async function( leaveRooms.forEach(function(leaveObj) { const room = leaveObj.room; room.setSyncedMembership("leave"); + room.onLeft(); const stateEvents = self._mapSyncEventsFormat(leaveObj.state, room);