* add link_inline accessiblebutton variant * valid anchors in SecurityRoomSettingsTab Signed-off-by: Kerry Archibald <kerrya@element.io> * new room intro link button Signed-off-by: Kerry Archibald <kerrya@element.io> * replace anchor with button in rerequest encryption keys message Signed-off-by: Kerry Archibald <kerrya@element.io> * inline button in UrlPreviewSettings Signed-off-by: Kerry Archibald <kerrya@element.io> * ButtonResetDefault mixin Signed-off-by: Kerry Archibald <kerrya@element.io> * inline link buttons in TextForEvent Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in InviteDialog Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in DevToolsDialog Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in login/registration/reset pword flows Signed-off-by: Kerry Archibald <kerrya@element.io> * fix types after fixing anchors in devtools Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in MemberEventListSummary Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in ReactionsRow and RoomUpgrade Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in ReplyChain Signed-off-by: Kerry Archibald <kerrya@element.io> * fix more anchors Signed-off-by: Kerry Archibald <kerrya@element.io> * fix anchors in auth comps * stylelint fixes Signed-off-by: Kerry Archibald <kerrya@element.io> * remove ignore of jsx-a11y rule that is not added yet Signed-off-by: Kerry Archibald <kerrya@element.io> * devtools style important explainer Signed-off-by: Kerry Archibald <kerrya@element.io> * translate button alt in devtools dialog Signed-off-by: Kerry Archibald <kerrya@element.io> * AccessibleButton is reactionsrow Signed-off-by: Kerry Archibald <kerrya@element.io> * fix viewsourcevent button placement, use AccessibleButton Signed-off-by: Kerry Archibald <kerrya@element.io> * use AccessibleButton in EventTile Signed-off-by: Kerry Archibald <kerrya@element.io> * unignore jsx-a11y/anchor-is-valid Signed-off-by: Kerry Archibald <kerrya@element.io> * fix lint issue in test jsx Signed-off-by: Kerry Archibald <kerrya@element.io> * update coment Signed-off-by: Kerry Archibald <kerrya@element.io>
125 lines
5.1 KiB
TypeScript
125 lines
5.1 KiB
TypeScript
/*
|
|
Copyright 2016 OpenMarket Ltd
|
|
Copyright 2017 Travis Ralston
|
|
Copyright 2018, 2019 New Vector Ltd
|
|
Copyright 2019 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 from 'react';
|
|
import { Room } from "matrix-js-sdk/src/models/room";
|
|
|
|
import { _t, _td } from '../../../languageHandler';
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
|
import dis from "../../../dispatcher/dispatcher";
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
|
import { Action } from "../../../dispatcher/actions";
|
|
import { SettingLevel } from "../../../settings/SettingLevel";
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
|
import SettingsFlag from "../elements/SettingsFlag";
|
|
import SettingsFieldset from '../settings/SettingsFieldset';
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
|
|
|
interface IProps {
|
|
room: Room;
|
|
}
|
|
|
|
@replaceableComponent("views.room_settings.UrlPreviewSettings")
|
|
export default class UrlPreviewSettings extends React.Component<IProps> {
|
|
private onClickUserSettings = (e: React.MouseEvent): void => {
|
|
e.preventDefault();
|
|
e.stopPropagation();
|
|
dis.fire(Action.ViewUserSettings);
|
|
};
|
|
|
|
public render(): JSX.Element {
|
|
const roomId = this.props.room.roomId;
|
|
const isEncrypted = MatrixClientPeg.get().isRoomEncrypted(roomId);
|
|
|
|
let previewsForAccount = null;
|
|
let previewsForRoom = null;
|
|
|
|
if (!isEncrypted) {
|
|
// Only show account setting state and room state setting state in non-e2ee rooms where they apply
|
|
const accountEnabled = SettingsStore.getValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled");
|
|
if (accountEnabled) {
|
|
previewsForAccount = (
|
|
_t("You have <a>enabled</a> URL previews by default.", {}, {
|
|
'a': (sub) => <AccessibleButton
|
|
kind='link_inline'
|
|
onClick={this.onClickUserSettings}>
|
|
{ sub }
|
|
</AccessibleButton>,
|
|
})
|
|
);
|
|
} else {
|
|
previewsForAccount = (
|
|
_t("You have <a>disabled</a> URL previews by default.", {}, {
|
|
'a': (sub) => <AccessibleButton
|
|
kind='link_inline'
|
|
onClick={this.onClickUserSettings}>
|
|
{ sub }
|
|
</AccessibleButton>,
|
|
})
|
|
);
|
|
}
|
|
|
|
if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, SettingLevel.ROOM)) {
|
|
previewsForRoom = (
|
|
<label>
|
|
<SettingsFlag
|
|
name="urlPreviewsEnabled"
|
|
level={SettingLevel.ROOM}
|
|
roomId={roomId}
|
|
isExplicit={true}
|
|
/>
|
|
</label>
|
|
);
|
|
} else {
|
|
let str = _td("URL previews are enabled by default for participants in this room.");
|
|
if (!SettingsStore.getValueAt(SettingLevel.ROOM, "urlPreviewsEnabled", roomId, /*explicit=*/true)) {
|
|
str = _td("URL previews are disabled by default for participants in this room.");
|
|
}
|
|
previewsForRoom = (<label>{ _t(str) }</label>);
|
|
}
|
|
} else {
|
|
previewsForAccount = (
|
|
_t("In encrypted rooms, like this one, URL previews are disabled by default to ensure that your " +
|
|
"homeserver (where the previews are generated) cannot gather information about links you see in " +
|
|
"this room.")
|
|
);
|
|
}
|
|
|
|
const previewsForRoomAccount = ( // in an e2ee room we use a special key to enforce per-room opt-in
|
|
<SettingsFlag name={isEncrypted ? 'urlPreviewsEnabled_e2ee' : 'urlPreviewsEnabled'}
|
|
level={SettingLevel.ROOM_ACCOUNT}
|
|
roomId={roomId} />
|
|
);
|
|
|
|
const description = <>
|
|
<p>
|
|
{ _t('When someone puts a URL in their message, a URL preview can be shown to give more ' +
|
|
'information about that link such as the title, description, and an image from the website.') }
|
|
</p>
|
|
<p>{ previewsForAccount }</p>
|
|
</>;
|
|
|
|
return (
|
|
<SettingsFieldset legend={_t("URL Previews")} description={description}>
|
|
{ previewsForRoom }
|
|
<label>{ previewsForRoomAccount }</label>
|
|
</SettingsFieldset>
|
|
);
|
|
}
|
|
}
|