2019-01-30 00:30:53 +03:00
|
|
|
/*
|
2021-04-06 14:26:50 +03:00
|
|
|
Copyright 2019-2021 The Matrix.org Foundation C.I.C.
|
2019-01-30 00:30:53 +03:00
|
|
|
|
|
|
|
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 from 'react';
|
2021-07-02 16:51:55 +03:00
|
|
|
import { GuestAccess, HistoryVisibility, JoinRule, RestrictedAllowType } from "matrix-js-sdk/src/@types/partials";
|
|
|
|
import { IContent, MatrixEvent } from "matrix-js-sdk/src/models/event";
|
2021-06-18 13:43:36 +03:00
|
|
|
import { EventType } from 'matrix-js-sdk/src/@types/event';
|
2021-06-18 12:05:46 +03:00
|
|
|
|
2021-06-29 15:11:58 +03:00
|
|
|
import { _t } from "../../../../../languageHandler";
|
|
|
|
import { MatrixClientPeg } from "../../../../../MatrixClientPeg";
|
2019-02-22 20:47:18 +03:00
|
|
|
import LabelledToggleSwitch from "../../../elements/LabelledToggleSwitch";
|
2019-03-01 06:34:34 +03:00
|
|
|
import Modal from "../../../../../Modal";
|
|
|
|
import QuestionDialog from "../../../dialogs/QuestionDialog";
|
2021-06-18 13:43:36 +03:00
|
|
|
import StyledRadioGroup, { IDefinition } from '../../../elements/StyledRadioGroup';
|
2021-06-29 15:11:58 +03:00
|
|
|
import { SettingLevel } from "../../../../../settings/SettingLevel";
|
2020-09-18 20:33:02 +03:00
|
|
|
import SettingsStore from "../../../../../settings/SettingsStore";
|
2021-06-29 15:11:58 +03:00
|
|
|
import { UIFeature } from "../../../../../settings/UIFeature";
|
2021-04-06 14:26:50 +03:00
|
|
|
import { replaceableComponent } from "../../../../../utils/replaceableComponent";
|
2021-07-02 16:51:55 +03:00
|
|
|
import AccessibleButton from "../../../elements/AccessibleButton";
|
|
|
|
import SpaceStore from "../../../../../stores/SpaceStore";
|
|
|
|
import RoomAvatar from "../../../avatars/RoomAvatar";
|
|
|
|
import ManageRestrictedJoinRuleDialog from '../../../dialogs/ManageRestrictedJoinRuleDialog';
|
|
|
|
import RoomUpgradeWarningDialog from '../../../dialogs/RoomUpgradeWarningDialog';
|
|
|
|
import { upgradeRoom } from "../../../../../utils/RoomUpgrade";
|
2021-07-02 17:18:27 +03:00
|
|
|
import { arrayHasDiff } from "../../../../../utils/arrays";
|
2021-07-02 19:15:05 +03:00
|
|
|
import SettingsFlag from '../../../elements/SettingsFlag';
|
2019-01-30 00:30:53 +03:00
|
|
|
|
2021-04-06 14:26:50 +03:00
|
|
|
interface IProps {
|
|
|
|
roomId: string;
|
|
|
|
}
|
2019-01-30 00:30:53 +03:00
|
|
|
|
2021-04-06 14:26:50 +03:00
|
|
|
interface IState {
|
|
|
|
joinRule: JoinRule;
|
2021-07-02 16:51:55 +03:00
|
|
|
restrictedAllowRoomIds?: string[];
|
2021-04-06 14:26:50 +03:00
|
|
|
guestAccess: GuestAccess;
|
2021-04-26 16:08:45 +03:00
|
|
|
history: HistoryVisibility;
|
2021-04-06 14:26:50 +03:00
|
|
|
hasAliases: boolean;
|
|
|
|
encrypted: boolean;
|
2021-07-02 16:51:55 +03:00
|
|
|
roomSupportsRestricted?: boolean;
|
|
|
|
preferredRestrictionVersion?: string;
|
|
|
|
showAdvancedSection: boolean;
|
2021-04-06 14:26:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@replaceableComponent("views.settings.tabs.room.SecurityRoomSettingsTab")
|
|
|
|
export default class SecurityRoomSettingsTab extends React.Component<IProps, IState> {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2019-02-08 00:01:34 +03:00
|
|
|
|
|
|
|
this.state = {
|
2021-04-26 18:14:21 +03:00
|
|
|
joinRule: JoinRule.Invite,
|
2021-07-02 16:51:55 +03:00
|
|
|
guestAccess: GuestAccess.Forbidden,
|
2021-04-26 18:14:21 +03:00
|
|
|
history: HistoryVisibility.Shared,
|
2020-02-19 13:18:56 +03:00
|
|
|
hasAliases: false,
|
2019-02-08 00:01:34 +03:00
|
|
|
encrypted: false,
|
2021-07-02 16:51:55 +03:00
|
|
|
showAdvancedSection: false,
|
2019-02-08 00:01:34 +03:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-03-31 23:12:52 +03:00
|
|
|
// TODO: [REACT-WARNING] Move this to constructor
|
2021-07-21 12:46:41 +03:00
|
|
|
UNSAFE_componentWillMount() { // eslint-disable-line
|
2021-06-18 13:43:36 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
cli.on("RoomState.events", this.onStateEvent);
|
2019-02-08 00:01:34 +03:00
|
|
|
|
2021-06-18 13:43:36 +03:00
|
|
|
const room = cli.getRoom(this.props.roomId);
|
2019-02-08 00:01:34 +03:00
|
|
|
const state = room.currentState;
|
2019-02-14 21:09:37 +03:00
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
const joinRuleEvent = state.getStateEvents(EventType.RoomJoinRules, "");
|
|
|
|
const joinRule: JoinRule = this.pullContentPropertyFromEvent<JoinRule>(
|
|
|
|
joinRuleEvent,
|
2019-02-14 21:09:37 +03:00
|
|
|
'join_rule',
|
2021-04-27 13:56:45 +03:00
|
|
|
JoinRule.Invite,
|
2019-02-14 21:09:37 +03:00
|
|
|
);
|
2021-07-02 16:51:55 +03:00
|
|
|
const restrictedAllowRoomIds = joinRule === JoinRule.Restricted
|
|
|
|
? joinRuleEvent?.getContent().allow
|
|
|
|
?.filter(a => a.type === RestrictedAllowType.RoomMembership)
|
|
|
|
?.map(a => a.room_id)
|
|
|
|
: undefined;
|
|
|
|
|
|
|
|
const guestAccess: GuestAccess = this.pullContentPropertyFromEvent<GuestAccess>(
|
2021-06-18 13:43:36 +03:00
|
|
|
state.getStateEvents(EventType.RoomGuestAccess, ""),
|
2019-02-14 21:09:37 +03:00
|
|
|
'guest_access',
|
2021-04-27 13:56:45 +03:00
|
|
|
GuestAccess.Forbidden,
|
2019-02-14 21:09:37 +03:00
|
|
|
);
|
2021-07-02 16:51:55 +03:00
|
|
|
const history: HistoryVisibility = this.pullContentPropertyFromEvent<HistoryVisibility>(
|
2021-06-18 13:43:36 +03:00
|
|
|
state.getStateEvents(EventType.RoomHistoryVisibility, ""),
|
2019-02-14 21:09:37 +03:00
|
|
|
'history_visibility',
|
2021-04-27 13:56:45 +03:00
|
|
|
HistoryVisibility.Shared,
|
2019-02-14 21:09:37 +03:00
|
|
|
);
|
2021-06-18 13:43:36 +03:00
|
|
|
|
2019-02-08 00:01:34 +03:00
|
|
|
const encrypted = MatrixClientPeg.get().isRoomEncrypted(this.props.roomId);
|
2021-07-06 12:10:25 +03:00
|
|
|
const restrictedRoomCapabilities = SpaceStore.instance.restrictedJoinRuleSupport;
|
|
|
|
const roomSupportsRestricted = Array.isArray(restrictedRoomCapabilities?.support)
|
|
|
|
&& restrictedRoomCapabilities.support.includes(room.getVersion());
|
2021-07-06 14:05:30 +03:00
|
|
|
const preferredRestrictionVersion = roomSupportsRestricted ? undefined : restrictedRoomCapabilities?.preferred;
|
2021-07-06 12:10:25 +03:00
|
|
|
this.setState({ joinRule, restrictedAllowRoomIds, guestAccess, history, encrypted,
|
|
|
|
roomSupportsRestricted, preferredRestrictionVersion });
|
2021-06-18 13:43:36 +03:00
|
|
|
|
|
|
|
this.hasAliases().then(hasAliases => this.setState({ hasAliases }));
|
2019-01-30 00:30:53 +03:00
|
|
|
}
|
|
|
|
|
2021-04-27 13:56:45 +03:00
|
|
|
private pullContentPropertyFromEvent<T>(event: MatrixEvent, key: string, defaultValue: T): T {
|
2021-07-02 16:51:55 +03:00
|
|
|
return event?.getContent()[key] || defaultValue;
|
2019-02-14 21:09:37 +03:00
|
|
|
}
|
|
|
|
|
2021-04-27 13:56:45 +03:00
|
|
|
componentWillUnmount() {
|
2021-04-26 16:02:53 +03:00
|
|
|
MatrixClientPeg.get().removeListener("RoomState.events", this.onStateEvent);
|
2019-01-30 00:30:53 +03:00
|
|
|
}
|
|
|
|
|
2021-04-27 13:56:45 +03:00
|
|
|
private onStateEvent = (e: MatrixEvent) => {
|
2021-06-18 13:43:36 +03:00
|
|
|
const refreshWhenTypes: EventType[] = [
|
|
|
|
EventType.RoomJoinRules,
|
|
|
|
EventType.RoomGuestAccess,
|
|
|
|
EventType.RoomHistoryVisibility,
|
|
|
|
EventType.RoomEncryption,
|
2019-02-02 00:56:29 +03:00
|
|
|
];
|
2021-06-18 13:43:36 +03:00
|
|
|
if (refreshWhenTypes.includes(e.getType() as EventType)) this.forceUpdate();
|
2019-01-30 00:30:53 +03:00
|
|
|
};
|
|
|
|
|
2021-06-08 18:40:01 +03:00
|
|
|
private onEncryptionChange = () => {
|
2019-03-01 06:34:34 +03:00
|
|
|
Modal.createTrackedDialog('Enable encryption', '', QuestionDialog, {
|
|
|
|
title: _t('Enable encryption?'),
|
|
|
|
description: _t(
|
|
|
|
"Once enabled, encryption for a room cannot be disabled. Messages sent in an encrypted " +
|
2019-03-01 06:45:31 +03:00
|
|
|
"room cannot be seen by the server, only by the participants of the room. Enabling encryption " +
|
2019-03-01 06:34:34 +03:00
|
|
|
"may prevent many bots and bridges from working correctly. <a>Learn more about encryption.</a>",
|
|
|
|
{},
|
|
|
|
{
|
2021-07-23 12:23:45 +03:00
|
|
|
a: sub => <a
|
|
|
|
href="https://element.io/help#encryption"
|
|
|
|
rel="noreferrer noopener"
|
|
|
|
target="_blank"
|
2021-07-20 00:43:11 +03:00
|
|
|
>{ sub }</a>,
|
2019-03-01 06:34:34 +03:00
|
|
|
},
|
|
|
|
),
|
|
|
|
onFinished: (confirm) => {
|
|
|
|
if (!confirm) {
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ encrypted: false });
|
2019-03-01 06:34:34 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const beforeEncrypted = this.state.encrypted;
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ encrypted: true });
|
2019-03-01 06:34:34 +03:00
|
|
|
MatrixClientPeg.get().sendStateEvent(
|
2021-06-18 13:43:36 +03:00
|
|
|
this.props.roomId, EventType.RoomEncryption,
|
2019-03-01 06:34:34 +03:00
|
|
|
{ algorithm: "m.megolm.v1.aes-sha2" },
|
|
|
|
).catch((e) => {
|
|
|
|
console.error(e);
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ encrypted: beforeEncrypted });
|
2019-03-01 06:34:34 +03:00
|
|
|
});
|
|
|
|
},
|
2019-02-08 00:01:34 +03:00
|
|
|
});
|
2019-01-30 00:30:53 +03:00
|
|
|
};
|
|
|
|
|
2021-07-02 17:18:27 +03:00
|
|
|
private onJoinRuleChange = async (joinRule: JoinRule) => {
|
|
|
|
const beforeJoinRule = this.state.joinRule;
|
2019-01-30 00:30:53 +03:00
|
|
|
|
2021-07-06 12:10:25 +03:00
|
|
|
let restrictedAllowRoomIds: string[];
|
2021-07-02 17:18:27 +03:00
|
|
|
if (joinRule === JoinRule.Restricted) {
|
|
|
|
const matrixClient = MatrixClientPeg.get();
|
2021-07-02 16:51:55 +03:00
|
|
|
const roomId = this.props.roomId;
|
2021-07-02 17:18:27 +03:00
|
|
|
const room = matrixClient.getRoom(roomId);
|
|
|
|
|
2021-07-06 12:10:25 +03:00
|
|
|
if (beforeJoinRule === JoinRule.Restricted || this.state.roomSupportsRestricted) {
|
2021-07-02 17:18:27 +03:00
|
|
|
// Have the user pick which spaces to allow joins from
|
2021-07-06 12:10:25 +03:00
|
|
|
restrictedAllowRoomIds = await this.editRestrictedRoomIds();
|
2021-07-02 17:18:27 +03:00
|
|
|
if (!Array.isArray(restrictedAllowRoomIds)) return;
|
|
|
|
} else if (this.state.preferredRestrictionVersion) {
|
|
|
|
// Block this action on a room upgrade otherwise it'd make their room unjoinable
|
|
|
|
const targetVersion = this.state.preferredRestrictionVersion;
|
|
|
|
Modal.createTrackedDialog('Restricted join rule upgrade', '', RoomUpgradeWarningDialog, {
|
|
|
|
roomId,
|
|
|
|
targetVersion,
|
|
|
|
description: _t("This upgrade will allow members of selected spaces " +
|
|
|
|
"access to this room without an invite."),
|
|
|
|
onFinished: (resp) => {
|
|
|
|
if (!resp?.continue) return;
|
|
|
|
upgradeRoom(room, targetVersion, resp.invite);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
return;
|
|
|
|
}
|
2021-07-02 16:51:55 +03:00
|
|
|
}
|
2019-02-08 00:01:34 +03:00
|
|
|
|
2021-07-06 12:10:25 +03:00
|
|
|
if (beforeJoinRule === joinRule && !restrictedAllowRoomIds) return;
|
|
|
|
|
2021-07-02 17:18:27 +03:00
|
|
|
const content: IContent = {
|
|
|
|
join_rule: joinRule,
|
|
|
|
};
|
|
|
|
|
|
|
|
// pre-set the accepted spaces with the currently viewed one as per the microcopy
|
2021-07-06 12:10:25 +03:00
|
|
|
if (joinRule === JoinRule.Restricted) {
|
|
|
|
content.allow = restrictedAllowRoomIds.map(roomId => ({
|
2021-07-02 17:18:27 +03:00
|
|
|
"type": RestrictedAllowType.RoomMembership,
|
2021-07-06 12:10:25 +03:00
|
|
|
"room_id": roomId,
|
|
|
|
}));
|
2021-07-02 17:18:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({ joinRule, restrictedAllowRoomIds });
|
2019-02-08 00:01:34 +03:00
|
|
|
|
2019-01-30 00:30:53 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2021-07-02 17:18:27 +03:00
|
|
|
client.sendStateEvent(this.props.roomId, EventType.RoomJoinRules, content, "").catch((e) => {
|
2019-02-08 00:01:34 +03:00
|
|
|
console.error(e);
|
2021-07-02 17:18:27 +03:00
|
|
|
this.setState({
|
|
|
|
joinRule: beforeJoinRule,
|
|
|
|
restrictedAllowRoomIds: undefined,
|
|
|
|
});
|
2019-02-08 00:01:34 +03:00
|
|
|
});
|
2019-01-30 00:30:53 +03:00
|
|
|
};
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private onRestrictedRoomIdsChange = (restrictedAllowRoomIds: string[]) => {
|
|
|
|
const beforeRestrictedAllowRoomIds = this.state.restrictedAllowRoomIds;
|
2021-07-02 17:18:27 +03:00
|
|
|
if (!arrayHasDiff(beforeRestrictedAllowRoomIds || [], restrictedAllowRoomIds)) return;
|
2021-07-02 16:51:55 +03:00
|
|
|
this.setState({ restrictedAllowRoomIds });
|
2019-02-08 00:01:34 +03:00
|
|
|
|
2019-01-30 00:30:53 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2021-07-02 16:51:55 +03:00
|
|
|
client.sendStateEvent(this.props.roomId, EventType.RoomJoinRules, {
|
|
|
|
join_rule: JoinRule.Restricted,
|
|
|
|
allow: restrictedAllowRoomIds.map(roomId => ({
|
|
|
|
"type": RestrictedAllowType.RoomMembership,
|
|
|
|
"room_id": roomId,
|
|
|
|
})),
|
|
|
|
}, "").catch((e) => {
|
2019-02-08 00:01:34 +03:00
|
|
|
console.error(e);
|
2021-07-02 16:51:55 +03:00
|
|
|
this.setState({ restrictedAllowRoomIds: beforeRestrictedAllowRoomIds });
|
2019-02-08 00:01:34 +03:00
|
|
|
});
|
2019-01-30 00:30:53 +03:00
|
|
|
};
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private onGuestAccessChange = (allowed: boolean) => {
|
|
|
|
const guestAccess = allowed ? GuestAccess.CanJoin : GuestAccess.Forbidden;
|
2019-02-08 00:01:34 +03:00
|
|
|
const beforeGuestAccess = this.state.guestAccess;
|
2021-07-02 17:18:27 +03:00
|
|
|
if (beforeGuestAccess === guestAccess) return;
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
this.setState({ guestAccess });
|
2019-02-08 00:01:34 +03:00
|
|
|
|
2019-01-30 00:30:53 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2021-07-02 16:51:55 +03:00
|
|
|
client.sendStateEvent(this.props.roomId, EventType.RoomGuestAccess, {
|
2021-06-18 13:43:36 +03:00
|
|
|
guest_access: guestAccess,
|
2021-07-02 16:51:55 +03:00
|
|
|
}, "").catch((e) => {
|
2019-02-08 00:01:34 +03:00
|
|
|
console.error(e);
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ guestAccess: beforeGuestAccess });
|
2019-02-08 00:01:34 +03:00
|
|
|
});
|
2019-01-30 00:30:53 +03:00
|
|
|
};
|
|
|
|
|
2021-04-27 13:56:45 +03:00
|
|
|
private onHistoryRadioToggle = (history: HistoryVisibility) => {
|
2019-02-08 00:01:34 +03:00
|
|
|
const beforeHistory = this.state.history;
|
2021-07-02 17:18:27 +03:00
|
|
|
if (beforeHistory === history) return;
|
|
|
|
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ history: history });
|
2021-06-18 13:43:36 +03:00
|
|
|
MatrixClientPeg.get().sendStateEvent(this.props.roomId, EventType.RoomHistoryVisibility, {
|
2020-08-05 15:53:19 +03:00
|
|
|
history_visibility: history,
|
2019-02-08 00:01:34 +03:00
|
|
|
}, "").catch((e) => {
|
|
|
|
console.error(e);
|
2021-06-29 15:11:58 +03:00
|
|
|
this.setState({ history: beforeHistory });
|
2019-02-08 00:01:34 +03:00
|
|
|
});
|
2019-01-30 00:30:53 +03:00
|
|
|
};
|
|
|
|
|
2021-04-27 13:56:45 +03:00
|
|
|
private updateBlacklistDevicesFlag = (checked: boolean) => {
|
2019-03-22 23:22:20 +03:00
|
|
|
MatrixClientPeg.get().getRoom(this.props.roomId).setBlacklistUnverifiedDevices(checked);
|
|
|
|
};
|
|
|
|
|
2021-04-27 13:56:45 +03:00
|
|
|
private async hasAliases(): Promise<boolean> {
|
2020-02-19 13:18:56 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
|
|
|
if (await cli.doesServerSupportUnstableFeature("org.matrix.msc2432")) {
|
|
|
|
const response = await cli.unstableGetLocalAliases(this.props.roomId);
|
|
|
|
const localAliases = response.aliases;
|
|
|
|
return Array.isArray(localAliases) && localAliases.length !== 0;
|
|
|
|
} else {
|
|
|
|
const room = cli.getRoom(this.props.roomId);
|
2021-06-18 13:43:36 +03:00
|
|
|
const aliasEvents = room.currentState.getStateEvents(EventType.RoomAliases) || [];
|
2020-02-19 13:18:56 +03:00
|
|
|
const hasAliases = !!aliasEvents.find((ev) => (ev.getContent().aliases || []).length > 0);
|
|
|
|
return hasAliases;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-06 12:10:25 +03:00
|
|
|
private editRestrictedRoomIds = async (): Promise<string[] | undefined> => {
|
|
|
|
let selected = this.state.restrictedAllowRoomIds;
|
|
|
|
if (!selected?.length && SpaceStore.instance.activeSpace) {
|
|
|
|
selected = [SpaceStore.instance.activeSpace.roomId];
|
|
|
|
}
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
const matrixClient = MatrixClientPeg.get();
|
2021-07-06 12:10:25 +03:00
|
|
|
const { finished } = Modal.createTrackedDialog('Edit restricted', '', ManageRestrictedJoinRuleDialog, {
|
2021-07-02 16:51:55 +03:00
|
|
|
matrixClient,
|
|
|
|
room: matrixClient.getRoom(this.props.roomId),
|
2021-07-06 12:10:25 +03:00
|
|
|
selected,
|
2021-07-02 16:51:55 +03:00
|
|
|
}, "mx_ManageRestrictedJoinRuleDialog_wrapper");
|
2021-07-06 12:10:25 +03:00
|
|
|
|
|
|
|
const [restrictedAllowRoomIds] = await finished;
|
|
|
|
return restrictedAllowRoomIds;
|
|
|
|
};
|
|
|
|
|
|
|
|
private onEditRestrictedClick = async () => {
|
|
|
|
const restrictedAllowRoomIds = await this.editRestrictedRoomIds();
|
|
|
|
if (!Array.isArray(restrictedAllowRoomIds)) return;
|
|
|
|
if (restrictedAllowRoomIds.length > 0) {
|
|
|
|
this.onRestrictedRoomIdsChange(restrictedAllowRoomIds);
|
|
|
|
} else {
|
|
|
|
this.onJoinRuleChange(JoinRule.Invite);
|
|
|
|
}
|
2021-07-02 16:51:55 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
private renderJoinRule() {
|
2019-01-30 00:30:53 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client.getRoom(this.props.roomId);
|
2019-02-08 00:01:34 +03:00
|
|
|
const joinRule = this.state.joinRule;
|
2019-01-30 00:30:53 +03:00
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
const canChangeJoinRule = room.currentState.mayClientSendStateEvent(EventType.RoomJoinRules, client);
|
2019-01-30 00:30:53 +03:00
|
|
|
|
|
|
|
let aliasWarning = null;
|
2021-06-18 13:43:36 +03:00
|
|
|
if (joinRule === JoinRule.Public && !this.state.hasAliases) {
|
2019-01-30 00:30:53 +03:00
|
|
|
aliasWarning = (
|
|
|
|
<div className='mx_SecurityRoomSettingsTab_warning'>
|
2019-02-22 20:47:18 +03:00
|
|
|
<img src={require("../../../../../../res/img/warning.svg")} width={15} height={15} />
|
2019-01-30 00:30:53 +03:00
|
|
|
<span>
|
2021-07-21 12:46:41 +03:00
|
|
|
{ _t("To link to this room, please add an address.") }
|
2019-01-30 00:30:53 +03:00
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
const radioDefinitions: IDefinition<JoinRule>[] = [{
|
|
|
|
value: JoinRule.Invite,
|
|
|
|
label: _t("Private (invite only)"),
|
|
|
|
description: _t("Only invited people can join."),
|
2021-07-06 12:10:25 +03:00
|
|
|
checked: this.state.joinRule === JoinRule.Invite
|
|
|
|
|| (this.state.joinRule === JoinRule.Restricted && !this.state.restrictedAllowRoomIds?.length),
|
2021-07-02 16:51:55 +03:00
|
|
|
}, {
|
|
|
|
value: JoinRule.Public,
|
2021-07-21 12:43:12 +03:00
|
|
|
label: _t("Public"),
|
2021-07-02 16:51:55 +03:00
|
|
|
description: _t("Anyone can find and join."),
|
|
|
|
}];
|
|
|
|
|
|
|
|
if (this.state.roomSupportsRestricted ||
|
|
|
|
this.state.preferredRestrictionVersion ||
|
|
|
|
joinRule === JoinRule.Restricted
|
|
|
|
) {
|
|
|
|
let upgradeRequiredPill;
|
|
|
|
if (this.state.preferredRestrictionVersion) {
|
|
|
|
upgradeRequiredPill = <span className="mx_SecurityRoomSettingsTab_upgradeRequired">
|
|
|
|
{ _t("Upgrade required") }
|
|
|
|
</span>;
|
|
|
|
}
|
2021-06-18 13:43:36 +03:00
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
let description;
|
2021-07-06 12:10:25 +03:00
|
|
|
if (joinRule === JoinRule.Restricted && this.state.restrictedAllowRoomIds?.length) {
|
|
|
|
const shownSpaces = this.state.restrictedAllowRoomIds
|
|
|
|
.map(roomId => client.getRoom(roomId))
|
|
|
|
.filter(room => room?.isSpaceRoom())
|
|
|
|
.slice(0, 4);
|
|
|
|
|
|
|
|
let moreText;
|
|
|
|
if (shownSpaces.length < this.state.restrictedAllowRoomIds.length) {
|
|
|
|
if (shownSpaces.length > 0) {
|
|
|
|
moreText = _t("& %(count)s more", {
|
|
|
|
count: this.state.restrictedAllowRoomIds.length - shownSpaces.length,
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
moreText = _t("Currently, %(count)s spaces have access", {
|
|
|
|
count: this.state.restrictedAllowRoomIds.length,
|
|
|
|
});
|
|
|
|
}
|
2021-07-02 16:51:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
description = <div>
|
2019-01-30 00:30:53 +03:00
|
|
|
<span>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ _t("Anyone in a space can find and join. <a>Edit which spaces can access here.</a>", {}, {
|
|
|
|
a: sub => <AccessibleButton
|
|
|
|
disabled={!canChangeJoinRule}
|
|
|
|
onClick={this.onEditRestrictedClick}
|
|
|
|
kind="link"
|
|
|
|
>
|
|
|
|
{ sub }
|
|
|
|
</AccessibleButton>,
|
|
|
|
}) }
|
2019-01-30 00:30:53 +03:00
|
|
|
</span>
|
2021-07-06 12:10:25 +03:00
|
|
|
|
|
|
|
<div className="mx_SecurityRoomSettingsTab_spacesWithAccess">
|
|
|
|
<h4>{ _t("Spaces with access") }</h4>
|
|
|
|
{ shownSpaces.map(room => {
|
|
|
|
return <span key={room.roomId}>
|
|
|
|
<RoomAvatar room={room} height={32} width={32} />
|
|
|
|
{ room.name }
|
|
|
|
</span>;
|
2021-07-21 13:27:36 +03:00
|
|
|
}) }
|
2021-07-06 12:10:25 +03:00
|
|
|
{ moreText && <span>{ moreText }</span> }
|
|
|
|
</div>
|
2021-07-02 16:51:55 +03:00
|
|
|
</div>;
|
|
|
|
} else if (SpaceStore.instance.activeSpace) {
|
|
|
|
description = _t("Anyone in %(spaceName)s can find and join. You can select other spaces too.", {
|
|
|
|
spaceName: SpaceStore.instance.activeSpace.name,
|
2021-06-18 14:18:23 +03:00
|
|
|
});
|
2021-07-02 16:51:55 +03:00
|
|
|
} else {
|
|
|
|
description = _t("Anyone in a space can find and join. You can select multiple spaces.");
|
2021-06-18 14:18:23 +03:00
|
|
|
}
|
2021-07-02 16:51:55 +03:00
|
|
|
|
|
|
|
radioDefinitions.splice(1, 0, {
|
|
|
|
value: JoinRule.Restricted,
|
|
|
|
label: <>
|
|
|
|
{ _t("Space members") }
|
|
|
|
{ upgradeRequiredPill }
|
|
|
|
</>,
|
|
|
|
description,
|
2021-07-06 12:10:25 +03:00
|
|
|
// if there are 0 allowed spaces then render it as invite only instead
|
|
|
|
checked: this.state.joinRule === JoinRule.Restricted && !!this.state.restrictedAllowRoomIds?.length,
|
2021-07-02 16:51:55 +03:00
|
|
|
});
|
2019-01-30 00:30:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2021-07-02 16:51:55 +03:00
|
|
|
<div className="mx_SecurityRoomSettingsTab_joinRule">
|
|
|
|
<div className="mx_SettingsTab_subsectionText">
|
2021-07-21 13:20:41 +03:00
|
|
|
<span>{ _t("Decide who can join %(roomName)s.", {
|
2021-07-02 16:51:55 +03:00
|
|
|
roomName: client.getRoom(this.props.roomId)?.name,
|
|
|
|
}) }</span>
|
|
|
|
</div>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ aliasWarning }
|
2020-07-28 19:13:58 +03:00
|
|
|
<StyledRadioGroup
|
2021-07-02 16:51:55 +03:00
|
|
|
name="joinRule"
|
2020-07-28 19:13:58 +03:00
|
|
|
value={joinRule}
|
2021-07-02 16:51:55 +03:00
|
|
|
onChange={this.onJoinRuleChange}
|
2021-06-18 13:43:36 +03:00
|
|
|
definitions={radioDefinitions}
|
2021-07-02 16:51:55 +03:00
|
|
|
disabled={!canChangeJoinRule}
|
2020-07-28 19:13:58 +03:00
|
|
|
/>
|
2019-01-30 00:30:53 +03:00
|
|
|
</div>
|
2019-01-30 00:37:21 +03:00
|
|
|
);
|
2019-01-30 00:30:53 +03:00
|
|
|
}
|
|
|
|
|
2021-04-26 16:02:53 +03:00
|
|
|
private renderHistory() {
|
2019-01-30 00:30:53 +03:00
|
|
|
const client = MatrixClientPeg.get();
|
2019-02-08 00:01:34 +03:00
|
|
|
const history = this.state.history;
|
|
|
|
const state = client.getRoom(this.props.roomId).currentState;
|
2021-06-18 13:43:36 +03:00
|
|
|
const canChangeHistory = state.mayClientSendStateEvent(EventType.RoomHistoryVisibility, client);
|
2019-01-30 00:30:53 +03:00
|
|
|
|
2021-04-30 01:13:06 +03:00
|
|
|
const options = [
|
|
|
|
{
|
|
|
|
value: HistoryVisibility.Shared,
|
|
|
|
label: _t('Members only (since the point in time of selecting this option)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: HistoryVisibility.Invited,
|
|
|
|
label: _t('Members only (since they were invited)'),
|
|
|
|
},
|
|
|
|
{
|
|
|
|
value: HistoryVisibility.Joined,
|
|
|
|
label: _t('Members only (since they joined)'),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
// World readable doesn't make sense for encrypted rooms
|
|
|
|
if (!this.state.encrypted || history === HistoryVisibility.WorldReadable) {
|
|
|
|
options.unshift({
|
|
|
|
value: HistoryVisibility.WorldReadable,
|
|
|
|
label: _t("Anyone"),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-30 00:30:53 +03:00
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<div>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ _t('Changes to who can read history will only apply to future messages in this room. ' +
|
|
|
|
'The visibility of existing history will be unchanged.') }
|
2019-01-30 00:30:53 +03:00
|
|
|
</div>
|
2020-07-28 19:13:58 +03:00
|
|
|
<StyledRadioGroup
|
|
|
|
name="historyVis"
|
|
|
|
value={history}
|
2021-04-26 16:02:53 +03:00
|
|
|
onChange={this.onHistoryRadioToggle}
|
2021-07-14 06:08:43 +03:00
|
|
|
disabled={!canChangeHistory}
|
2021-04-30 01:13:06 +03:00
|
|
|
definitions={options}
|
2020-07-28 19:13:58 +03:00
|
|
|
/>
|
2019-01-30 00:30:53 +03:00
|
|
|
</div>
|
2019-01-30 00:37:21 +03:00
|
|
|
);
|
2019-01-30 00:30:53 +03:00
|
|
|
}
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
private toggleAdvancedSection = () => {
|
|
|
|
this.setState({ showAdvancedSection: !this.state.showAdvancedSection });
|
|
|
|
};
|
|
|
|
|
|
|
|
private renderAdvanced() {
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const guestAccess = this.state.guestAccess;
|
|
|
|
const state = client.getRoom(this.props.roomId).currentState;
|
|
|
|
const canSetGuestAccess = state.mayClientSendStateEvent(EventType.RoomGuestAccess, client);
|
|
|
|
|
2021-07-06 12:10:25 +03:00
|
|
|
return <div className="mx_SettingsTab_section">
|
2021-07-02 16:51:55 +03:00
|
|
|
<LabelledToggleSwitch
|
|
|
|
value={guestAccess === GuestAccess.CanJoin}
|
|
|
|
onChange={this.onGuestAccessChange}
|
|
|
|
disabled={!canSetGuestAccess}
|
|
|
|
label={_t("Enable guest access")}
|
|
|
|
/>
|
|
|
|
<p>
|
|
|
|
{ _t("People with supported clients will be able to join " +
|
|
|
|
"the room without having a registered account.") }
|
|
|
|
</p>
|
2021-07-06 12:10:25 +03:00
|
|
|
</div>;
|
2021-07-02 16:51:55 +03:00
|
|
|
}
|
|
|
|
|
2019-01-30 00:30:53 +03:00
|
|
|
render() {
|
|
|
|
const client = MatrixClientPeg.get();
|
|
|
|
const room = client.getRoom(this.props.roomId);
|
2019-02-08 00:01:34 +03:00
|
|
|
const isEncrypted = this.state.encrypted;
|
2021-06-18 13:43:36 +03:00
|
|
|
const hasEncryptionPermission = room.currentState.mayClientSendStateEvent(EventType.RoomEncryption, client);
|
2019-01-30 00:30:53 +03:00
|
|
|
const canEnableEncryption = !isEncrypted && hasEncryptionPermission;
|
|
|
|
|
|
|
|
let encryptionSettings = null;
|
2020-09-18 20:33:02 +03:00
|
|
|
if (isEncrypted && SettingsStore.isEnabled("blacklistUnverifiedDevices")) {
|
|
|
|
encryptionSettings = <SettingsFlag
|
|
|
|
name="blacklistUnverifiedDevices"
|
|
|
|
level={SettingLevel.ROOM_DEVICE}
|
2021-04-26 16:02:53 +03:00
|
|
|
onChange={this.updateBlacklistDevicesFlag}
|
2020-09-18 20:33:02 +03:00
|
|
|
roomId={this.props.roomId}
|
|
|
|
/>;
|
2019-01-30 00:30:53 +03:00
|
|
|
}
|
|
|
|
|
2020-10-28 04:20:25 +03:00
|
|
|
let historySection = (<>
|
2021-07-20 00:43:11 +03:00
|
|
|
<span className='mx_SettingsTab_subheading'>{ _t("Who can read history?") }</span>
|
2020-10-28 04:20:25 +03:00
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ this.renderHistory() }
|
2020-10-28 04:20:25 +03:00
|
|
|
</div>
|
|
|
|
</>);
|
|
|
|
if (!SettingsStore.getValue(UIFeature.RoomHistorySettings)) {
|
|
|
|
historySection = null;
|
|
|
|
}
|
|
|
|
|
2019-01-30 00:30:53 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_SettingsTab mx_SecurityRoomSettingsTab">
|
2021-07-20 00:43:11 +03:00
|
|
|
<div className="mx_SettingsTab_heading">{ _t("Security & Privacy") }</div>
|
2019-01-30 00:30:53 +03:00
|
|
|
|
2021-07-20 00:43:11 +03:00
|
|
|
<span className='mx_SettingsTab_subheading'>{ _t("Encryption") }</span>
|
2019-01-30 00:30:53 +03:00
|
|
|
<div className='mx_SettingsTab_section mx_SecurityRoomSettingsTab_encryptionSection'>
|
2019-01-30 00:37:21 +03:00
|
|
|
<div>
|
|
|
|
<div className='mx_SettingsTab_subsectionText'>
|
2021-07-20 00:43:11 +03:00
|
|
|
<span>{ _t("Once enabled, encryption cannot be disabled.") }</span>
|
2019-01-30 00:37:21 +03:00
|
|
|
</div>
|
2021-07-23 12:23:45 +03:00
|
|
|
<LabelledToggleSwitch
|
|
|
|
value={isEncrypted}
|
|
|
|
onChange={this.onEncryptionChange}
|
|
|
|
label={_t("Encrypted")}
|
|
|
|
disabled={!canEnableEncryption}
|
2021-04-23 20:11:54 +03:00
|
|
|
/>
|
2019-01-30 00:37:21 +03:00
|
|
|
</div>
|
2021-07-20 00:43:11 +03:00
|
|
|
{ encryptionSettings }
|
2019-01-30 00:30:53 +03:00
|
|
|
</div>
|
|
|
|
|
2021-07-21 12:46:41 +03:00
|
|
|
<span className='mx_SettingsTab_subheading'>{ _t("Access") }</span>
|
2019-01-30 00:30:53 +03:00
|
|
|
<div className='mx_SettingsTab_section mx_SettingsTab_subsectionText'>
|
2021-07-02 16:51:55 +03:00
|
|
|
{ this.renderJoinRule() }
|
2019-01-30 00:30:53 +03:00
|
|
|
</div>
|
|
|
|
|
2021-07-02 16:51:55 +03:00
|
|
|
<AccessibleButton
|
|
|
|
onClick={this.toggleAdvancedSection}
|
|
|
|
kind="link"
|
|
|
|
className="mx_SettingsTab_showAdvanced"
|
|
|
|
>
|
|
|
|
{ this.state.showAdvancedSection ? _t("Hide advanced") : _t("Show advanced") }
|
|
|
|
</AccessibleButton>
|
|
|
|
{ this.state.showAdvancedSection && this.renderAdvanced() }
|
|
|
|
|
2021-07-20 00:43:11 +03:00
|
|
|
{ historySection }
|
2019-01-30 00:30:53 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|