From 300cd962e572bb0ab3314295721f4d2e5d2d16c7 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 2 Feb 2017 14:27:27 +0000 Subject: [PATCH 01/12] Add glue code to make react-sdk use indexedDB --- src/MatrixClientPeg.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 9c0daf4726..36521204c5 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -16,6 +16,7 @@ limitations under the License. 'use strict'; +import q from "q"; import Matrix from 'matrix-js-sdk'; import utils from 'matrix-js-sdk/lib/utils'; import EventTimeline from 'matrix-js-sdk/lib/models/event-timeline'; @@ -71,7 +72,17 @@ class MatrixClientPeg { const opts = utils.deepCopy(this.opts); // the react sdk doesn't work without this, so don't allow opts.pendingEventOrdering = "detached"; - this.get().startClient(opts); + + let promise = q(); + if (this.matrixClient.store instanceof Matrix.IndexedDBStore) { + // load from storage before starting up. + console.log("Loading history from IndexedDB."); + promise = this.matrixClient.store.startup(); + } + + promise.finally(() => { + this.get().startClient(opts); + }); } getCredentials(): MatrixClientCreds { @@ -111,6 +122,13 @@ class MatrixClientPeg { if (localStorage) { opts.sessionStore = new Matrix.WebStorageSessionStore(localStorage); } + if (window.indexedDB && localStorage) { + opts.store = new Matrix.IndexedDBStore( + new Matrix.IndexedDBStoreBackend(window.indexedDB), { + localStorage: localStorage, + } + ); + } this.matrixClient = Matrix.createClient(opts); From 407bcf1bb932ca53a753ae9d88a21bd44f020710 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 10 Feb 2017 14:22:54 +0000 Subject: [PATCH 02/12] Delete database on logout. DI a SyncAccumulator. Log uncaught errors --- src/Lifecycle.js | 11 +++++++++++ src/MatrixClientPeg.js | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 493bbf12aa..739e8e3832 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -329,10 +329,21 @@ export function startMatrixClient() { */ export function onLoggedOut() { _clearLocalStorage(); + _clearIndexedDB(); stopMatrixClient(); dis.dispatch({action: 'on_logged_out'}); } +function _clearIndexedDB() { + // remove indexeddb instances + if (!window.indexedDB) { + return; + } + console.log("Clearing indexeddb"); + window.indexedDB.deleteDatabase("matrix-js-sdk"); + window.indexedDB.deleteDatabase("logs"); +} + function _clearLocalStorage() { if (!window.localStorage) { return; diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 36521204c5..42834618ae 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -79,6 +79,7 @@ class MatrixClientPeg { console.log("Loading history from IndexedDB."); promise = this.matrixClient.store.startup(); } + promise.catch((err) => { console.error(err); }); promise.finally(() => { this.get().startClient(opts); @@ -124,7 +125,8 @@ class MatrixClientPeg { } if (window.indexedDB && localStorage) { opts.store = new Matrix.IndexedDBStore( - new Matrix.IndexedDBStoreBackend(window.indexedDB), { + new Matrix.IndexedDBStoreBackend(window.indexedDB), + new Matrix.SyncAccumulator(), { localStorage: localStorage, } ); From c46f28213995ef6a10f0c3715bef7b5b43ecc595 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 10 Feb 2017 16:19:39 +0000 Subject: [PATCH 03/12] Comments --- src/MatrixClientPeg.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 42834618ae..0267b36464 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -79,8 +79,11 @@ class MatrixClientPeg { console.log("Loading history from IndexedDB."); promise = this.matrixClient.store.startup(); } + // log any errors when starting up the database promise.catch((err) => { console.error(err); }); + // regardless of errors, start the client. If we did error out, we'll + // just end up doing a full initial /sync. promise.finally(() => { this.get().startClient(opts); }); From 87516fb950159589ea725a9ae4ab6ad3ae0848d5 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 14 Feb 2017 17:54:57 +0000 Subject: [PATCH 04/12] Add a button to un-ban users in RoomSettings https://github.com/vector-im/riot-web/issues/3091 --- src/components/views/rooms/RoomSettings.js | 57 ++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 4d1285678b..8b156f2ccc 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -35,6 +35,47 @@ function parseIntWithDefault(val, def) { return isNaN(res) ? def : res; } +const BannedUser = React.createClass({ + propTypes: { + member: React.PropTypes.string.isRequired, + }, + + _onUnbanClick: function() { + const ConfirmUserActionDialog = sdk.getComponent("dialogs.ConfirmUserActionDialog"); + Modal.createDialog(ConfirmUserActionDialog, { + member: this.props.member, + action: 'Unban', + danger: false, + onFinished: (proceed) => { + if (!proceed) return; + + MatrixClientPeg.get().unban( + this.props.member.roomId, this.props.member.userId, + ).catch((err) => { + const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); + Modal.createDialog(ErrorDialog, { + title: "Failed to unban", + description: err.message, + }); + }).done(); + }, + }); + }, + + render: function() { + return ( +
  • + + Unban + + {this.props.member.userId} +
  • + ); + } +}); + module.exports = React.createClass({ displayName: 'RoomSettings', @@ -74,6 +115,9 @@ module.exports = React.createClass({ componentWillMount: function() { ScalarMessaging.startListening(); + + MatrixClientPeg.get().on("RoomMember.membership", this._onRoomMemberMembership); + MatrixClientPeg.get().getRoomDirectoryVisibility( this.props.room.roomId ).done((result) => { @@ -102,6 +146,8 @@ module.exports = React.createClass({ componentWillUnmount: function() { ScalarMessaging.stopListening(); + MatrixClientPeg.get().removeListener("RoomMember.membership", this._onRoomMemberMembership); + dis.dispatch({ action: 'ui_opacity', sideOpacity: 1.0, @@ -501,6 +547,11 @@ module.exports = React.createClass({ }); }, + _onRoomMemberMembership: function() { + // Update, since our banned user list may have changed + this.forceUpdate(); + }, + _renderEncryptionSection: function() { var cli = MatrixClientPeg.get(); var roomState = this.props.room.currentState; @@ -611,11 +662,9 @@ module.exports = React.createClass({

    Banned users

      - {banned.map(function(member, i) { + {banned.map(function(member) { return ( -
    • - {member.userId} -
    • + ); })}
    From 431e7a875db2d35f04162c616ee086201f360aba Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 14 Feb 2017 18:10:40 +0000 Subject: [PATCH 05/12] Copyright --- src/components/views/rooms/RoomSettings.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 8b156f2ccc..7a9cb2224c 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -1,5 +1,6 @@ /* Copyright 2015, 2016 OpenMarket Ltd +Copyright 2017 Vector Creations Ltd Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. From c082827fc7e3e11e4790c0306933c751c7a09c65 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 15 Feb 2017 17:12:51 +0000 Subject: [PATCH 06/12] Fix docs & use WithMatrixClient --- src/components/views/rooms/RoomSettings.js | 56 ++++++++++++---------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 7a9cb2224c..783d343890 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -17,7 +17,6 @@ limitations under the License. import q from 'q'; import React from 'react'; -import MatrixClientPeg from '../../../MatrixClientPeg'; import SdkConfig from '../../../SdkConfig'; import sdk from '../../../index'; import Modal from '../../../Modal'; @@ -27,6 +26,7 @@ import ScalarAuthClient from '../../../ScalarAuthClient'; import ScalarMessaging from '../../../ScalarMessaging'; import UserSettingsStore from '../../../UserSettingsStore'; import AccessibleButton from '../elements/AccessibleButton'; +import WithMatrixClient from '../../../wrappers/WithMatrixClient'; // parse a string as an integer; if the input is undefined, or cannot be parsed @@ -36,9 +36,12 @@ function parseIntWithDefault(val, def) { return isNaN(res) ? def : res; } -const BannedUser = React.createClass({ +const BannedUser = WithMatrixClient(React.createClass({ propTypes: { - member: React.PropTypes.string.isRequired, + /* MatrixClient instance */ + matrixClient: React.PropTypes.object.isRequired, + + member: React.PropTypes.object.isRequired, // js-sdk member object }, _onUnbanClick: function() { @@ -50,7 +53,7 @@ const BannedUser = React.createClass({ onFinished: (proceed) => { if (!proceed) return; - MatrixClientPeg.get().unban( + this.props.matrixClient.unban( this.props.member.roomId, this.props.member.userId, ).catch((err) => { const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); @@ -75,12 +78,15 @@ const BannedUser = React.createClass({ ); } -}); +})); -module.exports = React.createClass({ +module.exports = WithMatrixClient(React.createClass({ displayName: 'RoomSettings', propTypes: { + /* MatrixClient instance */ + matrixClient: React.PropTypes.object.isRequired, + room: React.PropTypes.object.isRequired, onSaveClick: React.PropTypes.func, onCancelClick: React.PropTypes.func, @@ -117,9 +123,9 @@ module.exports = React.createClass({ componentWillMount: function() { ScalarMessaging.startListening(); - MatrixClientPeg.get().on("RoomMember.membership", this._onRoomMemberMembership); + this.props.matrixClient.on("RoomMember.membership", this._onRoomMemberMembership); - MatrixClientPeg.get().getRoomDirectoryVisibility( + this.props.matrixClient.getRoomDirectoryVisibility( this.props.room.roomId ).done((result) => { this.setState({ isRoomPublished: result.visibility === "public" }); @@ -147,7 +153,7 @@ module.exports = React.createClass({ componentWillUnmount: function() { ScalarMessaging.stopListening(); - MatrixClientPeg.get().removeListener("RoomMember.membership", this._onRoomMemberMembership); + this.props.matrixClient.removeListener("RoomMember.membership", this._onRoomMemberMembership); dis.dispatch({ action: 'ui_opacity', @@ -195,14 +201,14 @@ module.exports = React.createClass({ // name and topic if (this._hasDiff(this.state.name, originalState.name)) { - promises.push(MatrixClientPeg.get().setRoomName(roomId, this.state.name)); + promises.push(this.props.matrixClient.setRoomName(roomId, this.state.name)); } if (this._hasDiff(this.state.topic, originalState.topic)) { - promises.push(MatrixClientPeg.get().setRoomTopic(roomId, this.state.topic)); + promises.push(this.props.matrixClient.setRoomTopic(roomId, this.state.topic)); } if (this.state.history_visibility !== originalState.history_visibility) { - promises.push(MatrixClientPeg.get().sendStateEvent( + promises.push(this.props.matrixClient.sendStateEvent( roomId, "m.room.history_visibility", { history_visibility: this.state.history_visibility }, "" @@ -210,14 +216,14 @@ module.exports = React.createClass({ } if (this.state.isRoomPublished !== originalState.isRoomPublished) { - promises.push(MatrixClientPeg.get().setRoomDirectoryVisibility( + promises.push(this.props.matrixClient.setRoomDirectoryVisibility( roomId, this.state.isRoomPublished ? "public" : "private" )); } if (this.state.join_rule !== originalState.join_rule) { - promises.push(MatrixClientPeg.get().sendStateEvent( + promises.push(this.props.matrixClient.sendStateEvent( roomId, "m.room.join_rules", { join_rule: this.state.join_rule }, "" @@ -225,7 +231,7 @@ module.exports = React.createClass({ } if (this.state.guest_access !== originalState.guest_access) { - promises.push(MatrixClientPeg.get().sendStateEvent( + promises.push(this.props.matrixClient.sendStateEvent( roomId, "m.room.guest_access", { guest_access: this.state.guest_access }, "" @@ -236,7 +242,7 @@ module.exports = React.createClass({ // power levels var powerLevels = this._getPowerLevels(); if (powerLevels) { - promises.push(MatrixClientPeg.get().sendStateEvent( + promises.push(this.props.matrixClient.sendStateEvent( roomId, "m.room.power_levels", powerLevels, "" )); } @@ -249,12 +255,12 @@ module.exports = React.createClass({ switch (diff.place) { case "add": promises.push( - MatrixClientPeg.get().setRoomTag(roomId, diff.key, {}) + this.props.matrixClient.setRoomTag(roomId, diff.key, {}) ); break; case "del": promises.push( - MatrixClientPeg.get().deleteRoomTag(roomId, diff.key) + this.props.matrixClient.deleteRoomTag(roomId, diff.key) ); break; default: @@ -311,7 +317,7 @@ module.exports = React.createClass({ if (!encrypt) { return q(); } var roomId = this.props.room.roomId; - return MatrixClientPeg.get().sendStateEvent( + return this.props.matrixClient.sendStateEvent( roomId, "m.room.encryption", { algorithm: "m.megolm.v1.aes-sha2" } ); @@ -476,7 +482,7 @@ module.exports = React.createClass({ }, mayChangeRoomAccess: function() { - var cli = MatrixClientPeg.get(); + var cli = this.props.matrixClient; var roomState = this.props.room.currentState; return (roomState.mayClientSendStateEvent("m.room.join_rules", cli) && roomState.mayClientSendStateEvent("m.room.guest_access", cli)); @@ -513,7 +519,7 @@ module.exports = React.createClass({ onForgetClick() { // FIXME: duplicated with RoomTagContextualMenu (and dead code in RoomView) - MatrixClientPeg.get().forget(this.props.room.roomId).done(function() { + this.props.matrixClient.forget(this.props.room.roomId).done(function() { dis.dispatch({ action: 'view_next_room' }); }, function(err) { var errCode = err.errcode || "unknown error code"; @@ -554,7 +560,7 @@ module.exports = React.createClass({ }, _renderEncryptionSection: function() { - var cli = MatrixClientPeg.get(); + var cli = this.props.matrixClient; var roomState = this.props.room.currentState; var isEncrypted = cli.isRoomEncrypted(this.props.room.roomId); var isGlobalBlacklistUnverified = UserSettingsStore.getLocalSettings().blacklistUnverifiedDevices; @@ -608,7 +614,7 @@ module.exports = React.createClass({ var PowerSelector = sdk.getComponent('elements.PowerSelector'); var Loader = sdk.getComponent("elements.Spinner"); - var cli = MatrixClientPeg.get(); + var cli = this.props.matrixClient; var roomState = this.props.room.currentState; var user_id = cli.credentials.userId; @@ -833,7 +839,7 @@ module.exports = React.createClass({ - List this room in { MatrixClientPeg.get().getDomain() }'s room directory? + List this room in { this.props.matrixClient.getDomain() }'s room directory?
    @@ -943,4 +949,4 @@ module.exports = React.createClass({
    ); } -}); +})); From a5a056292dcb2ca2abd661153318e80d05a269a9 Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 15 Feb 2017 18:58:59 +0000 Subject: [PATCH 07/12] Revert c082827fc7e3e11e4790c0306933c751c7a09c65 Revert the WithMatrixClient change: RoomView calls methods on the RoomSettings component and this breaks when RoomSettings is wrapped in a WithMatrixClient. --- src/components/views/rooms/RoomSettings.js | 56 ++++++++++------------ 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 783d343890..7a9cb2224c 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -17,6 +17,7 @@ limitations under the License. import q from 'q'; import React from 'react'; +import MatrixClientPeg from '../../../MatrixClientPeg'; import SdkConfig from '../../../SdkConfig'; import sdk from '../../../index'; import Modal from '../../../Modal'; @@ -26,7 +27,6 @@ import ScalarAuthClient from '../../../ScalarAuthClient'; import ScalarMessaging from '../../../ScalarMessaging'; import UserSettingsStore from '../../../UserSettingsStore'; import AccessibleButton from '../elements/AccessibleButton'; -import WithMatrixClient from '../../../wrappers/WithMatrixClient'; // parse a string as an integer; if the input is undefined, or cannot be parsed @@ -36,12 +36,9 @@ function parseIntWithDefault(val, def) { return isNaN(res) ? def : res; } -const BannedUser = WithMatrixClient(React.createClass({ +const BannedUser = React.createClass({ propTypes: { - /* MatrixClient instance */ - matrixClient: React.PropTypes.object.isRequired, - - member: React.PropTypes.object.isRequired, // js-sdk member object + member: React.PropTypes.string.isRequired, }, _onUnbanClick: function() { @@ -53,7 +50,7 @@ const BannedUser = WithMatrixClient(React.createClass({ onFinished: (proceed) => { if (!proceed) return; - this.props.matrixClient.unban( + MatrixClientPeg.get().unban( this.props.member.roomId, this.props.member.userId, ).catch((err) => { const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); @@ -78,15 +75,12 @@ const BannedUser = WithMatrixClient(React.createClass({ ); } -})); +}); -module.exports = WithMatrixClient(React.createClass({ +module.exports = React.createClass({ displayName: 'RoomSettings', propTypes: { - /* MatrixClient instance */ - matrixClient: React.PropTypes.object.isRequired, - room: React.PropTypes.object.isRequired, onSaveClick: React.PropTypes.func, onCancelClick: React.PropTypes.func, @@ -123,9 +117,9 @@ module.exports = WithMatrixClient(React.createClass({ componentWillMount: function() { ScalarMessaging.startListening(); - this.props.matrixClient.on("RoomMember.membership", this._onRoomMemberMembership); + MatrixClientPeg.get().on("RoomMember.membership", this._onRoomMemberMembership); - this.props.matrixClient.getRoomDirectoryVisibility( + MatrixClientPeg.get().getRoomDirectoryVisibility( this.props.room.roomId ).done((result) => { this.setState({ isRoomPublished: result.visibility === "public" }); @@ -153,7 +147,7 @@ module.exports = WithMatrixClient(React.createClass({ componentWillUnmount: function() { ScalarMessaging.stopListening(); - this.props.matrixClient.removeListener("RoomMember.membership", this._onRoomMemberMembership); + MatrixClientPeg.get().removeListener("RoomMember.membership", this._onRoomMemberMembership); dis.dispatch({ action: 'ui_opacity', @@ -201,14 +195,14 @@ module.exports = WithMatrixClient(React.createClass({ // name and topic if (this._hasDiff(this.state.name, originalState.name)) { - promises.push(this.props.matrixClient.setRoomName(roomId, this.state.name)); + promises.push(MatrixClientPeg.get().setRoomName(roomId, this.state.name)); } if (this._hasDiff(this.state.topic, originalState.topic)) { - promises.push(this.props.matrixClient.setRoomTopic(roomId, this.state.topic)); + promises.push(MatrixClientPeg.get().setRoomTopic(roomId, this.state.topic)); } if (this.state.history_visibility !== originalState.history_visibility) { - promises.push(this.props.matrixClient.sendStateEvent( + promises.push(MatrixClientPeg.get().sendStateEvent( roomId, "m.room.history_visibility", { history_visibility: this.state.history_visibility }, "" @@ -216,14 +210,14 @@ module.exports = WithMatrixClient(React.createClass({ } if (this.state.isRoomPublished !== originalState.isRoomPublished) { - promises.push(this.props.matrixClient.setRoomDirectoryVisibility( + promises.push(MatrixClientPeg.get().setRoomDirectoryVisibility( roomId, this.state.isRoomPublished ? "public" : "private" )); } if (this.state.join_rule !== originalState.join_rule) { - promises.push(this.props.matrixClient.sendStateEvent( + promises.push(MatrixClientPeg.get().sendStateEvent( roomId, "m.room.join_rules", { join_rule: this.state.join_rule }, "" @@ -231,7 +225,7 @@ module.exports = WithMatrixClient(React.createClass({ } if (this.state.guest_access !== originalState.guest_access) { - promises.push(this.props.matrixClient.sendStateEvent( + promises.push(MatrixClientPeg.get().sendStateEvent( roomId, "m.room.guest_access", { guest_access: this.state.guest_access }, "" @@ -242,7 +236,7 @@ module.exports = WithMatrixClient(React.createClass({ // power levels var powerLevels = this._getPowerLevels(); if (powerLevels) { - promises.push(this.props.matrixClient.sendStateEvent( + promises.push(MatrixClientPeg.get().sendStateEvent( roomId, "m.room.power_levels", powerLevels, "" )); } @@ -255,12 +249,12 @@ module.exports = WithMatrixClient(React.createClass({ switch (diff.place) { case "add": promises.push( - this.props.matrixClient.setRoomTag(roomId, diff.key, {}) + MatrixClientPeg.get().setRoomTag(roomId, diff.key, {}) ); break; case "del": promises.push( - this.props.matrixClient.deleteRoomTag(roomId, diff.key) + MatrixClientPeg.get().deleteRoomTag(roomId, diff.key) ); break; default: @@ -317,7 +311,7 @@ module.exports = WithMatrixClient(React.createClass({ if (!encrypt) { return q(); } var roomId = this.props.room.roomId; - return this.props.matrixClient.sendStateEvent( + return MatrixClientPeg.get().sendStateEvent( roomId, "m.room.encryption", { algorithm: "m.megolm.v1.aes-sha2" } ); @@ -482,7 +476,7 @@ module.exports = WithMatrixClient(React.createClass({ }, mayChangeRoomAccess: function() { - var cli = this.props.matrixClient; + var cli = MatrixClientPeg.get(); var roomState = this.props.room.currentState; return (roomState.mayClientSendStateEvent("m.room.join_rules", cli) && roomState.mayClientSendStateEvent("m.room.guest_access", cli)); @@ -519,7 +513,7 @@ module.exports = WithMatrixClient(React.createClass({ onForgetClick() { // FIXME: duplicated with RoomTagContextualMenu (and dead code in RoomView) - this.props.matrixClient.forget(this.props.room.roomId).done(function() { + MatrixClientPeg.get().forget(this.props.room.roomId).done(function() { dis.dispatch({ action: 'view_next_room' }); }, function(err) { var errCode = err.errcode || "unknown error code"; @@ -560,7 +554,7 @@ module.exports = WithMatrixClient(React.createClass({ }, _renderEncryptionSection: function() { - var cli = this.props.matrixClient; + var cli = MatrixClientPeg.get(); var roomState = this.props.room.currentState; var isEncrypted = cli.isRoomEncrypted(this.props.room.roomId); var isGlobalBlacklistUnverified = UserSettingsStore.getLocalSettings().blacklistUnverifiedDevices; @@ -614,7 +608,7 @@ module.exports = WithMatrixClient(React.createClass({ var PowerSelector = sdk.getComponent('elements.PowerSelector'); var Loader = sdk.getComponent("elements.Spinner"); - var cli = this.props.matrixClient; + var cli = MatrixClientPeg.get(); var roomState = this.props.room.currentState; var user_id = cli.credentials.userId; @@ -839,7 +833,7 @@ module.exports = WithMatrixClient(React.createClass({ - List this room in { this.props.matrixClient.getDomain() }'s room directory? + List this room in { MatrixClientPeg.get().getDomain() }'s room directory?
    @@ -949,4 +943,4 @@ module.exports = WithMatrixClient(React.createClass({
    ); } -})); +}); From 8698d40d3ce3ef665c704f6db14399fa635cc0de Mon Sep 17 00:00:00 2001 From: David Baker Date: Wed, 15 Feb 2017 19:01:00 +0000 Subject: [PATCH 08/12] Fix docs & add MatrixClient check Addresses PR feedback without breaking RoomSettings --- src/components/views/rooms/RoomSettings.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/views/rooms/RoomSettings.js b/src/components/views/rooms/RoomSettings.js index 7a9cb2224c..3247f5a90b 100644 --- a/src/components/views/rooms/RoomSettings.js +++ b/src/components/views/rooms/RoomSettings.js @@ -38,7 +38,7 @@ function parseIntWithDefault(val, def) { const BannedUser = React.createClass({ propTypes: { - member: React.PropTypes.string.isRequired, + member: React.PropTypes.object.isRequired, // js-sdk RoomMember }, _onUnbanClick: function() { @@ -147,7 +147,10 @@ module.exports = React.createClass({ componentWillUnmount: function() { ScalarMessaging.stopListening(); - MatrixClientPeg.get().removeListener("RoomMember.membership", this._onRoomMemberMembership); + const cli = MatrixClientPeg.get(); + if (cli) { + cli.removeListener("RoomMember.membership", this._onRoomMemberMembership); + } dis.dispatch({ action: 'ui_opacity', From f07da44aa55e6076ea28d57b761e627929425c3d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Thu, 16 Feb 2017 12:42:45 +0000 Subject: [PATCH 09/12] Don't handle logs db: It needs to close its connections first --- src/Lifecycle.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index 9aded55193..87a2878e37 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -360,7 +360,7 @@ function _clearIndexedDB() { } console.log("Clearing indexeddb"); window.indexedDB.deleteDatabase("matrix-js-sdk"); - window.indexedDB.deleteDatabase("logs"); + // TODO: Remove logs db as well. } function _clearLocalStorage() { From 9d2bb70823945391406bd65f3b8e34eef9a55662 Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Thu, 16 Feb 2017 17:03:22 +0000 Subject: [PATCH 10/12] If the home page is somehow accessed, goto directory For example, if someone ends up on /home somehow, just redirect to the directory instead of displaying a very awkward "File not found" plain text in the home page iFrame. --- src/components/structures/MatrixChat.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index 72680a3eac..3265249105 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -464,6 +464,10 @@ module.exports = React.createClass({ this.notifyNewScreen('directory'); break; case 'view_home_page': + if (!this._teamToken) { + dis.dispatch({action: 'view_room_directory'}); + return; + } this._setPage(PageTypes.HomePage); this.notifyNewScreen('home'); break; From 406c34b71576050fb9beffaee12088c1e55965af Mon Sep 17 00:00:00 2001 From: Luke Barnard Date: Thu, 16 Feb 2017 18:00:52 +0000 Subject: [PATCH 11/12] Make UserSettings use the right teamToken This threads the correct teamToken through to UserSettings for generating the referral section. --- src/components/structures/LoggedInView.js | 1 + src/components/structures/UserSettings.js | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/structures/LoggedInView.js b/src/components/structures/LoggedInView.js index 961277a4a1..aa9470f126 100644 --- a/src/components/structures/LoggedInView.js +++ b/src/components/structures/LoggedInView.js @@ -175,6 +175,7 @@ export default React.createClass({ collapsedRhs={this.props.collapse_rhs} enableLabs={this.props.config.enableLabs} referralBaseUrl={this.props.config.referralBaseUrl} + teamToken={this.props.teamToken} />; if (!this.props.collapse_rhs) right_panel = ; break; diff --git a/src/components/structures/UserSettings.js b/src/components/structures/UserSettings.js index fdade60dfd..f8240e247b 100644 --- a/src/components/structures/UserSettings.js +++ b/src/components/structures/UserSettings.js @@ -109,6 +109,10 @@ module.exports = React.createClass({ // true if RightPanel is collapsed collapsedRhs: React.PropTypes.bool, + + // Team token for the referral link. If falsy, the referral section will + // not appear + teamToken: React.PropTypes.string, }, getDefaultProps: function() { @@ -462,7 +466,7 @@ module.exports = React.createClass({ }, _renderReferral: function() { - const teamToken = window.localStorage.getItem('mx_team_token'); + const teamToken = this.props.teamToken; if (!teamToken) { return null; } From cca266c62cea505d8e80e5e32cac07bfccc1caf3 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 17 Feb 2017 10:43:55 +0000 Subject: [PATCH 12/12] Review comments --- src/Lifecycle.js | 12 +----------- src/MatrixClientPeg.js | 9 ++------- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/src/Lifecycle.js b/src/Lifecycle.js index d5683b35a0..295ffe44f4 100644 --- a/src/Lifecycle.js +++ b/src/Lifecycle.js @@ -380,21 +380,10 @@ export function startMatrixClient() { */ export function onLoggedOut() { _clearLocalStorage(); - _clearIndexedDB(); stopMatrixClient(); dis.dispatch({action: 'on_logged_out'}); } -function _clearIndexedDB() { - // remove indexeddb instances - if (!window.indexedDB) { - return; - } - console.log("Clearing indexeddb"); - window.indexedDB.deleteDatabase("matrix-js-sdk"); - // TODO: Remove logs db as well. -} - function _clearLocalStorage() { if (!window.localStorage) { return; @@ -423,6 +412,7 @@ export function stopMatrixClient() { if (cli) { cli.stopClient(); cli.removeAllListeners(); + cli.store.deleteAllData(); MatrixClientPeg.unset(); } } diff --git a/src/MatrixClientPeg.js b/src/MatrixClientPeg.js index 0267b36464..3759aa72c1 100644 --- a/src/MatrixClientPeg.js +++ b/src/MatrixClientPeg.js @@ -73,13 +73,8 @@ class MatrixClientPeg { // the react sdk doesn't work without this, so don't allow opts.pendingEventOrdering = "detached"; - let promise = q(); - if (this.matrixClient.store instanceof Matrix.IndexedDBStore) { - // load from storage before starting up. - console.log("Loading history from IndexedDB."); - promise = this.matrixClient.store.startup(); - } - // log any errors when starting up the database + let promise = this.matrixClient.store.startup(); + // log any errors when starting up the database (if one exists) promise.catch((err) => { console.error(err); }); // regardless of errors, start the client. If we did error out, we'll