From ce24165e19a1b61f1447306b68d35c569d72de2f Mon Sep 17 00:00:00 2001 From: Matthew Hodgson Date: Fri, 8 Feb 2019 16:44:03 +0000 Subject: [PATCH 1/4] port over low_bandwidth mode to develop --- src/Lifecycle.js | 5 ++++- src/MatrixClientPeg.js | 2 +- src/components/structures/TimelinePanel.js | 2 ++ src/components/structures/UserSettings.js | 9 ++++++++- src/components/views/avatars/BaseAvatar.js | 11 ++++++++--- src/components/views/rooms/MessageComposerInput.js | 1 + src/i18n/strings/en_EN.json | 1 + src/settings/Settings.js | 5 +++++ 8 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 54ac605c65..2ea8aa190a 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -31,6 +31,7 @@ import Modal from './Modal'; import sdk from './index'; import ActiveWidgetStore from './stores/ActiveWidgetStore'; import PlatformPeg from "./PlatformPeg"; +import SettingsStore from "./settings/SettingsStore"; import {sendLoginRequest} from "./Login"; /** @@ -440,7 +441,9 @@ async function startMatrixClient() { Notifier.start(); UserActivity.start(); - Presence.start(); + if (!SettingsStore.getValue("lowBandwidth")) { + Presence.start(); + } DMRoomMap.makeShared().start(); ActiveWidgetStore.start(); diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 882a913452..12301e3716 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -115,7 +115,7 @@ class MatrixClientPeg { // try to initialise e2e on the new client try { // check that we have a version of the js-sdk which includes initCrypto - if (this.matrixClient.initCrypto) { + if (!SettingsStore.getValue("lowBandwidth") && this.matrixClient.initCrypto) { await this.matrixClient.initCrypto(); } } catch (e) { diff --git a/src/components/structures/TimelinePanel.js b/src/components/structures/TimelinePanel.js index 9fe83c2c2d..3bdcf542b1 100644 --- a/src/components/structures/TimelinePanel.js +++ b/src/components/structures/TimelinePanel.js @@ -584,6 +584,8 @@ var TimelinePanel = React.createClass({ }, sendReadReceipt: function() { + if (SettingsStore.getValue("lowBandwidth")) return; + if (!this.refs.messagePanel) return; if (!this.props.manageReadReceipts) return; // This happens on user_activity_end which is delayed, and it's diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index 809b06c3d6..0aa564cc85 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -84,6 +84,13 @@ const SIMPLE_SETTINGS = [ { id: "enableWidgetScreenshots" }, { id: "pinMentionedRooms" }, { id: "pinUnreadRooms" }, + { + id: "lowBandwidth", + fn: () => { + PlatformPeg.get().reload(); + }, + level: SettingLevel.DEVICE, + }, { id: "showDeveloperTools" }, { id: "promptBeforeInviteUnknownUsers" }, ]; @@ -644,7 +651,7 @@ module.exports = React.createClass({
); diff --git a/src/components/views/avatars/BaseAvatar.js b/src/components/views/avatars/BaseAvatar.js index 47de7c9dc4..7241e7cd4c 100644 --- a/src/components/views/avatars/BaseAvatar.js +++ b/src/components/views/avatars/BaseAvatar.js @@ -20,6 +20,7 @@ import PropTypes from 'prop-types'; import { MatrixClient } from 'matrix-js-sdk'; import AvatarLogic from '../../../Avatar'; import sdk from '../../../index'; +import SettingsStore from "../../../settings/SettingsStore"; import AccessibleButton from '../elements/AccessibleButton'; module.exports = React.createClass({ @@ -104,9 +105,13 @@ module.exports = React.createClass({ // work out the full set of urls to try to load. This is formed like so: // imageUrls: [ props.url, props.urls, default image ] - const urls = props.urls || []; - if (props.url) { - urls.unshift(props.url); // put in urls[0] + let urls = []; + if (!SettingsStore.getValue("lowBandwidth")) { + urls = props.urls || []; + + if (props.url) { + urls.unshift(props.url); // put in urls[0] + } } let defaultImageUrl = null; diff --git a/src/components/views/rooms/MessageComposerInput.js b/src/components/views/rooms/MessageComposerInput.js index ab89e402ae..0e9442edb9 100644 --- a/src/components/views/rooms/MessageComposerInput.js +++ b/src/components/views/rooms/MessageComposerInput.js @@ -487,6 +487,7 @@ export default class MessageComposerInput extends React.Component { sendTyping(isTyping) { if (!SettingsStore.getValue('sendTypingNotifications')) return; + if (SettingsStore.getValue('lowBandwidth')) return; MatrixClientPeg.get().sendTyping( this.props.room.roomId, this.isTyping, TYPING_SERVER_TIMEOUT, diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 623dd92613..e29be2da45 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -300,6 +300,7 @@ "Enable widget screenshots on supported widgets": "Enable widget screenshots on supported widgets", "Prompt before sending invites to potentially invalid matrix IDs": "Prompt before sending invites to potentially invalid matrix IDs", "Show developer tools": "Show developer tools", + "Low Bandwidth Mode": "Low Bandwidth Mode", "Collecting app version information": "Collecting app version information", "Collecting logs": "Collecting logs", "Uploading report": "Uploading report", diff --git a/src/settings/Settings.js b/src/settings/Settings.js index f21e94ea4a..177a90ef5d 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -362,4 +362,9 @@ export const SETTINGS = { displayName: _td('Show developer tools'), default: false, }, + "lowBandwidth": { + supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, + displayName: _td('Low Bandwidth Mode'), + default: false, + }, }; From 0d47222132bed37fc3928dec4be27e56f8d12b9d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 30 May 2019 19:57:17 -0600 Subject: [PATCH 2/4] Add LB setting to new user settings Put under labs out of concern for https://github.com/vector-im/riot-meta/issues/66 --- .../settings/tabs/user/LabsUserSettingsTab.js | 1 + src/i18n/strings/en_EN.json | 1 + src/settings/Settings.js | 4 +++- .../controllers/LowBandwidthController.js | 24 +++++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/settings/controllers/LowBandwidthController.js diff --git a/src/components/views/settings/tabs/user/LabsUserSettingsTab.js b/src/components/views/settings/tabs/user/LabsUserSettingsTab.js index d272d74d29..23b5e516cd 100644 --- a/src/components/views/settings/tabs/user/LabsUserSettingsTab.js +++ b/src/components/views/settings/tabs/user/LabsUserSettingsTab.js @@ -53,6 +53,7 @@ export default class LabsUserSettingsTab extends React.Component { {flags} + ); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 343e75bcf3..e34ed093e7 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -339,6 +339,7 @@ "Show developer tools": "Show developer tools", "Order rooms in the room list by most important first instead of most recent": "Order rooms in the room list by most important first instead of most recent", "Show hidden events in timeline": "Show hidden events in timeline", + "Low bandwidth mode": "Low bandwidth mode", "Collecting app version information": "Collecting app version information", "Collecting logs": "Collecting logs", "Uploading report": "Uploading report", diff --git a/src/settings/Settings.js b/src/settings/Settings.js index c8778b9d5c..2c911dda80 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -23,6 +23,7 @@ import { } from "./controllers/NotificationControllers"; import CustomStatusController from "./controllers/CustomStatusController"; import ThemeController from './controllers/ThemeController'; +import LowBandwidthController from "./controllers/LowBandwidthController"; // These are just a bunch of helper arrays to avoid copy/pasting a bunch of times const LEVELS_ROOM_SETTINGS = ['device', 'room-device', 'room-account', 'account', 'config']; @@ -375,7 +376,8 @@ export const SETTINGS = { }, "lowBandwidth": { supportedLevels: LEVELS_DEVICE_ONLY_SETTINGS_WITH_CONFIG, - displayName: _td('Low Bandwidth Mode'), + displayName: _td('Low bandwidth mode'), default: false, + controller: new LowBandwidthController(), }, }; diff --git a/src/settings/controllers/LowBandwidthController.js b/src/settings/controllers/LowBandwidthController.js new file mode 100644 index 0000000000..c7796a425a --- /dev/null +++ b/src/settings/controllers/LowBandwidthController.js @@ -0,0 +1,24 @@ +/* +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 SettingController from "./SettingController"; +import PlatformPeg from "../../PlatformPeg"; + +export default class LowBandwidthController extends SettingController { + onChange(level, roomId, newValue) { + PlatformPeg.get().reload(); + } +} From a935e26ee38a556b71a0b3cd67318bae687ae94d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 30 May 2019 19:57:37 -0600 Subject: [PATCH 3/4] Add flag to config to always show labs settings --- src/components/views/dialogs/UserSettingsDialog.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/views/dialogs/UserSettingsDialog.js b/src/components/views/dialogs/UserSettingsDialog.js index 1c4509eee5..a24c18c8b2 100644 --- a/src/components/views/dialogs/UserSettingsDialog.js +++ b/src/components/views/dialogs/UserSettingsDialog.js @@ -28,6 +28,7 @@ import VoiceUserSettingsTab from "../settings/tabs/user/VoiceUserSettingsTab"; import HelpUserSettingsTab from "../settings/tabs/user/HelpUserSettingsTab"; import FlairUserSettingsTab from "../settings/tabs/user/FlairUserSettingsTab"; import sdk from "../../../index"; +import SdkConfig from "../../../SdkConfig"; export default class UserSettingsDialog extends React.Component { static propTypes = { @@ -67,7 +68,7 @@ export default class UserSettingsDialog extends React.Component { "mx_UserSettingsDialog_securityIcon", , )); - if (SettingsStore.getLabsFeatures().length > 0) { + if (SdkConfig.get()['showLabsSettings'] || SettingsStore.getLabsFeatures().length > 0) { tabs.push(new Tab( _td("Labs"), "mx_UserSettingsDialog_labsIcon", From af86cdfe9a87780d0475d7c968b0901da47d34c6 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 30 May 2019 20:02:25 -0600 Subject: [PATCH 4/4] Disable avatars in desktop notifs when in LB mode --- src/Notifier.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Notifier.js b/src/Notifier.js index 6a4f9827f7..2322311769 100644 --- a/src/Notifier.js +++ b/src/Notifier.js @@ -85,7 +85,11 @@ const Notifier = { msg = ''; } - const avatarUrl = ev.sender ? Avatar.avatarUrlForMember(ev.sender, 40, 40, 'crop') : null; + let avatarUrl = null; + if (ev.sender && !SettingsStore.getValue("lowBandwidth")) { + avatarUrl = Avatar.avatarUrlForMember(ev.sender, 40, 40, 'crop'); + } + const notif = plaf.displayNotification(title, msg, avatarUrl, room); // if displayNotification returns non-null, the platform supports