update UrlPreview settings to be more privacy-aware in e2ee rooms

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2018-06-21 01:16:01 +01:00
parent df58715a17
commit 891070d001
No known key found for this signature in database
GPG key ID: 3F879DA5AD802A5E
2 changed files with 68 additions and 30 deletions

View file

@ -618,10 +618,26 @@ module.exports = React.createClass({
} }
}, },
_updatePreviewUrlVisibility: function(room) { _updatePreviewUrlVisibility: function({roomId}) {
this.setState({ const levels = [
showUrlPreview: SettingsStore.getValue("urlPreviewsEnabled", room.roomId), SettingLevel.ROOM_DEVICE,
}); SettingLevel.ROOM_ACCOUNT,
];
let showUrlPreview;
if (MatrixClientPeg.get().isRoomEncrypted(roomId)) {
for (const level of levels) {
const value = SettingsStore.getValueAt(level, "urlPreviewsEnabled", roomId, true, true);
if (value === Boolean(value)) { // if is Boolean
showUrlPreview = value;
break;
}
}
showUrlPreview = showUrlPreview || false;
} else {
showUrlPreview = SettingsStore.getValue("urlPreviewsEnabled", roomId);
}
this.setState({showUrlPreview});
}, },
onRoom: function(room) { onRoom: function(room) {

View file

@ -1,6 +1,7 @@
/* /*
Copyright 2016 OpenMarket Ltd Copyright 2016 OpenMarket Ltd
Copyright 2017 Travis Ralston Copyright 2017 Travis Ralston
Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@ -15,6 +16,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import {MatrixClient} from "matrix-js-sdk";
const React = require('react'); const React = require('react');
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
const sdk = require("../../../index"); const sdk = require("../../../index");
@ -29,6 +31,10 @@ module.exports = React.createClass({
room: PropTypes.object, room: PropTypes.object,
}, },
contextTypes: {
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
},
saveSettings: function() { saveSettings: function() {
const promises = []; const promises = [];
if (this.refs.urlPreviewsRoom) promises.push(this.refs.urlPreviewsRoom.save()); if (this.refs.urlPreviewsRoom) promises.push(this.refs.urlPreviewsRoom.save());
@ -39,36 +45,52 @@ module.exports = React.createClass({
render: function() { render: function() {
const SettingsFlag = sdk.getComponent("elements.SettingsFlag"); const SettingsFlag = sdk.getComponent("elements.SettingsFlag");
const roomId = this.props.room.roomId; const roomId = this.props.room.roomId;
const isEncrypted = this.context.matrixClient.isRoomEncrypted(roomId);
let previewsForAccount = null; let previewsForAccount = null;
if (SettingsStore.getValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled")) {
previewsForAccount = (
_t("You have <a>enabled</a> URL previews by default.", {}, { 'a': (sub)=><a href="#/settings">{ sub }</a> })
);
} else {
previewsForAccount = (
_t("You have <a>disabled</a> URL previews by default.", {}, { 'a': (sub)=><a href="#/settings">{ sub }</a> })
);
}
let previewsForRoom = null; let previewsForRoom = null;
if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, "room")) {
previewsForRoom = (
<label> if (!isEncrypted) {
<SettingsFlag name="urlPreviewsEnabled" // Only show account setting state and room state setting state in non-e2ee rooms where they apply
level={SettingLevel.ROOM} const accountEnabled = SettingsStore.getValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled");
roomId={this.props.room.roomId} if (accountEnabled) {
isExplicit={true} previewsForAccount = (
manualSave={true} _t("You have <a>enabled</a> URL previews by default.", {}, {
ref="urlPreviewsRoom" /> 'a': (sub)=><a href="#/settings">{ sub }</a>,
</label> })
); );
} else { } else if (accountEnabled) {
let str = _td("URL previews are enabled by default for participants in this room."); previewsForAccount = (
if (!SettingsStore.getValueAt(SettingLevel.ROOM, "urlPreviewsEnabled", roomId, /*explicit=*/true)) { _t("You have <a>disabled</a> URL previews by default.", {}, {
str = _td("URL previews are disabled by default for participants in this room."); 'a': (sub)=><a href="#/settings">{ sub }</a>,
})
);
} }
previewsForRoom = (<label>{ _t(str) }</label>);
if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, "room")) {
previewsForRoom = (
<label>
<SettingsFlag name="urlPreviewsEnabled"
level={SettingLevel.ROOM}
roomId={this.props.room.roomId}
isExplicit={true}
manualSave={true}
ref="urlPreviewsRoom" />
</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("URL Previews default to off in End-to-End Encrypted rooms to protect your privacy. " +
"They are requested through your homeserver which could infer links which are otherwise encrypted")
);
} }
const previewsForRoomAccount = ( const previewsForRoomAccount = (