From 2ac951bc6553bc6921f14ad92efc2d1b0a86b85d Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 4 Oct 2018 20:46:09 +0100 Subject: [PATCH 1/7] Revert "Use createObjectURL instead of readAsDataURL for videos" --- src/ContentMessages.js | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/ContentMessages.js b/src/ContentMessages.js index a0bf75bccf..fd21977108 100644 --- a/src/ContentMessages.js +++ b/src/ContentMessages.js @@ -153,17 +153,24 @@ function loadVideoElement(videoFile) { // Load the file into an html element const video = document.createElement("video"); - // Wait until we have enough data to thumbnail the first frame. - video.onloadeddata = function() { - URL.revokeObjectURL(video.src); - deferred.resolve(video); + const reader = new FileReader(); + reader.onload = function(e) { + video.src = e.target.result; + + // Once ready, returns its size + // Wait until we have enough data to thumbnail the first frame. + video.onloadeddata = function() { + deferred.resolve(video); + }; + video.onerror = function(e) { + deferred.reject(e); + }; }; - video.onerror = function(e) { + reader.onerror = function(e) { deferred.reject(e); }; - - // We don't use readAsDataURL because massive files and b64 don't mix. - video.src = URL.createObjectURL(videoFile); + reader.readAsDataURL(videoFile); + return deferred.promise; } From f4ae3855d045a27e114dd45c3786904738a5e475 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 3 Oct 2018 18:28:41 +0100 Subject: [PATCH 2/7] Remove old migration code ...as instructed! --- src/utils/createMatrixClient.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/utils/createMatrixClient.js b/src/utils/createMatrixClient.js index b83e254fad..54312695b6 100644 --- a/src/utils/createMatrixClient.js +++ b/src/utils/createMatrixClient.js @@ -48,9 +48,6 @@ export default function createMatrixClient(opts) { } if (indexedDB && localStorage) { - // FIXME: bodge to remove old database. Remove this after a few weeks. - indexedDB.deleteDatabase("matrix-js-sdk:default"); - storeOpts.store = new Matrix.IndexedDBStore({ indexedDB: indexedDB, dbName: "riot-web-sync", From fd64369a5f34ad880be3f74539239489170641ff Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 2 Oct 2018 19:23:43 +0100 Subject: [PATCH 3/7] Fix error logging --- src/MatrixClientPeg.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index f5872812de..9865044717 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -109,7 +109,7 @@ class MatrixClientPeg { await promise; } catch (err) { // log any errors when starting up the database (if one exists) - console.error(`Error starting matrixclient store: ${err}`); + console.error('Error starting matrixclient store', err); } // regardless of errors, start the client. If we did error out, we'll From 573029af74347a5b0953850863c1d7006526b87a Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 4 Oct 2018 13:40:56 +0100 Subject: [PATCH 4/7] Fall back to another store if indexeddb start fails If we can't start indexeddb, fall back to a different store. Previously we just ignored the exception and ploughed on anyway, on the assumption that startup() was just for the indexeddb store to load data anyway, and if that failed it would just do an initial /sync instead (and also we'd keep trying to save the sync back which would fail...). Then, in the previous release we started pulling the settings out of the store on startup, making the assumpton that the store actually worked, so the read obviously failed and the app failed to start up. This makes Riot work in Tor browser / firefox in daft mode again. --- src/MatrixClientPeg.js | 41 ++++++++++++++++++++++----------- src/utils/createMatrixClient.js | 9 ++++++-- 2 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 9865044717..f02c751a2c 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -18,6 +18,8 @@ limitations under the License. 'use strict'; +import Matrix from 'matrix-js-sdk'; + import utils from 'matrix-js-sdk/lib/utils'; import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline'; import EventTimelineSet from 'matrix-js-sdk/lib/models/event-timeline-set'; @@ -51,6 +53,9 @@ class MatrixClientPeg { this.opts = { initialSyncLimit: 20, }; + // the credentials used to init the current client object. + // used if we tear it down & recreate it with a different store + this._currentClientCreds = null; } /** @@ -79,10 +84,30 @@ class MatrixClientPeg { * Home Server / Identity Server URLs and active credentials */ replaceUsingCreds(creds: MatrixClientCreds) { + this._currentClientCreds = creds; this._createClient(creds); } async start() { + for (const dbType of ['indexeddb', 'memory']) { + try { + const promise = this.matrixClient.store.startup(); + console.log("MatrixClientPeg: waiting for MatrixClient store to initialise"); + await promise; + break; + } catch (err) { + if (dbType === 'indexeddb') { + console.error('Error starting matrixclient store - falling back to memory store', err); + this.matrixClient.store = new Matrix.MatrixInMemoryStore({ + localStorage: global.localStorage, + }); + } else { + console.error('Failed to start memory store!', err); + throw err; + } + } + } + // try to initialise e2e on the new client try { // check that we have a version of the js-sdk which includes initCrypto @@ -103,18 +128,6 @@ class MatrixClientPeg { opts.lazyLoadMembers = true; } - try { - const promise = this.matrixClient.store.startup(); - console.log(`MatrixClientPeg: waiting for MatrixClient store to initialise`); - await promise; - } catch (err) { - // log any errors when starting up the database (if one exists) - console.error('Error starting matrixclient store', err); - } - - // regardless of errors, start the client. If we did error out, we'll - // just end up doing a full initial /sync. - // Connect the matrix client to the dispatcher MatrixActionCreators.start(this.matrixClient); @@ -147,7 +160,7 @@ class MatrixClientPeg { return matches[1]; } - _createClient(creds: MatrixClientCreds) { + _createClient(creds: MatrixClientCreds, useIndexedDb) { const opts = { baseUrl: creds.homeserverUrl, idBaseUrl: creds.identityServerUrl, @@ -158,7 +171,7 @@ class MatrixClientPeg { forceTURN: SettingsStore.getValue('webRtcForceTURN', false), }; - this.matrixClient = createMatrixClient(opts, this.indexedDbWorkerScript); + this.matrixClient = createMatrixClient(opts, useIndexedDb); // we're going to add eventlisteners for each matrix event tile, so the // potential number of event listeners is quite high. diff --git a/src/utils/createMatrixClient.js b/src/utils/createMatrixClient.js index 54312695b6..2acd1fae28 100644 --- a/src/utils/createMatrixClient.js +++ b/src/utils/createMatrixClient.js @@ -32,13 +32,18 @@ try { * @param {Object} opts options to pass to Matrix.createClient. This will be * extended with `sessionStore` and `store` members. * + * @param {bool} useIndexedDb True to attempt to use indexeddb, or false to force + * use of the memory store. Default: true. + * * @property {string} indexedDbWorkerScript Optional URL for a web worker script * for IndexedDB store operations. By default, indexeddb ops are done on * the main thread. * * @returns {MatrixClient} the newly-created MatrixClient */ -export default function createMatrixClient(opts) { +export default function createMatrixClient(opts, useIndexedDb) { + if (useIndexedDb === undefined) useIndexedDb = true; + const storeOpts = { useAuthorizationHeader: true, }; @@ -47,7 +52,7 @@ export default function createMatrixClient(opts) { storeOpts.sessionStore = new Matrix.WebStorageSessionStore(localStorage); } - if (indexedDB && localStorage) { + if (indexedDB && localStorage && useIndexedDb) { storeOpts.store = new Matrix.IndexedDBStore({ indexedDB: indexedDB, dbName: "riot-web-sync", From cc962c975bcf1cdb0982ca75d52bd05439de544a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 8 Oct 2018 15:28:00 +0200 Subject: [PATCH 5/7] show warning when LL is disabled but was enabled before --- src/Lifecycle.js | 13 +++++++ .../dialogs/LazyLoadingDisabledDialog.js | 39 +++++++++++++++++++ src/i18n/strings/en_EN.json | 6 ++- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 src/components/views/dialogs/LazyLoadingDisabledDialog.js diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 434975a5bc..b3178710a1 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -250,6 +250,19 @@ function _handleLoadSessionFailure(e) { onFinished: resolve, }); }); + } else { + // show warning about simultaneous use + // between LL/non-LL version on same host. + // as disabling LL when previously enabled + // is a strong indicator of this (/develop & /app) + const LazyLoadingDisabledDialog = + sdk.getComponent("views.dialogs.LazyLoadingDisabledDialog"); + return new Promise((resolve) => { + Modal.createDialog(LazyLoadingDisabledDialog, { + onFinished: resolve, + host: window.location.host, + }); + }); } }).then(() => { return MatrixClientPeg.get().store.deleteAllData(); diff --git a/src/components/views/dialogs/LazyLoadingDisabledDialog.js b/src/components/views/dialogs/LazyLoadingDisabledDialog.js new file mode 100644 index 0000000000..d128d8dedd --- /dev/null +++ b/src/components/views/dialogs/LazyLoadingDisabledDialog.js @@ -0,0 +1,39 @@ +/* +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. +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 React from 'react'; +import QuestionDialog from './QuestionDialog'; +import { _t } from '../../../languageHandler'; + +export default (props) => { + const description1 = + _t("You've previously used Riot on %(host)s with lazy loading of members enabled. " + + "In this version lazy loading is disabled. " + + "As the local cache is not compatible between these two settings, " + + "Riot needs to resync your account.", + {host: props.host}); + const description2 = _t("If the other version of Riot is still open in another tab, " + + "please close it as using Riot on the same host with both " + + "lazy loading enabled and disabled simultaneously will cause issues."); + + return (

{description1}

{description2}

} + button={_t("Clear cache and resync")} + onFinished={props.onFinished} + />); +}; diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 94dc3cb393..261fc7b012 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1259,5 +1259,9 @@ "Import": "Import", "Failed to set direct chat tag": "Failed to set direct chat tag", "Failed to remove tag %(tagName)s from room": "Failed to remove tag %(tagName)s from room", - "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room" + "Failed to add tag %(tagName)s to room": "Failed to add tag %(tagName)s to room", + "You've previously used Riot on %(host)s with lazy loading of members enabled. In this version lazy loading is disabled. As the local cache is not compatible between these two settings, Riot needs to resync your account.": "You've previously used Riot on %(host)s with lazy loading of members enabled. In this version lazy loading is disabled. As the local cache is not compatible between these two settings, Riot needs to resync your account.", + "If the other version of Riot is still open in another tab, please close it as using Riot on the same host with both lazy loading enabled and disabled simultaneously will cause issues.": "If the other version of Riot is still open in another tab, please close it as using Riot on the same host with both lazy loading enabled and disabled simultaneously will cause issues.", + "Incompatible local cache": "Incompatible local cache", + "Clear cache and resync": "Clear cache and resync" } From cd83a6b5d3ab58b0961d0a9d886407b6e3909bff Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 8 Oct 2018 17:07:54 +0200 Subject: [PATCH 6/7] Prepare changelog for v0.13.6 --- CHANGELOG.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d007be0f4b..a52034d305 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +Changes in [0.13.6](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v0.13.6) (2018-10-08) +===================================================================================================== +[Full Changelog](https://github.com/matrix-org/matrix-react-sdk/compare/v0.13.5...v0.13.6) + + * Fix resuming session in Firefox private mode/Tor browser being broken + [\#2195](https://github.com/matrix-org/matrix-react-sdk/pull/2195) + * Show warning about using lazy-loading/non-lazy-loading versions simultaneously (/app & /develop) + [\#2201](https://github.com/matrix-org/matrix-react-sdk/pull/2201) + Changes in [0.13.5](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v0.13.5) (2018-10-01) ===================================================================================================== [Full Changelog](https://github.com/matrix-org/matrix-react-sdk/compare/v0.13.5-rc.1...v0.13.5) From ae288bb9c9861c8c32845d72bcfa1c0e2a218b94 Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Mon, 8 Oct 2018 17:07:54 +0200 Subject: [PATCH 7/7] v0.13.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d8f44c0fb0..5957493189 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "0.13.5", + "version": "0.13.6", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": {