Skip to content

Commit

Permalink
Merge pull request #674 from matrix-org/bwindels/backport_infinite_sp…
Browse files Browse the repository at this point in the history
…inner_fix

back-port infinite spinner fix for lazy loading
  • Loading branch information
bwindels authored Jul 31, 2018
2 parents e671697 + 8a59813 commit 8b2a339
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions src/models/room-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,14 +323,8 @@ RoomState.prototype.setStateEvents = function(stateEvents) {
event.getPrevContent().displayname;
}

let member = self.members[userId];
if (!member) {
member = new RoomMember(event.getRoomId(), userId);
self.emit("RoomState.newMember", event, self, member);
}

const member = self._getOrCreateMember(userId, event);
member.setMembershipEvent(event, self);

// if out of band members are loading,
// mark the member as more recent
if (self._oobMemberFlags.status == OOB_STATUS_INPROGRESS) {
Expand All @@ -352,6 +346,28 @@ RoomState.prototype.setStateEvents = function(stateEvents) {
});
};

/**
* Looks up a member by the given userId, and if it doesn't exist,
* create it and emit the `RoomState.newMember` event.
* This method makes sure the member is added to the members dictionary
* before emitting, as this is done from setStateEvents and _setOutOfBandMember.
* @param {string} userId the id of the user to look up
* @param {MatrixEvent} event the membership event for the (new) member. Used to emit.
* @fires module:client~MatrixClient#event:"RoomState.newMember"
* @returns {RoomMember} the member, existing or newly created.
*/
RoomState.prototype._getOrCreateMember = function(userId, event) {
let member = this.members[userId];
if (!member) {
member = new RoomMember(this.roomId, userId);
// add member to members before emitting any events,
// as event handlers often lookup the member
this.members[userId] = member;
this.emit("RoomState.newMember", event, this, member);
}
return member;
};

RoomState.prototype._setStateEvent = function(event) {
if (this.events[event.getType()] === undefined) {
this.events[event.getType()] = {};
Expand Down Expand Up @@ -450,8 +466,7 @@ RoomState.prototype._setOutOfBandMember = function(stateEvent) {
}
}

const member =
existingMember ? existingMember : new RoomMember(this.roomId, userId);
const member = this._getOrCreateMember(userId, stateEvent);
member.setMembershipEvent(stateEvent);
// needed to know which members need to be stored seperately
// as the are not part of the sync accumulator
Expand All @@ -462,12 +477,7 @@ RoomState.prototype._setOutOfBandMember = function(stateEvent) {

this._setStateEvent(stateEvent);
this._updateMember(member);

if (existingMember) {
this.emit("RoomState.members", {}, this, member);
} else {
this.emit('RoomState.newMember', {}, this, member);
}
this.emit("RoomState.members", {}, stateEvent, member);
};

/**
Expand Down

0 comments on commit 8b2a339

Please sign in to comment.