do self membership checks with getMyMembership elsewhere as well

This commit is contained in:
Bruno Windels 2018-08-22 14:06:28 +02:00
parent c38b286e8e
commit 860c6355f0
3 changed files with 10 additions and 13 deletions

View File

@ -497,12 +497,11 @@ function canSendEvent(event, roomId) {
sendError(event, _t('This room is not recognised.')); sendError(event, _t('This room is not recognised.'));
return; return;
} }
const me = client.credentials.userId; if (room.getMyMembership() !== "join") {
const member = room.getMember(me);
if (!member || member.membership !== "join") {
sendError(event, _t('You are not in this room.')); sendError(event, _t('You are not in this room.'));
return; return;
} }
const me = client.credentials.userId;
let canSend = false; let canSend = false;
if (isState) { if (isState) {

View File

@ -346,20 +346,18 @@ module.exports = React.createClass({
}, },
render: function() { render: function() {
const myMember = this.props.room.getMember( const myMembership = this.props.room.getMyMembership();
MatrixClientPeg.get().credentials.userId,
);
// Can't set notif level or tags on non-join rooms // Can't set notif level or tags on non-join rooms
if (myMember.membership !== 'join') { if (myMembership !== 'join') {
return this._renderLeaveMenu(myMember.membership); return this._renderLeaveMenu(myMembership);
} }
return ( return (
<div> <div>
{ this._renderNotifMenu() } { this._renderNotifMenu() }
<hr className="mx_RoomTileContextMenu_separator" /> <hr className="mx_RoomTileContextMenu_separator" />
{ this._renderLeaveMenu(myMember.membership) } { this._renderLeaveMenu(myMembership) }
<hr className="mx_RoomTileContextMenu_separator" /> <hr className="mx_RoomTileContextMenu_separator" />
{ this._renderRoomTagMenu() } { this._renderRoomTagMenu() }
</div> </div>

View File

@ -794,15 +794,15 @@ module.exports = React.createClass({
} }
let leaveButton = null; let leaveButton = null;
const myMember = this.props.room.getMember(myUserId); const myMemberShip = this.props.room.getMyMembership();
if (myMember) { if (myMemberShip) {
if (myMember.membership === "join") { if (myMemberShip === "join") {
leaveButton = ( leaveButton = (
<AccessibleButton className="mx_RoomSettings_leaveButton" onClick={this.onLeaveClick}> <AccessibleButton className="mx_RoomSettings_leaveButton" onClick={this.onLeaveClick}>
{ _t('Leave room') } { _t('Leave room') }
</AccessibleButton> </AccessibleButton>
); );
} else if (myMember.membership === "leave") { } else if (myMemberShip === "leave") {
leaveButton = ( leaveButton = (
<AccessibleButton className="mx_RoomSettings_leaveButton" onClick={this.onForgetClick}> <AccessibleButton className="mx_RoomSettings_leaveButton" onClick={this.onForgetClick}>
{ _t('Forget room') } { _t('Forget room') }