From 891070d001cd6570f6156b33d8d294704fb0995f Mon Sep 17 00:00:00 2001
From: Michael Telatynski <7t3chguy@gmail.com>
Date: Thu, 21 Jun 2018 01:16:01 +0100
Subject: [PATCH] update UrlPreview settings to be more privacy-aware in e2ee
rooms
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
---
src/components/structures/RoomView.js | 24 +++++-
.../views/room_settings/UrlPreviewSettings.js | 74 ++++++++++++-------
2 files changed, 68 insertions(+), 30 deletions(-)
diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js
index 97e575ff4e..c465eff44b 100644
--- a/src/components/structures/RoomView.js
+++ b/src/components/structures/RoomView.js
@@ -618,10 +618,26 @@ module.exports = React.createClass({
}
},
- _updatePreviewUrlVisibility: function(room) {
- this.setState({
- showUrlPreview: SettingsStore.getValue("urlPreviewsEnabled", room.roomId),
- });
+ _updatePreviewUrlVisibility: function({roomId}) {
+ const levels = [
+ 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) {
diff --git a/src/components/views/room_settings/UrlPreviewSettings.js b/src/components/views/room_settings/UrlPreviewSettings.js
index ed58d610aa..749167c0a5 100644
--- a/src/components/views/room_settings/UrlPreviewSettings.js
+++ b/src/components/views/room_settings/UrlPreviewSettings.js
@@ -1,6 +1,7 @@
/*
Copyright 2016 OpenMarket Ltd
Copyright 2017 Travis Ralston
+Copyright 2018 New Vector Ltd
Licensed under the Apache License, Version 2.0 (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.
*/
+import {MatrixClient} from "matrix-js-sdk";
const React = require('react');
import PropTypes from 'prop-types';
const sdk = require("../../../index");
@@ -29,6 +31,10 @@ module.exports = React.createClass({
room: PropTypes.object,
},
+ contextTypes: {
+ matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
+ },
+
saveSettings: function() {
const promises = [];
if (this.refs.urlPreviewsRoom) promises.push(this.refs.urlPreviewsRoom.save());
@@ -39,36 +45,52 @@ module.exports = React.createClass({
render: function() {
const SettingsFlag = sdk.getComponent("elements.SettingsFlag");
const roomId = this.props.room.roomId;
+ const isEncrypted = this.context.matrixClient.isRoomEncrypted(roomId);
let previewsForAccount = null;
- if (SettingsStore.getValueAt(SettingLevel.ACCOUNT, "urlPreviewsEnabled")) {
- previewsForAccount = (
- _t("You have enabled URL previews by default.", {}, { 'a': (sub)=>{ sub } })
- );
- } else {
- previewsForAccount = (
- _t("You have disabled URL previews by default.", {}, { 'a': (sub)=>{ sub } })
- );
- }
-
let previewsForRoom = null;
- if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, "room")) {
- previewsForRoom = (
-
- );
- } 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.");
+
+
+ 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 enabled URL previews by default.", {}, {
+ 'a': (sub)=>{ sub },
+ })
+ );
+ } else if (accountEnabled) {
+ previewsForAccount = (
+ _t("You have disabled URL previews by default.", {}, {
+ 'a': (sub)=>{ sub },
+ })
+ );
}
- previewsForRoom = ();
+
+ if (SettingsStore.canSetValue("urlPreviewsEnabled", roomId, "room")) {
+ previewsForRoom = (
+
+ );
+ } 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 = ();
+ }
+ } 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 = (