1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-26 17:03:12 +03:00

store /members promise on room while loading members

This commit is contained in:
Bruno Windels
2018-08-06 17:16:13 +02:00
parent 6609dfd410
commit 3616a07dbb

View File

@@ -175,6 +175,8 @@ function Room(roomId, myUserId, opts) {
this._blacklistUnverifiedDevices = null; this._blacklistUnverifiedDevices = null;
this._syncedMembership = null; this._syncedMembership = null;
this._summaryHeroes = null; this._summaryHeroes = null;
// awaited by getEncryptionTargetMembers while room mebers are loading
this._oobMembersPromise = null;
} }
utils.inherits(Room, EventEmitter); utils.inherits(Room, EventEmitter);
@@ -283,19 +285,21 @@ Room.prototype.needsOutOfBandMembers = function() {
* Loads the out-of-band members from the promise passed in * Loads the out-of-band members from the promise passed in
* @param {Promise} eventsPromise promise that resolves to an array with membership MatrixEvents for the members * @param {Promise} eventsPromise promise that resolves to an array with membership MatrixEvents for the members
*/ */
Room.prototype.loadOutOfBandMembers = async function(eventsPromise) { Room.prototype.loadOutOfBandMembers = function(eventsPromise) {
if (!this.needsOutOfBandMembers()) { if (!this.needsOutOfBandMembers()) {
return; return Promise.resolve();
} }
this.currentState.markOutOfBandMembersStarted(); this.currentState.markOutOfBandMembersStarted();
let events = null;
try { // store the promise that already updated the room state
events = await eventsPromise; // to ensure that happens first
} catch (err) { this._oobMembersPromise = eventsPromise.then((events) => {
this.currentState.setOutOfBandMembers(events);
}, (err) => {
this.currentState.markOutOfBandMembersFailed(); this.currentState.markOutOfBandMembersFailed();
throw err; //rethrow so calling code is aware operation failed throw err; //rethrow so calling code is aware operation failed
} });
this.currentState.setOutOfBandMembers(events); return this._oobMembersPromise;
}; };
/** /**