diff --git a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx index e0add2cd05..a9dfd67ca9 100644 --- a/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx +++ b/src/components/views/settings/tabs/room/SecurityRoomSettingsTab.tsx @@ -15,8 +15,10 @@ limitations under the License. */ import React from 'react'; -import { JoinRule, GuestAccess, HistoryVisibility } from "matrix-js-sdk/src/@types/partials"; +import { GuestAccess, HistoryVisibility, JoinRule } from "matrix-js-sdk/src/@types/partials"; import { MatrixEvent } from "matrix-js-sdk/src/models/event"; +import { IRoomVersionsCapability } from 'matrix-js-sdk/src/client'; +import { EventType } from 'matrix-js-sdk/src/@types/event'; import { _t } from "../../../../../languageHandler"; import { MatrixClientPeg } from "../../../../../MatrixClientPeg"; @@ -24,7 +26,7 @@ import * as sdk from "../../../../.."; import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch"; import Modal from "../../../../../Modal"; import QuestionDialog from "../../../dialogs/QuestionDialog"; -import StyledRadioGroup from '../../../elements/StyledRadioGroup'; +import StyledRadioGroup, { IDefinition } from '../../../elements/StyledRadioGroup'; import { SettingLevel } from "../../../../../settings/SettingLevel"; import SettingsStore from "../../../../../settings/SettingsStore"; import { UIFeature } from "../../../../../settings/UIFeature"; @@ -42,6 +44,12 @@ interface IState { encrypted: boolean; } +enum RoomVisibility { + InviteOnly = "invite_only", + PublicNoGuests = "public_no_guests", + PublicWithGuests = "public_with_guests", +} + @replaceableComponent("views.settings.tabs.room.SecurityRoomSettingsTab") export default class SecurityRoomSettingsTab extends React.Component { constructor(props) { @@ -57,31 +65,33 @@ export default class SecurityRoomSettingsTab extends React.Component this.setState({ hasAliases })); } private pullContentPropertyFromEvent(event: MatrixEvent, key: string, defaultValue: T): T { @@ -94,13 +104,13 @@ export default class SecurityRoomSettingsTab extends React.Component { - const refreshWhenTypes = [ - 'm.room.join_rules', - 'm.room.guest_access', - 'm.room.history_visibility', - 'm.room.encryption', + const refreshWhenTypes: EventType[] = [ + EventType.RoomJoinRules, + EventType.RoomGuestAccess, + EventType.RoomHistoryVisibility, + EventType.RoomEncryption, ]; - if (refreshWhenTypes.includes(e.getType())) this.forceUpdate(); + if (refreshWhenTypes.includes(e.getType() as EventType)) this.forceUpdate(); }; private onEncryptionChange = (e: React.ChangeEvent) => { @@ -126,7 +136,7 @@ export default class SecurityRoomSettingsTab extends React.Component { console.error(e); @@ -140,25 +150,21 @@ export default class SecurityRoomSettingsTab extends React.Component { - console.error(e); - this.setState({joinRule: beforeJoinRule}); - }); - client.sendStateEvent(this.props.roomId, "m.room.guest_access", {guest_access: guestAccess}, "").catch((e) => { + client.sendStateEvent(this.props.roomId, EventType.RoomGuestAccess, { + guest_access: guestAccess, + }, "").catch((e) => { console.error(e); this.setState({guestAccess: beforeGuestAccess}); }); }; - private onRoomAccessRadioToggle = (roomAccess: string) => { + private onRoomAccessRadioToggle = (roomAccess: RoomVisibility) => { // join_rule // INVITE | PUBLIC // ----------------------+---------------- @@ -176,14 +182,14 @@ export default class SecurityRoomSettingsTab extends React.Component { + client.sendStateEvent(this.props.roomId, EventType.RoomJoinRules, { + join_rule: joinRule, + }, "").catch((e) => { console.error(e); this.setState({joinRule: beforeJoinRule}); }); - client.sendStateEvent(this.props.roomId, "m.room.guest_access", {guest_access: guestAccess}, "").catch((e) => { + client.sendStateEvent(this.props.roomId, EventType.RoomGuestAccess, { + guest_access: guestAccess, + }, "").catch((e) => { console.error(e); this.setState({guestAccess: beforeGuestAccess}); }); @@ -207,7 +217,7 @@ export default class SecurityRoomSettingsTab extends React.Component { const beforeHistory = this.state.history; this.setState({history: history}); - MatrixClientPeg.get().sendStateEvent(this.props.roomId, "m.room.history_visibility", { + MatrixClientPeg.get().sendStateEvent(this.props.roomId, EventType.RoomHistoryVisibility, { history_visibility: history, }, "").catch((e) => { console.error(e); @@ -227,7 +237,7 @@ export default class SecurityRoomSettingsTab extends React.Component (ev.getContent().aliases || []).length > 0); return hasAliases; } @@ -239,11 +249,11 @@ export default class SecurityRoomSettingsTab extends React.Component @@ -256,7 +266,7 @@ export default class SecurityRoomSettingsTab extends React.Component @@ -267,34 +277,33 @@ export default class SecurityRoomSettingsTab extends React.Component[] = [ + { + value: RoomVisibility.InviteOnly, + label: _t('Only people who have been invited'), + checked: joinRule !== JoinRule.Public && joinRule !== JoinRule.Restricted, + }, + { + value: RoomVisibility.PublicNoGuests, + label: _t('Anyone who knows the room\'s link, apart from guests'), + checked: joinRule === JoinRule.Public && guestAccess !== GuestAccess.CanJoin, + }, + { + value: RoomVisibility.PublicWithGuests, + label: _t("Anyone who knows the room's link, including guests"), + checked: joinRule === JoinRule.Public && guestAccess === GuestAccess.CanJoin, + }, + ]; + return (
- {guestWarning} - {aliasWarning} + { guestWarning } + { aliasWarning }
); @@ -304,7 +313,7 @@ export default class SecurityRoomSettingsTab extends React.Component @@ -349,7 +358,7 @@ export default class SecurityRoomSettingsTab extends React.Component