Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Check whether user has permission to invite
Browse files Browse the repository at this point in the history
Signed-off-by: Jaiwanth <[email protected]>
  • Loading branch information
jaiwanth-v committed Feb 15, 2021
1 parent f420c85 commit 04d2bf1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion res/css/views/rooms/_RoomTile.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
22 changes: 17 additions & 5 deletions src/components/views/rooms/RoomTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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")}
Expand Down

0 comments on commit 04d2bf1

Please sign in to comment.