From 9f9699bf75a5b37b485e99e8ff768b9e1744e9b8 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Tue, 8 Dec 2020 10:31:40 +0000 Subject: [PATCH] Hide Invite to this room CTA if no permission --- src/components/views/rooms/NewRoomIntro.tsx | 31 +++++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/components/views/rooms/NewRoomIntro.tsx b/src/components/views/rooms/NewRoomIntro.tsx index be4ecaffb3..9be3d6be18 100644 --- a/src/components/views/rooms/NewRoomIntro.tsx +++ b/src/components/views/rooms/NewRoomIntro.tsx @@ -60,8 +60,9 @@ const NewRoomIntro = () => { { caption &&
{ caption }
} ; } else { + const inRoom = room && room.getMyMembership() === "join"; const topic = room.currentState.getStateEvents(EventType.RoomTopic, "")?.getContent()?.topic; - const canAddTopic = room.currentState.maySendStateEvent(EventType.RoomTopic, cli.getUserId()); + const canAddTopic = inRoom && room.currentState.maySendStateEvent(EventType.RoomTopic, cli.getUserId()); const onTopicClick = () => { dis.dispatch({ @@ -99,9 +100,25 @@ const NewRoomIntro = () => { }); } - const onInviteClick = () => { - dis.dispatch({ action: "view_invite", roomId }); - }; + let canInvite = inRoom; + const powerLevels = room.currentState.getStateEvents(EventType.RoomPowerLevels, "")?.getContent(); + const me = room.getMember(cli.getUserId()); + if (powerLevels && me && powerLevels.invite > me.powerLevel) { + canInvite = false; + } + + let buttons; + if (canInvite) { + const onInviteClick = () => { + dis.dispatch({ action: "view_invite", roomId }); + }; + + buttons ={topicText}
-