Check whether user has permission to invite

Signed-off-by: Jaiwanth <jaiwanth2011@gmail.com>
pull/21833/head
Jaiwanth 2021-02-15 20:52:19 +05:30
parent f420c85985
commit 04d2bf1d6a
2 changed files with 18 additions and 6 deletions

View File

@ -188,7 +188,7 @@ limitations under the License.
.mx_RoomTile_iconSettings::before {
mask-image: url('$(res)/img/element-icons/settings.svg');
}
.mx_RoomTile_iconInvite::before {
mask-image: url('$(res)/img/element-icons/room/invite.svg');
}

View File

@ -462,6 +462,16 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
const isLowPriority = roomTags.includes(DefaultTagID.LowPriority);
const lowPriorityLabel = _t("Low Priority");
const inRoom = this.props.room && this.props.room.getMyMembership() === "join";
const userId = MatrixClientPeg.get().getUserId();
let canInvite = inRoom;
const powerLevels = this.props.room.currentState
.getStateEvents("m.room.power_levels", "")
?.getContent();
const me = this.props.room.getMember(userId);
if (powerLevels && me && powerLevels.invite > me.powerLevel) {
canInvite = false;
}
contextMenu = <IconizedContextMenu
{...contextMenuBelow(this.state.generalMenuPosition)}
onFinished={this.onCloseGeneralMenu}
@ -481,11 +491,13 @@ export default class RoomTile extends React.PureComponent<IProps, IState> {
label={lowPriorityLabel}
iconClassName="mx_RoomTile_iconArrowDown"
/>
<IconizedContextMenuOption
onClick={this.onInviteClick}
label={_t("Invite to this room")}
iconClassName="mx_RoomTile_iconInvite"
/>
{canInvite ? (
<IconizedContextMenuOption
onClick={this.onInviteClick}
label={_t("Invite to this room")}
iconClassName="mx_RoomTile_iconInvite"
/>
) : null}
<IconizedContextMenuOption
onClick={this.onOpenRoomSettings}
label={_t("Settings")}