postpone loading the members until the user joined the room
when peeking, the members weren't being loaded at all because the room wasn't available yet, and the need for loading the members was never re-evaluated after that. This only loads the members once the user has joined the room, which also helps to avoid load all the members before an invite is accepted.
This commit is contained in:
parent
518be24a5b
commit
f194f323f4
2 changed files with 56 additions and 28 deletions
|
@ -314,16 +314,6 @@ module.exports = React.createClass({
|
||||||
// Stop peeking because we have joined this room previously
|
// Stop peeking because we have joined this room previously
|
||||||
MatrixClientPeg.get().stopPeeking();
|
MatrixClientPeg.get().stopPeeking();
|
||||||
this.setState({isPeeking: false});
|
this.setState({isPeeking: false});
|
||||||
|
|
||||||
// lazy load members if enabled
|
|
||||||
if (SettingsStore.isFeatureEnabled('feature_lazyloading')) {
|
|
||||||
room.loadMembersIfNeeded().catch((err) => {
|
|
||||||
const errorMessage = `Fetching room members for ${room.roomId} failed.` +
|
|
||||||
" Room members will appear incomplete.";
|
|
||||||
console.error(errorMessage);
|
|
||||||
console.error(err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -592,6 +582,23 @@ module.exports = React.createClass({
|
||||||
this._warnAboutEncryption(room);
|
this._warnAboutEncryption(room);
|
||||||
this._calculatePeekRules(room);
|
this._calculatePeekRules(room);
|
||||||
this._updatePreviewUrlVisibility(room);
|
this._updatePreviewUrlVisibility(room);
|
||||||
|
this._loadMembersIfJoined();
|
||||||
|
},
|
||||||
|
|
||||||
|
_loadMembersIfJoined: function() {
|
||||||
|
// lazy load members if enabled
|
||||||
|
if (SettingsStore.isFeatureEnabled('feature_lazyloading')) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const room = cli.getRoom(this.state.roomId);
|
||||||
|
if (room && room.getMyMembership() === 'join') {
|
||||||
|
room.loadMembersIfNeeded().catch((err) => {
|
||||||
|
const errorMessage = `Fetching room members for ${room.roomId} failed.` +
|
||||||
|
" Room members will appear incomplete.";
|
||||||
|
console.error(errorMessage);
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_warnAboutEncryption: function(room) {
|
_warnAboutEncryption: function(room) {
|
||||||
|
@ -705,6 +712,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
onRoomMemberMembership: function(ev, member, oldMembership) {
|
onRoomMemberMembership: function(ev, member, oldMembership) {
|
||||||
if (member.userId == MatrixClientPeg.get().credentials.userId) {
|
if (member.userId == MatrixClientPeg.get().credentials.userId) {
|
||||||
|
this._loadMembersIfJoined();
|
||||||
this.forceUpdate();
|
this.forceUpdate();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -46,6 +46,8 @@ module.exports = React.createClass({
|
||||||
if (!cli.hasLazyLoadMembersEnabled()) {
|
if (!cli.hasLazyLoadMembersEnabled()) {
|
||||||
this._listenForMembersChanges();
|
this._listenForMembersChanges();
|
||||||
}
|
}
|
||||||
|
cli.on("Room", this.onRoom); // invites & joining after peek
|
||||||
|
cli.on("RoomMember.membership", this.onRoomMembership); // update when accepting an invite
|
||||||
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
|
const enablePresenceByHsUrl = SdkConfig.get()["enable_presence_by_hs_url"];
|
||||||
const hsUrl = MatrixClientPeg.get().baseUrl;
|
const hsUrl = MatrixClientPeg.get().baseUrl;
|
||||||
this._showPresence = true;
|
this._showPresence = true;
|
||||||
|
@ -59,7 +61,6 @@ module.exports = React.createClass({
|
||||||
cli.on("RoomState.members", this.onRoomStateMember);
|
cli.on("RoomState.members", this.onRoomStateMember);
|
||||||
cli.on("RoomMember.name", this.onRoomMemberName);
|
cli.on("RoomMember.name", this.onRoomMemberName);
|
||||||
cli.on("RoomState.events", this.onRoomStateEvent);
|
cli.on("RoomState.events", this.onRoomStateEvent);
|
||||||
cli.on("Room", this.onRoom); // invites
|
|
||||||
// We listen for changes to the lastPresenceTs which is essentially
|
// We listen for changes to the lastPresenceTs which is essentially
|
||||||
// listening for all presence events (we display most of not all of
|
// listening for all presence events (we display most of not all of
|
||||||
// the information contained in presence events).
|
// the information contained in presence events).
|
||||||
|
@ -69,14 +70,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
componentDidMount: async function() {
|
componentDidMount: async function() {
|
||||||
this._mounted = true;
|
this._mounted = true;
|
||||||
const cli = MatrixClientPeg.get();
|
this._loadMembersIfNeeded(true);
|
||||||
if (cli.hasLazyLoadMembersEnabled()) {
|
|
||||||
await this._waitForMembersToLoad();
|
|
||||||
if (this._mounted) {
|
|
||||||
this.setState(this._getMembersState());
|
|
||||||
this._listenForMembersChanges();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillUnmount: function() {
|
componentWillUnmount: function() {
|
||||||
|
@ -85,6 +79,7 @@ module.exports = React.createClass({
|
||||||
if (cli) {
|
if (cli) {
|
||||||
cli.removeListener("RoomState.members", this.onRoomStateMember);
|
cli.removeListener("RoomState.members", this.onRoomStateMember);
|
||||||
cli.removeListener("RoomMember.name", this.onRoomMemberName);
|
cli.removeListener("RoomMember.name", this.onRoomMemberName);
|
||||||
|
cli.removeListener("RoomMember.membership", this.onRoomMembership);
|
||||||
cli.removeListener("RoomState.events", this.onRoomStateEvent);
|
cli.removeListener("RoomState.events", this.onRoomStateEvent);
|
||||||
cli.removeListener("Room", this.onRoom);
|
cli.removeListener("Room", this.onRoom);
|
||||||
cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs);
|
cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs);
|
||||||
|
@ -95,14 +90,24 @@ module.exports = React.createClass({
|
||||||
this._updateList.cancelPendingCall();
|
this._updateList.cancelPendingCall();
|
||||||
},
|
},
|
||||||
|
|
||||||
_waitForMembersToLoad: async function() {
|
_loadMembersIfNeeded: async function(initial) {
|
||||||
if (!this.props.roomId) return {};
|
|
||||||
const cli = MatrixClientPeg.get();
|
const cli = MatrixClientPeg.get();
|
||||||
const room = cli.getRoom(this.props.roomId);
|
if (cli.hasLazyLoadMembersEnabled()) {
|
||||||
if (room) {
|
const cli = MatrixClientPeg.get();
|
||||||
try {
|
const room = cli.getRoom(this.props.roomId);
|
||||||
await room.loadMembersIfNeeded();
|
if (room && room.getMyMembership() === 'join') {
|
||||||
} catch(ex) {/* already logged in RoomView */}
|
this.setState({loading: true});
|
||||||
|
try {
|
||||||
|
await room.loadMembersIfNeeded();
|
||||||
|
} catch(ex) {/* already logged in RoomView */}
|
||||||
|
if (this._mounted) {
|
||||||
|
this.setState(this._getMembersState());
|
||||||
|
this._listenForMembersChanges();
|
||||||
|
}
|
||||||
|
} else if(initial) {
|
||||||
|
// show the members we've got
|
||||||
|
this.setState(this._getMembersState());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -163,14 +168,28 @@ module.exports = React.createClass({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRoom: function(room) {
|
onRoom: async function(room) {
|
||||||
if (room.roomId !== this.props.roomId) {
|
if (room.roomId !== this.props.roomId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// We listen for room events because when we accept an invite
|
// We listen for room events because when we accept an invite
|
||||||
// we need to wait till the room is fully populated with state
|
// we need to wait till the room is fully populated with state
|
||||||
// before refreshing the member list else we get a stale list.
|
// before refreshing the member list else we get a stale list.
|
||||||
this._updateList();
|
|
||||||
|
// also when peeking, we need to await the members being loaded
|
||||||
|
// before showing them.
|
||||||
|
|
||||||
|
this._loadMembersIfNeeded();
|
||||||
|
},
|
||||||
|
|
||||||
|
onRoomMembership: async function(ev, member, oldMembership) {
|
||||||
|
const cli = MatrixClientPeg.get();
|
||||||
|
const myId = cli.getUserId();
|
||||||
|
if (member.userId === myId && oldMembership !== "join" && member.membership === "join") {
|
||||||
|
// once we've joined, no need to listen for membership anymore
|
||||||
|
cli.removeListener("RoomMember.membership", this.onRoomMembership);
|
||||||
|
this._loadMembersIfNeeded();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRoomStateMember: function(ev, state, member) {
|
onRoomStateMember: function(ev, state, member) {
|
||||||
|
@ -197,6 +216,7 @@ module.exports = React.createClass({
|
||||||
_updateList: new rate_limited_func(function() {
|
_updateList: new rate_limited_func(function() {
|
||||||
// console.log("Updating memberlist");
|
// console.log("Updating memberlist");
|
||||||
const newState = {
|
const newState = {
|
||||||
|
loading: false,
|
||||||
members: this.roomMembers(),
|
members: this.roomMembers(),
|
||||||
};
|
};
|
||||||
newState.filteredJoinedMembers = this._filterMembers(newState.members, 'join', this.state.searchQuery);
|
newState.filteredJoinedMembers = this._filterMembers(newState.members, 'join', this.state.searchQuery);
|
||||||
|
|
Loading…
Reference in a new issue