2016-07-20 14:03:13 +03:00
|
|
|
/*
|
|
|
|
Copyright 2016 OpenMarket Ltd
|
2017-10-30 06:48:29 +03:00
|
|
|
Copyright 2017 Travis Ralston
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-10-11 19:56:17 +03:00
|
|
|
const React = require('react');
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-10-11 19:56:17 +03:00
|
|
|
const sdk = require("../../../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";
|
2016-07-20 14:03:13 +03:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'UrlPreviewSettings',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-12-26 04:03:18 +03:00
|
|
|
room: PropTypes.object,
|
2016-07-20 14:03:13 +03:00
|
|
|
},
|
|
|
|
|
2017-10-30 07:18:03 +03:00
|
|
|
saveSettings: function() {
|
2017-11-05 05:52:20 +03:00
|
|
|
const promises = [];
|
|
|
|
if (this.refs.urlPreviewsRoom) promises.push(this.refs.urlPreviewsRoom.save());
|
2017-11-18 08:02:33 +03:00
|
|
|
if (this.refs.urlPreviewsSelf) promises.push(this.refs.urlPreviewsSelf.save());
|
2017-11-05 05:52:20 +03:00
|
|
|
return promises;
|
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;
|
2016-07-20 14:03:13 +03:00
|
|
|
|
2017-10-30 06:48:29 +03:00
|
|
|
let previewsForAccount = null;
|
2017-11-04 08:19:45 +03:00
|
|
|
if (SettingsStore.getValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled")) {
|
2017-10-30 06:48:29 +03:00
|
|
|
previewsForAccount = (
|
2017-11-15 22:40:51 +03:00
|
|
|
_t("You have <a>enabled</a> URL previews by default.", {}, { 'a': (sub)=><a href="#/settings">{ sub }</a> })
|
2016-07-20 14:03:13 +03:00
|
|
|
);
|
2017-10-30 06:48:29 +03:00
|
|
|
} else {
|
|
|
|
previewsForAccount = (
|
2017-11-15 22:40:51 +03:00
|
|
|
_t("You have <a>disabled</a> URL previews by default.", {}, { 'a': (sub)=><a href="#/settings">{ sub }</a> })
|
2016-07-20 14:03:13 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-10-30 06:48:29 +03:00
|
|
|
let previewsForRoom = null;
|
|
|
|
if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, "room")) {
|
|
|
|
previewsForRoom = (
|
2016-07-20 14:03:13 +03:00
|
|
|
<label>
|
2017-10-31 05:08:27 +03:00
|
|
|
<SettingsFlag name="urlPreviewsEnabled"
|
2017-11-05 01:32:13 +03:00
|
|
|
level={SettingLevel.ROOM}
|
|
|
|
roomId={this.props.room.roomId}
|
|
|
|
isExplicit={true}
|
|
|
|
manualSave={true}
|
|
|
|
ref="urlPreviewsRoom" />
|
2017-10-30 06:48:29 +03:00
|
|
|
</label>
|
2017-06-02 12:18:31 +03:00
|
|
|
);
|
2017-10-11 19:56:17 +03:00
|
|
|
} else {
|
2017-11-16 08:31:16 +03:00
|
|
|
let str = _td("URL previews are enabled by default for participants in this room.");
|
2017-11-18 08:03:06 +03:00
|
|
|
if (!SettingsStore.getValueAt(SettingLevel.ROOM, "urlPreviewsEnabled", roomId, /*explicit=*/true)) {
|
2017-11-16 08:31:16 +03:00
|
|
|
str = _td("URL previews are disabled by default for participants in this room.");
|
2017-10-30 06:48:29 +03:00
|
|
|
}
|
|
|
|
previewsForRoom = (<label>{ _t(str) }</label>);
|
2017-06-02 12:18:31 +03:00
|
|
|
}
|
|
|
|
|
2017-11-15 22:40:51 +03:00
|
|
|
const previewsForRoomAccount = (
|
2017-10-31 05:08:27 +03:00
|
|
|
<SettingsFlag name="urlPreviewsEnabled"
|
2017-11-05 01:32:13 +03:00
|
|
|
level={SettingLevel.ROOM_ACCOUNT}
|
|
|
|
roomId={this.props.room.roomId}
|
|
|
|
manualSave={true}
|
|
|
|
ref="urlPreviewsSelf"
|
2017-10-30 06:48:29 +03:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2016-07-20 14:03:13 +03:00
|
|
|
return (
|
|
|
|
<div className="mx_RoomSettings_toggles">
|
2017-10-11 19:56:17 +03:00
|
|
|
<h3>{ _t("URL Previews") }</h3>
|
2016-07-20 14:03:13 +03:00
|
|
|
|
2017-10-30 06:48:29 +03:00
|
|
|
<label>{ previewsForAccount }</label>
|
|
|
|
{ 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
|
|
|
});
|