This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 829
Add Element Call room settings #9347
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
b421911
Correctly setup EC perms on room creation
SimonBrandner 055faf6
Add `VoipRoomSettingsTab`
SimonBrandner 0cdf7ca
Show `VoipRoomSettingsTab`
SimonBrandner ebcd2d5
Show MSC3401 perms in room settings
SimonBrandner 88c3666
i18n
SimonBrandner 761e528
Remove `ScreenName`
SimonBrandner adf9f19
Hide behind labs flag
SimonBrandner b92a576
Add `testid`
SimonBrandner 5491451
Add tests
SimonBrandner eb8b242
i18n
SimonBrandner 1b19491
Don't mix `"` and `'`
SimonBrandner 1e56fbc
Fix indent
SimonBrandner 278f0fd
Fix test name
SimonBrandner 9983434
Try to use existing power levels
SimonBrandner d4f0789
Fix MSC number
SimonBrandner 940095b
Fix MSC number
SimonBrandner deabd80
Gate behind flag
SimonBrandner 512b07a
Add missing `DEFAULT_EVENT_POWER_LEVELS`
SimonBrandner 938498f
Mock `SettingsStore`
SimonBrandner 2a6bbda
Disable when insufficient perms
SimonBrandner 756bdaf
Fix tests
SimonBrandner 14d9bab
Don't cast as `any`
SimonBrandner b62e74b
Merge branch 'develop' into SimonBrandner/feat/ec-perms
SimonBrandner 2bcdbf7
Add EC brand
SimonBrandner e7000b6
i18n
SimonBrandner d5ee3d6
Delint
SimonBrandner dfd4031
Fix tests
SimonBrandner e19e015
Merge branch 'develop' into SimonBrandner/feat/ec-perms
SimonBrandner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/components/views/settings/tabs/room/VoipRoomSettingsTab.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
Copyright 2022 The Matrix.org Foundation C.I.C. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import React, { useCallback, useMemo, useState } from 'react'; | ||
import { JoinRule } from "matrix-js-sdk/src/@types/partials"; | ||
import { EventType } from "matrix-js-sdk/src/@types/event"; | ||
|
||
import { _t } from "../../../../../languageHandler"; | ||
import { MatrixClientPeg } from "../../../../../MatrixClientPeg"; | ||
import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch"; | ||
import SettingsSubsection from "../../shared/SettingsSubsection"; | ||
import SettingsTab from "../SettingsTab"; | ||
import { ElementCall } from "../../../../../models/Call"; | ||
import { useRoomState } from "../../../../../hooks/useRoomState"; | ||
import SdkConfig from "../../../../../SdkConfig"; | ||
|
||
interface ElementCallSwitchProps { | ||
roomId: string; | ||
} | ||
|
||
const ElementCallSwitch: React.FC<ElementCallSwitchProps> = ({ roomId }) => { | ||
const room = useMemo(() => MatrixClientPeg.get().getRoom(roomId), [roomId]); | ||
const isPublic = useMemo(() => room.getJoinRule() === JoinRule.Public, [room]); | ||
const [content, events, maySend] = useRoomState(room, useCallback((state) => { | ||
const content = state?.getStateEvents(EventType.RoomPowerLevels, "")?.getContent(); | ||
return [ | ||
content ?? {}, | ||
content?.["events"] ?? {}, | ||
state?.maySendStateEvent(EventType.RoomPowerLevels, MatrixClientPeg.get().getUserId()), | ||
]; | ||
}, [])); | ||
|
||
const [elementCallEnabled, setElementCallEnabled] = useState<boolean>(() => { | ||
return events[ElementCall.MEMBER_EVENT_TYPE.name] === 0; | ||
}); | ||
|
||
const onChange = useCallback((enabled: boolean): void => { | ||
setElementCallEnabled(enabled); | ||
|
||
if (enabled) { | ||
const userLevel = events[EventType.RoomMessage] ?? content.users_default ?? 0; | ||
const moderatorLevel = content.kick ?? 50; | ||
|
||
events[ElementCall.CALL_EVENT_TYPE.name] = isPublic ? moderatorLevel : userLevel; | ||
events[ElementCall.MEMBER_EVENT_TYPE.name] = userLevel; | ||
} else { | ||
const adminLevel = events[EventType.RoomPowerLevels] ?? content.state_default ?? 100; | ||
|
||
events[ElementCall.CALL_EVENT_TYPE.name] = adminLevel; | ||
events[ElementCall.MEMBER_EVENT_TYPE.name] = adminLevel; | ||
} | ||
|
||
MatrixClientPeg.get().sendStateEvent(roomId, EventType.RoomPowerLevels, { | ||
"events": events, | ||
...content, | ||
}); | ||
}, [roomId, content, events, isPublic]); | ||
|
||
const brand = SdkConfig.get("element_call").brand; | ||
|
||
return <LabelledToggleSwitch | ||
data-testid="element-call-switch" | ||
label={_t("Enable %(brand)s as an additional calling option in this room", { brand })} | ||
caption={_t( | ||
"%(brand)s is end-to-end encrypted, " + | ||
"but is currently limited to smaller numbers of users.", | ||
{ brand }, | ||
)} | ||
value={elementCallEnabled} | ||
onChange={onChange} | ||
disabled={!maySend} | ||
tooltip={_t("You do not have sufficient permissions to change this.")} | ||
/>; | ||
}; | ||
|
||
interface Props { | ||
roomId: string; | ||
} | ||
|
||
export const VoipRoomSettingsTab: React.FC<Props> = ({ roomId }) => { | ||
return <SettingsTab heading={_t("Voice & Video")}> | ||
<SettingsSubsection heading={_t("Call type")}> | ||
<ElementCallSwitch roomId={roomId} /> | ||
</SettingsSubsection> | ||
</SettingsTab>; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an error waiting to happen: we should be using
SdkConfig.get().element_call?.brand ?? DEFAULTS.element_call.brand
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed by #9376