You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-28 05:03:59 +03:00
Support for updating members in RoomState from lazily loaded members
This commit is contained in:
@@ -228,15 +228,7 @@ RoomState.prototype.setStateEvents = function(stateEvents) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
member.setMembershipEvent(event, self);
|
member.setMembershipEvent(event, self);
|
||||||
// this member may have a power level already, so set it.
|
self._updateMember(member);
|
||||||
const pwrLvlEvent = self.getStateEvents("m.room.power_levels", "");
|
|
||||||
if (pwrLvlEvent) {
|
|
||||||
member.setPowerLevelEvent(pwrLvlEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
// blow away the sentinel which is now outdated
|
|
||||||
delete self._sentinels[userId];
|
|
||||||
|
|
||||||
self.emit("RoomState.members", event, self, member);
|
self.emit("RoomState.members", event, self, member);
|
||||||
} else if (event.getType() === "m.room.power_levels") {
|
} else if (event.getType() === "m.room.power_levels") {
|
||||||
const members = utils.values(self.members);
|
const members = utils.values(self.members);
|
||||||
@@ -251,6 +243,35 @@ RoomState.prototype.setStateEvents = function(stateEvents) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RoomState.prototype._updateMember = function(member) {
|
||||||
|
// this member may have a power level already, so set it.
|
||||||
|
const pwrLvlEvent = this.getStateEvents("m.room.power_levels", "");
|
||||||
|
if (pwrLvlEvent) {
|
||||||
|
member.setPowerLevelEvent(pwrLvlEvent);
|
||||||
|
}
|
||||||
|
|
||||||
|
// blow away the sentinel which is now outdated
|
||||||
|
delete this._sentinels[member.userId];
|
||||||
|
|
||||||
|
this.members[member.userId] = member;
|
||||||
|
this._joinedMemberCount = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
RoomState.prototype.setJoinedMembers = function(joinedMembers) {
|
||||||
|
const joinedRoomMembers = Object.entries(joinedMembers).map(([userId, details]) => {
|
||||||
|
const displayName = details.display_name;
|
||||||
|
const avatarUrl = details.avatar_url;
|
||||||
|
const member = new RoomMember(this.roomId, userId);
|
||||||
|
member.setAsJoinedMember(displayName, avatarUrl, this);
|
||||||
|
return member;
|
||||||
|
});
|
||||||
|
joinedRoomMembers.forEach(member => {
|
||||||
|
_updateDisplayNameCache(this, member.userId, member.name);
|
||||||
|
this._updateMember(member);
|
||||||
|
});
|
||||||
|
this.emit("Room");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current typing event for this room.
|
* Set the current typing event for this room.
|
||||||
* @param {MatrixEvent} event The typing event
|
* @param {MatrixEvent} event The typing event
|
||||||
|
|||||||
Reference in New Issue
Block a user