2016-07-20 14:03:13 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-10-30 06:48:29 +03:00
|
|
|
Copyright 2017 Travis Ralston
|
2019-01-28 23:52:59 +03:00
|
|
|
Copyright 2018-2019 New Vector Ltd
|
2016-07-20 14:03:13 +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.
|
|
|
|
*/
|
|
|
|
|
2019-09-06 20:37:43 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 20:37:43 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
|
|
|
import sdk from "../../../index";
|
2017-11-16 16:12:03 +03:00
|
|
|
import { _t, _td } from '../../../languageHandler';
|
2017-11-04 08:19:45 +03:00
|
|
|
import SettingsStore, {SettingLevel} from "../../../settings/SettingsStore";
|
2019-01-28 23:52:59 +03:00
|
|
|
import dis from "../../../dispatcher";
|
|
|
|
import MatrixClientPeg from "../../../MatrixClientPeg";
|
2016-07-20 14:03:13 +03:00
|
|
|
|
|
|
|
|
2019-09-06 20:37:43 +03:00
|
|
|
module.exports = createReactClass({
|
2016-07-20 14:03:13 +03:00
|
|
|
displayName: 'UrlPreviewSettings',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
room: PropTypes.object,
|
2016-07-20 14:03:13 +03:00
|
|
|
},
|
|
|
|
|
2019-01-28 23:52:59 +03:00
|
|
|
_onClickUserSettings: (e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
dis.dispatch({action: 'view_user_settings'});
|
2017-10-30 07:18:03 +03:00
|
|
|
},
|
|
|
|
|
2017-10-30 06:48:29 +03:00
|
|
|
render: function() {
|
2017-10-31 05:08:27 +03:00
|
|
|
const SettingsFlag = sdk.getComponent("elements.SettingsFlag");
|
2017-10-30 06:48:29 +03:00
|
|
|
const roomId = this.props.room.roomId;
|
2019-01-28 23:52:59 +03:00
|
|
|
const isEncrypted = MatrixClientPeg.get().isRoomEncrypted(roomId);
|
2016-07-20 14:03:13 +03:00
|
|
|
|
2017-10-30 06:48:29 +03:00
|
|
|
let previewsForAccount = null;
|
2018-06-21 03:16:01 +03:00
|
|
|
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.", {}, {
|
2019-01-28 23:52:59 +03:00
|
|
|
'a': (sub)=><a onClick={this._onClickUserSettings} href=''>{ sub }</a>,
|
2018-06-21 03:16:01 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
} else if (accountEnabled) {
|
|
|
|
previewsForAccount = (
|
|
|
|
_t("You have <a>disabled</a> URL previews by default.", {}, {
|
2019-01-28 23:52:59 +03:00
|
|
|
'a': (sub)=><a onClick={this._onClickUserSettings} href=''>{ sub }</a>,
|
2018-06-21 03:16:01 +03:00
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, "room")) {
|
|
|
|
previewsForRoom = (
|
|
|
|
<label>
|
|
|
|
<SettingsFlag name="urlPreviewsEnabled"
|
|
|
|
level={SettingLevel.ROOM}
|
2018-06-22 20:44:54 +03:00
|
|
|
roomId={roomId}
|
2019-01-28 23:52:59 +03:00
|
|
|
isExplicit={true} />
|
2018-06-21 03:16:01 +03:00
|
|
|
</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>);
|
|
|
|
}
|
2017-10-30 06:48:29 +03:00
|
|
|
} else {
|
|
|
|
previewsForAccount = (
|
2018-06-21 03:40:16 +03:00
|
|
|
_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.")
|
2017-06-02 12:18:31 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-06-22 20:44:54 +03:00
|
|
|
const previewsForRoomAccount = ( // in an e2ee room we use a special key to enforce per-room opt-in
|
|
|
|
<SettingsFlag name={isEncrypted ? 'urlPreviewsEnabled_e2ee' : 'urlPreviewsEnabled'}
|
2017-11-05 01:32:13 +03:00
|
|
|
level={SettingLevel.ROOM_ACCOUNT}
|
2019-01-28 23:52:59 +03:00
|
|
|
roomId={roomId} />
|
2017-10-30 06:48:29 +03:00
|
|
|
);
|
|
|
|
|
2016-07-20 14:03:13 +03:00
|
|
|
return (
|
2019-01-28 23:52:59 +03:00
|
|
|
<div>
|
|
|
|
<div className='mx_SettingsTab_subsectionText'>
|
2018-06-21 03:40:16 +03:00
|
|
|
{ _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.') }
|
|
|
|
</div>
|
2019-01-28 23:52:59 +03:00
|
|
|
<div className='mx_SettingsTab_subsectionText'>
|
2018-06-21 03:40:16 +03:00
|
|
|
{ previewsForAccount }
|
|
|
|
</div>
|
2017-10-30 06:48:29 +03:00
|
|
|
{ previewsForRoom }
|
|
|
|
<label>{ previewsForRoomAccount }</label>
|
2016-07-20 14:03:13 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
},
|
2017-01-20 17:22:27 +03:00
|
|
|
});
|