From e25dc46863c76eec16766a53064b7489a5f7b313 Mon Sep 17 00:00:00 2001 From: Ajay Bura Date: Fri, 29 Oct 2021 14:59:16 +0530 Subject: [PATCH] Add option to select role on roomCreation Signed-off-by: Ajay Bura --- src/app/organisms/create-room/CreateRoom.jsx | 24 +++++++++++++++++-- src/app/organisms/create-room/CreateRoom.scss | 7 ++++++ src/client/action/room.js | 5 ++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/app/organisms/create-room/CreateRoom.jsx b/src/app/organisms/create-room/CreateRoom.jsx index d94c4b1..22ec87f 100644 --- a/src/app/organisms/create-room/CreateRoom.jsx +++ b/src/app/organisms/create-room/CreateRoom.jsx @@ -5,6 +5,7 @@ import './CreateRoom.scss'; import initMatrix from '../../../client/initMatrix'; import { isRoomAliasAvailable } from '../../../util/matrixUtil'; import * as roomActions from '../../../client/action/room'; +import { selectRoom } from '../../../client/action/navigation'; import Text from '../../atoms/text/Text'; import Button from '../../atoms/button/Button'; @@ -12,6 +13,7 @@ import Toggle from '../../atoms/button/Toggle'; import IconButton from '../../atoms/button/IconButton'; import Input from '../../atoms/input/Input'; import Spinner from '../../atoms/spinner/Spinner'; +import SegmentControl from '../../atoms/segmented-controls/SegmentedControls'; import PopupWindow from '../../molecules/popup-window/PopupWindow'; import SettingTile from '../../molecules/setting-tile/SettingTile'; @@ -28,6 +30,7 @@ function CreateRoom({ isOpen, onRequestClose }) { const [titleValue, updateTitleValue] = useState(undefined); const [topicValue, updateTopicValue] = useState(undefined); const [addressValue, updateAddressValue] = useState(undefined); + const [roleIndex, setRoleIndex] = useState(0); const addressRef = useRef(null); const topicRef = useRef(null); @@ -45,6 +48,7 @@ function CreateRoom({ isOpen, onRequestClose }) { updateTitleValue(undefined); updateTopicValue(undefined); updateAddressValue(undefined); + setRoleIndex(0); } async function createRoom() { @@ -60,12 +64,15 @@ function CreateRoom({ isOpen, onRequestClose }) { if (roomAlias.trim() === '') roomAlias = undefined; } + const powerLevel = roleIndex === 1 ? 101 : undefined; + try { - await roomActions.create({ - name, topic, isPublic, roomAlias, isEncrypted, + const result = await roomActions.create({ + name, topic, isPublic, roomAlias, isEncrypted, powerLevel, }); resetForm(); + selectRoom(result.room_id); onRequestClose(); } catch (e) { if (e.message === 'M_UNKNOWN: Invalid characters in room alias') { @@ -139,6 +146,19 @@ function CreateRoom({ isOpen, onRequestClose }) { content={You can’t disable this later. Bridges & most bots won’t work yet.} /> )} + + )} + content={( + Override the default (100) power level. + )} + />
diff --git a/src/app/organisms/create-room/CreateRoom.scss b/src/app/organisms/create-room/CreateRoom.scss index c587fa2..cb2d556 100644 --- a/src/app/organisms/create-room/CreateRoom.scss +++ b/src/app/organisms/create-room/CreateRoom.scss @@ -9,6 +9,13 @@ } } + & .segment-btn { + padding: var(--sp-ultra-tight) 0; + &__base { + padding: 0 var(--sp-tight); + } + } + &__address { display: flex; &__label { diff --git a/src/client/action/room.js b/src/client/action/room.js index c887d24..f16b97f 100644 --- a/src/client/action/room.js +++ b/src/client/action/room.js @@ -132,9 +132,11 @@ function leave(roomId) { * @param {boolean} [opts.isEncrypted=false] Makes room encrypted * @param {boolean} [opts.isDirect=false] Makes room as direct message * @param {string[]} [opts.invite=[]] An array of userId's to invite + * @param{number} [opts.powerLevel=100] My power level */ async function create(opts) { const mx = initMatrix.matrixClient; + const customPowerLevels = [101]; const options = { name: opts.name, topic: opts.topic, @@ -144,6 +146,9 @@ async function create(opts) { invite: opts.invite || [], initial_state: [], preset: opts.isDirect === true ? 'trusted_private_chat' : undefined, + power_level_content_override: customPowerLevels.indexOf(opts.powerLevel) === -1 ? undefined : { + users: { [initMatrix.matrixClient.getUserId()]: opts.powerLevel }, + }, }; if (opts.isPublic !== true && opts.isEncrypted === true) {