From 01a0260ac8a05f35c7499b18810e677c66390f04 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Aug 2018 10:33:13 +0200 Subject: [PATCH 1/5] use getMyMembership instead of member --- src/components/structures/RoomView.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 855090873f..92be0954f9 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -310,7 +310,7 @@ module.exports = React.createClass({ }); } else if (room) { //viewing a previously joined room, try to lazy load members - + // Stop peeking because we have joined this room previously MatrixClientPeg.get().stopPeeking(); this.setState({isPeeking: false}); @@ -1507,9 +1507,8 @@ module.exports = React.createClass({ } } - const myUserId = MatrixClientPeg.get().credentials.userId; - const myMember = this.state.room.getMember(myUserId); - if (myMember && myMember.membership == 'invite') { + const myMembership = this.state.room.getMyMembership(); + if (myMembership == 'invite') { if (this.state.joining || this.state.rejecting) { return (
@@ -1517,6 +1516,8 @@ module.exports = React.createClass({
); } else { + const myUserId = MatrixClientPeg.get().credentials.userId; + const myMember = this.state.room.getMember(myUserId); const inviteEvent = myMember.events.member; var inviterName = inviteEvent.sender ? inviteEvent.sender.name : inviteEvent.getSender(); @@ -1600,7 +1601,7 @@ module.exports = React.createClass({ } else if (this.state.showingPinned) { hideCancel = true; // has own cancel aux = ; - } else if (!myMember || myMember.membership !== "join") { + } else if (!myMembership || myMembership !== "join") { // We do have a room object for this room, but we're not currently in it. // We may have a 3rd party invite to it. var inviterName = undefined; @@ -1642,7 +1643,7 @@ module.exports = React.createClass({ let messageComposer, searchInfo; const canSpeak = ( // joined and not showing search results - myMember && (myMember.membership == 'join') && !this.state.searchResults + myMembership == 'join' && !this.state.searchResults ); if (canSpeak) { messageComposer = @@ -1777,15 +1778,15 @@ module.exports = React.createClass({ oobData={this.props.oobData} editing={this.state.editingRoomSettings} saving={this.state.uploadingRoomSettings} - inRoom={myMember && myMember.membership === 'join'} + inRoom={myMembership === 'join'} collapsedRhs={this.props.collapsedRhs} onSearchClick={this.onSearchClick} onSettingsClick={this.onSettingsClick} onPinnedClick={this.onPinnedClick} onSaveClick={this.onSettingsSaveClick} onCancelClick={(aux && !hideCancel) ? this.onCancelClick : null} - onForgetClick={(myMember && myMember.membership === "leave") ? this.onForgetClick : null} - onLeaveClick={(myMember && myMember.membership === "join") ? this.onLeaveClick : null} + onForgetClick={(myMembership === "leave") ? this.onForgetClick : null} + onLeaveClick={(myMembership === "join") ? this.onLeaveClick : null} /> { auxPanel }
From c38b286e8e6f7aaa3cf2d6f77939e3182736c8c1 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Aug 2018 12:28:00 +0200 Subject: [PATCH 2/5] falsy check is obsolete now --- src/components/structures/RoomView.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 92be0954f9..84b8788297 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -1601,7 +1601,7 @@ module.exports = React.createClass({ } else if (this.state.showingPinned) { hideCancel = true; // has own cancel aux = ; - } else if (!myMembership || myMembership !== "join") { + } else if (myMembership !== "join") { // We do have a room object for this room, but we're not currently in it. // We may have a 3rd party invite to it. var inviterName = undefined; From 860c6355f026aabab384e75402f0de475510d49e Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Aug 2018 14:06:28 +0200 Subject: [PATCH 3/5] do self membership checks with getMyMembership elsewhere as well --- src/ScalarMessaging.js | 5 ++--- .../views/context_menus/RoomTileContextMenu.js | 10 ++++------ src/components/views/rooms/RoomSettings.js | 8 ++++---- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/ScalarMessaging.js b/src/ScalarMessaging.js index 3325044b84..7ec928f895 100644 --- a/src/ScalarMessaging.js +++ b/src/ScalarMessaging.js @@ -497,12 +497,11 @@ function canSendEvent(event, roomId) { sendError(event, _t('This room is not recognised.')); return; } - const me = client.credentials.userId; - const member = room.getMember(me); - if (!member || member.membership !== "join") { + if (room.getMyMembership() !== "join") { sendError(event, _t('You are not in this room.')); return; } + const me = client.credentials.userId; let canSend = false; if (isState) { diff --git a/src/components/views/context_menus/RoomTileContextMenu.js b/src/components/views/context_menus/RoomTileContextMenu.js index 77f71fa8fa..ce9895447e 100644 --- a/src/components/views/context_menus/RoomTileContextMenu.js +++ b/src/components/views/context_menus/RoomTileContextMenu.js @@ -346,20 +346,18 @@ module.exports = React.createClass({ }, render: function() { - const myMember = this.props.room.getMember( - MatrixClientPeg.get().credentials.userId, - ); + const myMembership = this.props.room.getMyMembership(); // Can't set notif level or tags on non-join rooms - if (myMember.membership !== 'join') { - return this._renderLeaveMenu(myMember.membership); + if (myMembership !== 'join') { + return this._renderLeaveMenu(myMembership); } return (
{ this._renderNotifMenu() }
- { this._renderLeaveMenu(myMember.membership) } + { this._renderLeaveMenu(myMembership) }
{ this._renderRoomTagMenu() }
diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 7a78d205b9..3b95fa9905 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -794,15 +794,15 @@ module.exports = React.createClass({ } let leaveButton = null; - const myMember = this.props.room.getMember(myUserId); - if (myMember) { - if (myMember.membership === "join") { + const myMemberShip = this.props.room.getMyMembership(); + if (myMemberShip) { + if (myMemberShip === "join") { leaveButton = ( { _t('Leave room') } ); - } else if (myMember.membership === "leave") { + } else if (myMemberShip === "leave") { leaveButton = ( { _t('Forget room') } From a54629276fe225ad0281bf2f805b5d5b2fd6dc94 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Aug 2018 14:08:18 +0200 Subject: [PATCH 4/5] use getJoinedMemberCount() instead of getJoinedMembers().length as the latter doesnt take LL into account --- src/ScalarMessaging.js | 2 +- src/VectorConferenceHandler.js | 2 +- src/components/structures/RightPanel.js | 2 +- src/components/structures/RoomView.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ScalarMessaging.js b/src/ScalarMessaging.js index 7ec928f895..fa7b8c5b76 100644 --- a/src/ScalarMessaging.js +++ b/src/ScalarMessaging.js @@ -480,7 +480,7 @@ function getMembershipCount(event, roomId) { sendError(event, _t('This room is not recognised.')); return; } - const count = room.getJoinedMembers().length; + const count = room.getJoinedMemberCount(); sendResponse(event, count); } diff --git a/src/VectorConferenceHandler.js b/src/VectorConferenceHandler.js index 9ba46b2ab6..c53a01d464 100644 --- a/src/VectorConferenceHandler.js +++ b/src/VectorConferenceHandler.js @@ -72,7 +72,7 @@ ConferenceCall.prototype._getConferenceUserRoom = function() { for (var i = 0; i < rooms.length; i++) { var confUser = rooms[i].getMember(this.confUserId); if (confUser && confUser.membership === "join" && - rooms[i].getJoinedMembers().length === 2) { + rooms[i].getJoinedMemberCount() === 2) { confRoom = rooms[i]; break; } diff --git a/src/components/structures/RightPanel.js b/src/components/structures/RightPanel.js index 18523ceb59..bd4ed722cb 100644 --- a/src/components/structures/RightPanel.js +++ b/src/components/structures/RightPanel.js @@ -280,7 +280,7 @@ module.exports = React.createClass({ const room = cli.getRoom(this.props.roomId); let isUserInRoom; if (room) { - const numMembers = room.getJoinedMembers().length; + const numMembers = room.getJoinedMemberCount(); membersTitle = _t('%(count)s Members', { count: numMembers }); membersBadge =
{ formatCount(numMembers) }
; isUserInRoom = room.hasMembershipState(this.context.matrixClient.credentials.userId, 'join'); diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 84b8788297..7b7a7bb813 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -363,7 +363,7 @@ module.exports = React.createClass({ // XXX: EVIL HACK to autofocus inviting on empty rooms. // We use the setTimeout to avoid racing with focus_composer. if (this.state.room && - this.state.room.getJoinedMembers().length == 1 && + this.state.room.getJoinedMemberCount() == 1 && this.state.room.getLiveTimeline() && this.state.room.getLiveTimeline().getEvents() && this.state.room.getLiveTimeline().getEvents().length <= 6) { From db7dd8e9e88edec5d128cea502b567c6384a12c2 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 22 Aug 2018 16:00:03 +0200 Subject: [PATCH 5/5] fix tests --- test/test-utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test-utils.js b/test/test-utils.js index 975a4df0ee..25df9686ff 100644 --- a/test/test-utils.js +++ b/test/test-utils.js @@ -256,6 +256,7 @@ export function mkStubRoom(roomId = null) { getAccountData: () => null, hasMembershipState: () => null, getVersion: () => '1', + getMyMembership: () => "join", currentState: { getStateEvents: sinon.stub(), mayClientSendStateEvent: sinon.stub().returns(true),