From c49afe4d720598377d35117380651bc3423796a4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 8 Apr 2019 16:23:00 -0600 Subject: [PATCH 01/12] Use dedicated permalink creators in search results with multiple rooms Fixes https://github.com/vector-im/riot-web/issues/9376 This also would have happened in "All Rooms" searches. --- src/components/structures/RoomView.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 4f20b354d3..a60f19b35e 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -1161,6 +1161,10 @@ module.exports = React.createClass({ } }; + // We cache the permalink creators to avoid creating a ton of them in popular searches + const permalinkCreators = {}; // [roomId] => creator + permalinkCreators[this.state.room.roomId] = this.state.permalinkCreator; + let lastRoomId; for (let i = this.state.searchResults.results.length - 1; i >= 0; i--) { @@ -1168,6 +1172,7 @@ module.exports = React.createClass({ const mxEv = result.context.getEvent(); const roomId = mxEv.getRoomId(); + const room = cli.getRoom(roomId); if (!EventTile.haveTileForEvent(mxEv)) { // XXX: can this ever happen? It will make the result count @@ -1177,7 +1182,6 @@ module.exports = React.createClass({ if (this.state.searchScope === 'All') { if (roomId != lastRoomId) { - const room = cli.getRoom(roomId); // XXX: if we've left the room, we might not know about // it. We should tell the js sdk to go and find out about @@ -1194,11 +1198,17 @@ module.exports = React.createClass({ const resultLink = "#/room/"+roomId+"/"+mxEv.getId(); + let permalinkCreator = permalinkCreators[roomId]; + if (!permalinkCreator) { + permalinkCreator = permalinkCreators[roomId] = new RoomPermalinkCreator(room); + permalinkCreator.stop(); // We're not interested in monitoring for updates here. + } + ret.push(); } return ret; From e4a9d4f5c889699525e27d8297601de1625cf301 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Tue, 9 Apr 2019 12:01:09 -0600 Subject: [PATCH 02/12] Cache permalink creators out of the component's state --- src/components/structures/RoomView.js | 42 +++++++++++++-------------- src/matrix-to.js | 7 +++++ 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index a60f19b35e..3f9d93c9b1 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -272,6 +272,20 @@ module.exports = React.createClass({ return this.state.room ? this.state.room.roomId : this.state.roomId; }, + _getPermalinkCreatorForRoom: function(room) { + if (!this._permalinkCreators) this._permalinkCreators = {}; + if (this._permalinkCreators[room.roomId]) return this._permalinkCreators[room.roomId]; + + return this._permalinkCreators[room.roomId] = new RoomPermalinkCreator(room); + }, + + _stopAllPermalinkCreators: function() { + if (!this._permalinkCreators) return; + for (const roomId of Object.keys(this._permalinkCreators)) { + this._permalinkCreators[roomId].stop(); + } + }, + _onWidgetEchoStoreUpdate: function() { this.setState({ showApps: this._shouldShowApps(this.state.room), @@ -436,9 +450,7 @@ module.exports = React.createClass({ } // stop tracking room changes to format permalinks - if (this.state.permalinkCreator) { - this.state.permalinkCreator.stop(); - } + this._stopAllPermalinkCreators(); if (this.refs.roomView) { // disconnect the D&D event listeners from the room view. This @@ -650,11 +662,9 @@ module.exports = React.createClass({ this._loadMembersIfJoined(room); this._calculateRecommendedVersion(room); this._updateE2EStatus(room); - if (!this.state.permalinkCreator) { - const permalinkCreator = new RoomPermalinkCreator(room); - permalinkCreator.start(); - this.setState({permalinkCreator}); - } + + let creator = this._getPermalinkCreatorForRoom(room); + if (!creator.isStarted()) creator.start(); }, _calculateRecommendedVersion: async function(room) { @@ -1161,10 +1171,6 @@ module.exports = React.createClass({ } }; - // We cache the permalink creators to avoid creating a ton of them in popular searches - const permalinkCreators = {}; // [roomId] => creator - permalinkCreators[this.state.room.roomId] = this.state.permalinkCreator; - let lastRoomId; for (let i = this.state.searchResults.results.length - 1; i >= 0; i--) { @@ -1198,17 +1204,11 @@ module.exports = React.createClass({ const resultLink = "#/room/"+roomId+"/"+mxEv.getId(); - let permalinkCreator = permalinkCreators[roomId]; - if (!permalinkCreator) { - permalinkCreator = permalinkCreators[roomId] = new RoomPermalinkCreator(room); - permalinkCreator.stop(); // We're not interested in monitoring for updates here. - } - ret.push(); } return ret; @@ -1733,7 +1733,7 @@ module.exports = React.createClass({ disabled={this.props.disabled} showApps={this.state.showApps} e2eStatus={this.state.e2eStatus} - permalinkCreator={this.state.permalinkCreator} + permalinkCreator={this._getPermalinkCreatorForRoom(this.state.room)} />; } @@ -1835,7 +1835,7 @@ module.exports = React.createClass({ showUrlPreview = {this.state.showUrlPreview} className="mx_RoomView_messagePanel" membersLoaded={this.state.membersLoaded} - permalinkCreator={this.state.permalinkCreator} + permalinkCreator={this._getPermalinkCreatorForRoom(this.state.room)} resizeNotifier={this.props.resizeNotifier} />); diff --git a/src/matrix-to.js b/src/matrix-to.js index bb7ddfbd94..a198bb422e 100644 --- a/src/matrix-to.js +++ b/src/matrix-to.js @@ -77,6 +77,7 @@ export class RoomPermalinkCreator { this._bannedHostsRegexps = null; this._allowedHostsRegexps = null; this._serverCandidates = null; + this._started = false; this.onMembership = this.onMembership.bind(this); this.onRoomState = this.onRoomState.bind(this); @@ -101,11 +102,17 @@ export class RoomPermalinkCreator { this.load(); this._room.on("RoomMember.membership", this.onMembership); this._room.on("RoomState.events", this.onRoomState); + this._started = true; } stop() { this._room.removeListener("RoomMember.membership", this.onMembership); this._room.removeListener("RoomState.events", this.onRoomState); + this._started = false; + } + + isStarted() { + return this._started; } forEvent(eventId) { From ccf292f05368f63dc4f0f5fd01135224d38f5b97 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 11 Apr 2019 10:59:00 -0600 Subject: [PATCH 03/12] Load permalink creators to get proper state of the room --- src/components/structures/RoomView.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 3f9d93c9b1..1bcbec4845 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -276,7 +276,9 @@ module.exports = React.createClass({ if (!this._permalinkCreators) this._permalinkCreators = {}; if (this._permalinkCreators[room.roomId]) return this._permalinkCreators[room.roomId]; - return this._permalinkCreators[room.roomId] = new RoomPermalinkCreator(room); + this._permalinkCreators[room.roomId] = new RoomPermalinkCreator(room); + this._permalinkCreators[room.roomId].load(); + return this._permalinkCreators[room.roomId]; }, _stopAllPermalinkCreators: function() { From 11bd82ee4cc78e6d33d415c3b93b5d38140199a6 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 12 Apr 2019 15:05:07 +0100 Subject: [PATCH 04/12] Ensure tags appear bold for all browsers In Firefox, the default style is such that it doesn't appear bold with our current selection of specific font weights. This specifically sets a working font weight. --- res/css/_common.scss | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/res/css/_common.scss b/res/css/_common.scss index 4a9c2945f5..11894e414a 100644 --- a/res/css/_common.scss +++ b/res/css/_common.scss @@ -36,6 +36,12 @@ body { color: $warning-color; } +b { + // On Firefox, the default weight for `` is `bolder` which results in no bold + // effect since we only have specific weights of our fonts available. + font-weight: bold; +} + h2 { color: $primary-fg-color; font-weight: 400; From 5ee9de04c37aeac7d5d67842a7eea0f0e2ef2236 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 12 Apr 2019 16:23:54 +0100 Subject: [PATCH 05/12] Fix key backup status when missing device We might not have the device in `sig.device`, so we have to check for it's existence first. This fixes the "Unable to load key backup status" message that is incorrectly triggering. Fixes https://github.com/vector-im/riot-web/issues/9442 --- src/components/views/settings/KeyBackupPanel.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/views/settings/KeyBackupPanel.js b/src/components/views/settings/KeyBackupPanel.js index 7667e11d46..42ebf1c89d 100644 --- a/src/components/views/settings/KeyBackupPanel.js +++ b/src/components/views/settings/KeyBackupPanel.js @@ -221,7 +221,10 @@ export default class KeyBackupPanel extends React.PureComponent { {sub} ; const device = sub => {deviceName}; - const fromThisDevice = sig.device.getFingerprint() === MatrixClientPeg.get().getDeviceEd25519Key(); + const fromThisDevice = ( + sig.device && + sig.device.getFingerprint() === MatrixClientPeg.get().getDeviceEd25519Key() + ); let sigStatus; if (!sig.device) { sigStatus = _t( From 0479901daa288bd87a645d8827b6530db92b2190 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 12 Apr 2019 10:38:39 -0600 Subject: [PATCH 06/12] Load data for permalink creators once --- src/components/structures/RoomView.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 1bcbec4845..acece9271c 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -277,7 +277,13 @@ module.exports = React.createClass({ if (this._permalinkCreators[room.roomId]) return this._permalinkCreators[room.roomId]; this._permalinkCreators[room.roomId] = new RoomPermalinkCreator(room); - this._permalinkCreators[room.roomId].load(); + if (this.state.room && room.roomId === this.state.room.roomId) { + // We want to watch for changes in the creator for the primary room in the view, but + // don't need to do so for search results. + this._permalinkCreators[room.roomId].start(); + } else { + this._permalinkCreators[room.roomId].load(); + } return this._permalinkCreators[room.roomId]; }, @@ -664,9 +670,6 @@ module.exports = React.createClass({ this._loadMembersIfJoined(room); this._calculateRecommendedVersion(room); this._updateE2EStatus(room); - - let creator = this._getPermalinkCreatorForRoom(room); - if (!creator.isStarted()) creator.start(); }, _calculateRecommendedVersion: async function(room) { From 9478ccc6836e8988a7f16a346ff0c78e49d70421 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Sun, 14 Apr 2019 20:46:32 -0600 Subject: [PATCH 07/12] Add missing newline --- src/components/structures/GenericErrorPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/GenericErrorPage.js b/src/components/structures/GenericErrorPage.js index 1962b471f3..f28f66064c 100644 --- a/src/components/structures/GenericErrorPage.js +++ b/src/components/structures/GenericErrorPage.js @@ -35,4 +35,4 @@ export default class GenericErrorPage extends React.PureComponent { ; } -} \ No newline at end of file +} From e256dd6b057e737e987a83e6092cc92a763d9ecb Mon Sep 17 00:00:00 2001 From: Thomas Karner Date: Mon, 15 Apr 2019 09:13:18 +0200 Subject: [PATCH 08/12] use SdkConfig brand name instead of static "Riot" Signed-off-by: Thomas Karner --- src/components/structures/MatrixChat.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index fe0deb0d49..f6ca6fbdd9 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -1797,7 +1797,7 @@ export default React.createClass({ }, _setPageSubtitle: function(subtitle='') { - document.title = `Riot ${subtitle}`; + document.title = `${SdkConfig.get().brand || 'Riot'} ${subtitle}`; }, updateStatusIndicator: function(state, prevState) { From 9a59b0d390a5bbcd995e12791dcbf7a11c4a05aa Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 12 Apr 2019 12:38:35 +0100 Subject: [PATCH 09/12] Clarify that use backup means restore "Use key backup" feels like it's telling me I haven't set it up at all. This changes to "Restore ..." which seems more reassuring. Fixes https://github.com/vector-im/riot-web/issues/9438 --- src/components/views/settings/KeyBackupPanel.js | 3 +-- src/i18n/strings/en_EN.json | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/views/settings/KeyBackupPanel.js b/src/components/views/settings/KeyBackupPanel.js index 42ebf1c89d..5575f08be5 100644 --- a/src/components/views/settings/KeyBackupPanel.js +++ b/src/components/views/settings/KeyBackupPanel.js @@ -176,7 +176,7 @@ export default class KeyBackupPanel extends React.PureComponent { } else if (this.state.backupInfo) { const EmojiText = sdk.getComponent('elements.EmojiText'); let clientBackupStatus; - let restoreButtonCaption = _t("Restore from Backup"); + const restoreButtonCaption = _t("Restore from Backup"); if (MatrixClientPeg.get().getKeyBackupEnabled()) { clientBackupStatus =
@@ -192,7 +192,6 @@ export default class KeyBackupPanel extends React.PureComponent { )}

{_t("Back up your keys before signing out to avoid losing them.")}

; - restoreButtonCaption = _t("Use key backup"); } let uploadStatus; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index e4d1d3ea80..78733dae7c 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -469,7 +469,6 @@ "This device is backing up your keys. ": "This device is backing up your keys. ", "This device is not backing up your keys.": "This device is not backing up your keys.", "Back up your keys before signing out to avoid losing them.": "Back up your keys before signing out to avoid losing them.", - "Use key backup": "Use key backup", "Backing up %(sessionsRemaining)s keys...": "Backing up %(sessionsRemaining)s keys...", "All keys backed up": "All keys backed up", "Backup has a signature from unknown device with ID %(deviceId)s.": "Backup has a signature from unknown device with ID %(deviceId)s.", From bded275f6a2ed62251bc4093ff5032cf6fa4842f Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Fri, 12 Apr 2019 17:40:22 +0100 Subject: [PATCH 10/12] Clarify messaging when key backup exists but is unused This makes the key backup panel much more explicit about the case where an existing backup does exist, but this device just isn't using it. You can join the device to the backup and restore from it by going through the restore workflow. Fixes https://github.com/vector-im/riot-web/issues/9446 --- src/components/views/settings/KeyBackupPanel.js | 10 ++++++++-- src/i18n/strings/en_EN.json | 5 +++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/views/settings/KeyBackupPanel.js b/src/components/views/settings/KeyBackupPanel.js index 5575f08be5..e85491bf60 100644 --- a/src/components/views/settings/KeyBackupPanel.js +++ b/src/components/views/settings/KeyBackupPanel.js @@ -187,10 +187,16 @@ export default class KeyBackupPanel extends React.PureComponent { clientBackupStatus =

{encryptedMessageAreEncrypted}

{_t( - "This device is not backing up your keys.", {}, + "This device is not backing up your keys, " + + "but there is an existing backup you can restore from " + + "and add to going forward.", {}, {b: sub => {sub}}, )}

-

{_t("Back up your keys before signing out to avoid losing them.")}

+

{_t( + "Enable key backup on this device via the restore " + + "process before signing out to avoid losing any keys " + + "that may only be on this device.", + )}

; } diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 78733dae7c..5d390f815a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -467,8 +467,8 @@ "Unable to load key backup status": "Unable to load key backup status", "Restore from Backup": "Restore from Backup", "This device is backing up your keys. ": "This device is backing up your keys. ", - "This device is not backing up your keys.": "This device is not backing up your keys.", - "Back up your keys before signing out to avoid losing them.": "Back up your keys before signing out to avoid losing them.", + "This device is not backing up your keys, but there is an existing backup you can restore from and add to going forward.": "This device is not backing up your keys, but there is an existing backup you can restore from and add to going forward.", + "Enable key backup on this device via the restore process before signing out to avoid losing any keys that may only be on this device.": "Enable key backup on this device via the restore process before signing out to avoid losing any keys that may only be on this device.", "Backing up %(sessionsRemaining)s keys...": "Backing up %(sessionsRemaining)s keys...", "All keys backed up": "All keys backed up", "Backup has a signature from unknown device with ID %(deviceId)s.": "Backup has a signature from unknown device with ID %(deviceId)s.", @@ -484,6 +484,7 @@ "Backup version: ": "Backup version: ", "Algorithm: ": "Algorithm: ", "Your keys are not being backed up from this device.": "Your keys are not being backed up from this device.", + "Back up your keys before signing out to avoid losing them.": "Back up your keys before signing out to avoid losing them.", "Start using Key Backup": "Start using Key Backup", "Error saving email notification preferences": "Error saving email notification preferences", "An error occurred whilst saving your email notification preferences.": "An error occurred whilst saving your email notification preferences.", From 2054d5378274000572d7a932e844d70f1ead15ec Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 15 Apr 2019 15:10:19 +0100 Subject: [PATCH 11/12] Tweaked wording after discussing with @lampholder --- src/components/views/settings/KeyBackupPanel.js | 10 +++++----- src/i18n/strings/en_EN.json | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/views/settings/KeyBackupPanel.js b/src/components/views/settings/KeyBackupPanel.js index e85491bf60..2ba05a0e6b 100644 --- a/src/components/views/settings/KeyBackupPanel.js +++ b/src/components/views/settings/KeyBackupPanel.js @@ -176,7 +176,7 @@ export default class KeyBackupPanel extends React.PureComponent { } else if (this.state.backupInfo) { const EmojiText = sdk.getComponent('elements.EmojiText'); let clientBackupStatus; - const restoreButtonCaption = _t("Restore from Backup"); + let restoreButtonCaption = _t("Restore from Backup"); if (MatrixClientPeg.get().getKeyBackupEnabled()) { clientBackupStatus =
@@ -188,16 +188,16 @@ export default class KeyBackupPanel extends React.PureComponent {

{encryptedMessageAreEncrypted}

{_t( "This device is not backing up your keys, " + - "but there is an existing backup you can restore from " + + "but you do have an existing backup you can restore from " + "and add to going forward.", {}, {b: sub => {sub}}, )}

{_t( - "Enable key backup on this device via the restore " + - "process before signing out to avoid losing any keys " + - "that may only be on this device.", + "Connect this device to key backup before signing out to avoid " + + "losing any keys that may only be on this device.", )}

; + restoreButtonCaption = _t("Connect this device to Key Backup"); } let uploadStatus; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 5d390f815a..d0f265e430 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -467,8 +467,9 @@ "Unable to load key backup status": "Unable to load key backup status", "Restore from Backup": "Restore from Backup", "This device is backing up your keys. ": "This device is backing up your keys. ", - "This device is not backing up your keys, but there is an existing backup you can restore from and add to going forward.": "This device is not backing up your keys, but there is an existing backup you can restore from and add to going forward.", - "Enable key backup on this device via the restore process before signing out to avoid losing any keys that may only be on this device.": "Enable key backup on this device via the restore process before signing out to avoid losing any keys that may only be on this device.", + "This device is not backing up your keys, but you do have an existing backup you can restore from and add to going forward.": "This device is not backing up your keys, but you do have an existing backup you can restore from and add to going forward.", + "Connect this device to key backup before signing out to avoid losing any keys that may only be on this device.": "Connect this device to key backup before signing out to avoid losing any keys that may only be on this device.", + "Connect this device to Key Backup": "Connect this device to Key Backup", "Backing up %(sessionsRemaining)s keys...": "Backing up %(sessionsRemaining)s keys...", "All keys backed up": "All keys backed up", "Backup has a signature from unknown device with ID %(deviceId)s.": "Backup has a signature from unknown device with ID %(deviceId)s.", From a11cf88e07100974997363e5218cf6e7eca4d942 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 15 Apr 2019 14:46:00 -0600 Subject: [PATCH 12/12] Add a function to append/overwrite objects in the config on the fly Intended to be used to overwrite settings which may be calculated rather than provided. --- src/SdkConfig.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/SdkConfig.js b/src/SdkConfig.js index 78dd050a1e..eb18dad453 100644 --- a/src/SdkConfig.js +++ b/src/SdkConfig.js @@ -41,6 +41,12 @@ class SdkConfig { static unset() { global.mxReactSdkConfig = undefined; } + + static add(cfg) { + const liveConfig = SdkConfig.get(); + const newConfig = Object.assign({}, liveConfig, cfg); + SdkConfig.put(newConfig); + } } module.exports = SdkConfig;