From 2ed414494f24435e459e5da0b2ff64e46b0bd254 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 17 Sep 2018 19:14:52 +0200 Subject: [PATCH] use Room.myMembership event instead of RoomMember.membership for me This is more reliable with LL enabled as the syncing user is only known when it was active in the current timeline or when the members have been loaded --- src/actions/MatrixActionCreators.js | 11 ++++------- src/components/structures/RoomView.js | 10 +++++----- src/components/views/rooms/MemberList.js | 17 ++++++++--------- src/stores/RoomListStore.js | 2 +- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/actions/MatrixActionCreators.js b/src/actions/MatrixActionCreators.js index 17be9a5e0f..a18dc77551 100644 --- a/src/actions/MatrixActionCreators.js +++ b/src/actions/MatrixActionCreators.js @@ -149,7 +149,7 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi */ /** - * Create a MatrixActions.Room.selfMembership action that represents + * Create a MatrixActions.Room.myMembership action that represents * a MatrixClient `RoomMember.membership` matrix event for the syncing user, * emitted when the member's membership is updated. * @@ -159,11 +159,8 @@ function createRoomTimelineAction(matrixClient, timelineEvent, room, toStartOfTi * @param {string} oldMembership the member's previous membership. * @returns {RoomMembershipAction} an action of type `MatrixActions.RoomMember.membership`. */ -function createSelfRoomMembershipAction(matrixClient, membershipEvent, member, oldMembership) { - if (member.userId === matrixClient.getUserId()) { - return { action: 'MatrixActions.Room.selfMembership', member }; - } - return null; +function createSelfMembershipAction(matrixClient, room, membership, oldMembership) { + return { action: 'MatrixActions.Room.myMembership', room, membership, oldMembership}; } /** @@ -205,7 +202,7 @@ export default { this._addMatrixClientListener(matrixClient, 'Room', createRoomAction); this._addMatrixClientListener(matrixClient, 'Room.tags', createRoomTagsAction); this._addMatrixClientListener(matrixClient, 'Room.timeline', createRoomTimelineAction); - this._addMatrixClientListener(matrixClient, 'RoomMember.membership', createSelfRoomMembershipAction); + this._addMatrixClientListener(matrixClient, 'Room.myMembership', createSelfMembershipAction); this._addMatrixClientListener(matrixClient, 'Event.decrypted', createEventDecryptedAction); }, diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 2715a5698d..cf99bb9fc3 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -148,7 +148,7 @@ module.exports = React.createClass({ MatrixClientPeg.get().on("Room.name", this.onRoomName); MatrixClientPeg.get().on("Room.accountData", this.onRoomAccountData); MatrixClientPeg.get().on("RoomState.members", this.onRoomStateMember); - MatrixClientPeg.get().on("RoomMember.membership", this.onRoomMemberMembership); + MatrixClientPeg.get().on("Room.myMembership", this.onMyMembership); MatrixClientPeg.get().on("accountData", this.onAccountData); // Start listening for RoomViewStore updates @@ -412,8 +412,8 @@ module.exports = React.createClass({ MatrixClientPeg.get().removeListener("Room.timeline", this.onRoomTimeline); MatrixClientPeg.get().removeListener("Room.name", this.onRoomName); MatrixClientPeg.get().removeListener("Room.accountData", this.onRoomAccountData); + MatrixClientPeg.get().removeListener("Room.myMembership", this.onMyMembership); MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember); - MatrixClientPeg.get().removeListener("RoomMember.membership", this.onRoomMemberMembership); MatrixClientPeg.get().removeListener("accountData", this.onAccountData); } @@ -715,10 +715,10 @@ module.exports = React.createClass({ this._updateRoomMembers(); }, - onRoomMemberMembership: function(ev, member, oldMembership) { - if (member.userId == MatrixClientPeg.get().credentials.userId) { - this._loadMembersIfJoined(); + onMyMembership: function(room, membership, oldMembership) { + if (room.roomId === this.state.roomId) { this.forceUpdate(); + this._loadMembersIfJoined(room); } }, diff --git a/src/components/views/rooms/MemberList.js b/src/components/views/rooms/MemberList.js index 6a00c88d37..854bd20c30 100644 --- a/src/components/views/rooms/MemberList.js +++ b/src/components/views/rooms/MemberList.js @@ -43,11 +43,14 @@ module.exports = React.createClass({ componentWillMount: function() { this._mounted = false; const cli = MatrixClientPeg.get(); - if (!cli.hasLazyLoadMembersEnabled()) { + if (cli.hasLazyLoadMembersEnabled()) { + // true means will not show a spinner but the + // known members so far if not joined + cli.on("Room.myMembership", this.onMyMembership); + } else { 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 hsUrl = MatrixClientPeg.get().baseUrl; this._showPresence = true; @@ -79,7 +82,7 @@ module.exports = React.createClass({ if (cli) { cli.removeListener("RoomState.members", this.onRoomStateMember); cli.removeListener("RoomMember.name", this.onRoomMemberName); - cli.removeListener("RoomMember.membership", this.onRoomMembership); + cli.removeListener("Room.myMembership", this.onMyMembership); cli.removeListener("RoomState.events", this.onRoomStateEvent); cli.removeListener("Room", this.onRoom); cli.removeListener("User.lastPresenceTs", this.onUserLastPresenceTs); @@ -182,12 +185,8 @@ module.exports = React.createClass({ this._loadMembersIfNeeded(); }, - onRoomMembership: 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); + onMyMembership: function(room, membership, oldMembership) { + if (room.roomId === this.props.roomId && membership === "join") { this._loadMembersIfNeeded(); } }, diff --git a/src/stores/RoomListStore.js b/src/stores/RoomListStore.js index 5a041f52ac..67c0c13be7 100644 --- a/src/stores/RoomListStore.js +++ b/src/stores/RoomListStore.js @@ -120,7 +120,7 @@ class RoomListStore extends Store { this._generateRoomLists(); } break; - case 'MatrixActions.Room.selfMembership': { + case 'MatrixActions.Room.myMembership': { this._generateRoomLists(); } break;