2016-11-03 18:42:26 +00:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2017-04-26 12:48:03 +00:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2016-11-03 18:42:26 +00:00
|
|
|
|
|
|
|
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 * as Matrix from 'matrix-js-sdk';
|
|
|
|
import React from 'react';
|
|
|
|
|
2017-06-01 02:00:30 +00:00
|
|
|
import UserSettingsStore from '../../UserSettingsStore';
|
2016-11-03 18:42:26 +00:00
|
|
|
import KeyCode from '../../KeyCode';
|
|
|
|
import Notifier from '../../Notifier';
|
|
|
|
import PageTypes from '../../PageTypes';
|
2017-04-28 17:21:22 +00:00
|
|
|
import CallMediaHandler from '../../CallMediaHandler';
|
2016-11-03 18:42:26 +00:00
|
|
|
import sdk from '../../index';
|
2017-01-25 14:59:18 +00:00
|
|
|
import dis from '../../dispatcher';
|
2017-05-15 13:56:05 +00:00
|
|
|
import sessionStore from '../../stores/SessionStore';
|
2017-05-31 14:13:27 +00:00
|
|
|
import MatrixClientPeg from '../../MatrixClientPeg';
|
2016-11-03 18:42:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This is what our MatrixChat shows when we are logged in. The precise view is
|
|
|
|
* determined by the page_type property.
|
|
|
|
*
|
|
|
|
* Currently it's very tightly coupled with MatrixChat. We should try to do
|
|
|
|
* something about that.
|
2016-11-03 18:54:30 +00:00
|
|
|
*
|
|
|
|
* Components mounted below us can access the matrix client via the react context.
|
2016-11-03 18:42:26 +00:00
|
|
|
*/
|
|
|
|
export default React.createClass({
|
|
|
|
displayName: 'LoggedInView',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
matrixClient: React.PropTypes.instanceOf(Matrix.MatrixClient).isRequired,
|
|
|
|
page_type: React.PropTypes.string.isRequired,
|
|
|
|
onRoomCreated: React.PropTypes.func,
|
|
|
|
onUserSettingsClose: React.PropTypes.func,
|
|
|
|
|
2017-04-28 12:22:55 +00:00
|
|
|
// Called with the credentials of a registered user (if they were a ROU that
|
|
|
|
// transitioned to PWLU)
|
|
|
|
onRegistered: React.PropTypes.func,
|
|
|
|
|
2017-02-03 11:48:24 +00:00
|
|
|
teamToken: React.PropTypes.string,
|
|
|
|
|
2016-11-03 18:42:26 +00:00
|
|
|
// and lots and lots of other stuff.
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:54:30 +00:00
|
|
|
childContextTypes: {
|
|
|
|
matrixClient: React.PropTypes.instanceOf(Matrix.MatrixClient),
|
2017-02-21 01:03:22 +00:00
|
|
|
authCache: React.PropTypes.object,
|
2016-11-03 18:54:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getChildContext: function() {
|
|
|
|
return {
|
|
|
|
matrixClient: this._matrixClient,
|
2017-02-21 01:03:22 +00:00
|
|
|
authCache: {
|
|
|
|
auth: {},
|
|
|
|
lastUpdate: 0,
|
|
|
|
},
|
2016-11-03 18:54:30 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2017-06-01 02:00:30 +00:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
// use compact timeline view
|
|
|
|
useCompactLayout: UserSettingsStore.getSyncedSetting('useCompactLayout'),
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:26 +00:00
|
|
|
componentWillMount: function() {
|
2016-11-03 18:54:30 +00:00
|
|
|
// stash the MatrixClient in case we log out before we are unmounted
|
|
|
|
this._matrixClient = this.props.matrixClient;
|
|
|
|
|
2016-11-03 18:42:26 +00:00
|
|
|
// _scrollStateMap is a map from room id to the scroll state returned by
|
|
|
|
// RoomView.getScrollState()
|
|
|
|
this._scrollStateMap = {};
|
|
|
|
|
2017-05-25 00:01:40 +00:00
|
|
|
CallMediaHandler.loadDevices();
|
2017-04-28 17:21:22 +00:00
|
|
|
|
2016-11-03 18:42:26 +00:00
|
|
|
document.addEventListener('keydown', this._onKeyDown);
|
2017-05-15 13:56:05 +00:00
|
|
|
|
|
|
|
this._sessionStore = sessionStore;
|
2017-05-16 10:52:51 +00:00
|
|
|
this._sessionStoreToken = this._sessionStore.addListener(
|
2017-05-15 16:17:32 +00:00
|
|
|
this._setStateFromSessionStore,
|
2017-05-16 10:52:51 +00:00
|
|
|
);
|
2017-05-15 13:56:05 +00:00
|
|
|
this._setStateFromSessionStore();
|
2017-06-05 15:08:03 +00:00
|
|
|
|
2017-06-01 02:00:30 +00:00
|
|
|
this._matrixClient.on("accountData", this.onAccountData);
|
2016-11-03 18:42:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
document.removeEventListener('keydown', this._onKeyDown);
|
2017-06-01 02:00:30 +00:00
|
|
|
this._matrixClient.removeListener("accountData", this.onAccountData);
|
2017-05-16 10:52:51 +00:00
|
|
|
if (this._sessionStoreToken) {
|
|
|
|
this._sessionStoreToken.remove();
|
2017-05-15 16:17:32 +00:00
|
|
|
}
|
2016-11-03 18:42:26 +00:00
|
|
|
},
|
|
|
|
|
2017-05-31 14:13:27 +00:00
|
|
|
// Child components assume that the client peg will not be null, so give them some
|
|
|
|
// sort of assurance here by only allowing a re-render if the client is truthy.
|
|
|
|
//
|
|
|
|
// This is required because `LoggedInView` maintains its own state and if this state
|
|
|
|
// updates after the client peg has been made null (during logout), then it will
|
|
|
|
// attempt to re-render and the children will throw errors.
|
|
|
|
shouldComponentUpdate: function() {
|
|
|
|
return Boolean(MatrixClientPeg.get());
|
2016-11-03 18:42:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
getScrollStateForRoom: function(roomId) {
|
|
|
|
return this._scrollStateMap[roomId];
|
|
|
|
},
|
|
|
|
|
2017-03-22 15:06:52 +00:00
|
|
|
canResetTimelineInRoom: function(roomId) {
|
|
|
|
if (!this.refs.roomView) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return this.refs.roomView.canResetTimeline();
|
|
|
|
},
|
|
|
|
|
2017-05-15 13:56:05 +00:00
|
|
|
_setStateFromSessionStore() {
|
|
|
|
this.setState({
|
|
|
|
userHasGeneratedPassword: Boolean(this._sessionStore.getCachedPassword()),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-06-01 02:00:30 +00:00
|
|
|
onAccountData: function(event) {
|
|
|
|
if (event.getType() === "im.vector.web.settings") {
|
|
|
|
this.setState({
|
2017-06-05 15:08:03 +00:00
|
|
|
useCompactLayout: event.getContent().useCompactLayout,
|
2017-06-01 02:00:30 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-11-03 18:42:26 +00:00
|
|
|
_onKeyDown: function(ev) {
|
|
|
|
/*
|
|
|
|
// Remove this for now as ctrl+alt = alt-gr so this breaks keyboards which rely on alt-gr for numbers
|
|
|
|
// Will need to find a better meta key if anyone actually cares about using this.
|
|
|
|
if (ev.altKey && ev.ctrlKey && ev.keyCode > 48 && ev.keyCode < 58) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_indexed_room',
|
|
|
|
roomIndex: ev.keyCode - 49,
|
|
|
|
});
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
|
|
|
var handled = false;
|
|
|
|
|
|
|
|
switch (ev.keyCode) {
|
|
|
|
case KeyCode.UP:
|
|
|
|
case KeyCode.DOWN:
|
2017-04-22 23:49:14 +00:00
|
|
|
if (ev.altKey && !ev.shiftKey && !ev.ctrlKey && !ev.metaKey) {
|
2016-11-03 18:42:26 +00:00
|
|
|
var action = ev.keyCode == KeyCode.UP ?
|
|
|
|
'view_prev_room' : 'view_next_room';
|
|
|
|
dis.dispatch({action: action});
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyCode.PAGE_UP:
|
|
|
|
case KeyCode.PAGE_DOWN:
|
2017-04-22 23:49:14 +00:00
|
|
|
if (!ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
|
|
|
|
this._onScrollKeyPressed(ev);
|
|
|
|
handled = true;
|
|
|
|
}
|
2016-11-03 18:42:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case KeyCode.HOME:
|
|
|
|
case KeyCode.END:
|
2017-04-22 23:49:14 +00:00
|
|
|
if (ev.ctrlKey && !ev.shiftKey && !ev.altKey && !ev.metaKey) {
|
2016-11-03 18:42:26 +00:00
|
|
|
this._onScrollKeyPressed(ev);
|
|
|
|
handled = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (handled) {
|
|
|
|
ev.stopPropagation();
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/** dispatch a page-up/page-down/etc to the appropriate component */
|
|
|
|
_onScrollKeyPressed: function(ev) {
|
|
|
|
if (this.refs.roomView) {
|
|
|
|
this.refs.roomView.handleScrollKey(ev);
|
|
|
|
}
|
2017-04-23 00:00:44 +00:00
|
|
|
else if (this.refs.roomDirectory) {
|
|
|
|
this.refs.roomDirectory.handleScrollKey(ev);
|
|
|
|
}
|
2016-11-03 18:42:26 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-04-26 12:48:03 +00:00
|
|
|
const LeftPanel = sdk.getComponent('structures.LeftPanel');
|
|
|
|
const RightPanel = sdk.getComponent('structures.RightPanel');
|
|
|
|
const RoomView = sdk.getComponent('structures.RoomView');
|
|
|
|
const UserSettings = sdk.getComponent('structures.UserSettings');
|
|
|
|
const CreateRoom = sdk.getComponent('structures.CreateRoom');
|
|
|
|
const RoomDirectory = sdk.getComponent('structures.RoomDirectory');
|
|
|
|
const HomePage = sdk.getComponent('structures.HomePage');
|
2017-06-05 15:51:50 +00:00
|
|
|
const GroupView = sdk.getComponent('structures.GroupView');
|
2017-04-26 12:48:03 +00:00
|
|
|
const MatrixToolbar = sdk.getComponent('globals.MatrixToolbar');
|
|
|
|
const NewVersionBar = sdk.getComponent('globals.NewVersionBar');
|
2017-06-03 14:10:05 +00:00
|
|
|
const UpdateCheckBar = sdk.getComponent('globals.UpdateCheckBar');
|
2017-05-05 15:31:33 +00:00
|
|
|
const PasswordNagBar = sdk.getComponent('globals.PasswordNagBar');
|
2017-04-26 12:48:03 +00:00
|
|
|
|
|
|
|
let page_element;
|
|
|
|
let right_panel = '';
|
2016-11-03 18:42:26 +00:00
|
|
|
|
|
|
|
switch (this.props.page_type) {
|
|
|
|
case PageTypes.RoomView:
|
|
|
|
page_element = <RoomView
|
|
|
|
ref='roomView'
|
|
|
|
autoJoin={this.props.autoJoin}
|
2017-04-28 12:22:55 +00:00
|
|
|
onRegistered={this.props.onRegistered}
|
2016-11-03 18:42:26 +00:00
|
|
|
thirdPartyInvite={this.props.thirdPartyInvite}
|
|
|
|
oobData={this.props.roomOobData}
|
|
|
|
eventPixelOffset={this.props.initialEventPixelOffset}
|
2017-05-24 17:04:04 +00:00
|
|
|
key={this.props.currentRoomId || 'roomview'}
|
2016-11-03 18:42:26 +00:00
|
|
|
opacity={this.props.middleOpacity}
|
|
|
|
collapsedRhs={this.props.collapse_rhs}
|
|
|
|
ConferenceHandler={this.props.ConferenceHandler}
|
2016-11-04 09:28:35 +00:00
|
|
|
scrollStateMap={this._scrollStateMap}
|
2017-01-20 14:22:27 +00:00
|
|
|
/>;
|
2017-05-18 23:20:32 +00:00
|
|
|
if (!this.props.collapse_rhs) right_panel = <RightPanel roomId={this.props.currentRoomId} opacity={this.props.rightOpacity} />;
|
2016-11-03 18:42:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PageTypes.UserSettings:
|
|
|
|
page_element = <UserSettings
|
|
|
|
onClose={this.props.onUserSettingsClose}
|
|
|
|
brand={this.props.config.brand}
|
|
|
|
enableLabs={this.props.config.enableLabs}
|
2017-01-31 15:17:43 +00:00
|
|
|
referralBaseUrl={this.props.config.referralBaseUrl}
|
2017-02-16 18:00:52 +00:00
|
|
|
teamToken={this.props.teamToken}
|
2017-01-20 14:22:27 +00:00
|
|
|
/>;
|
2017-05-18 23:20:32 +00:00
|
|
|
if (!this.props.collapse_rhs) right_panel = <RightPanel opacity={this.props.rightOpacity}/>;
|
2016-11-03 18:42:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PageTypes.CreateRoom:
|
|
|
|
page_element = <CreateRoom
|
|
|
|
onRoomCreated={this.props.onRoomCreated}
|
|
|
|
collapsedRhs={this.props.collapse_rhs}
|
2017-01-20 14:22:27 +00:00
|
|
|
/>;
|
2017-05-18 23:20:32 +00:00
|
|
|
if (!this.props.collapse_rhs) right_panel = <RightPanel opacity={this.props.rightOpacity}/>;
|
2016-11-03 18:42:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PageTypes.RoomDirectory:
|
|
|
|
page_element = <RoomDirectory
|
2017-04-23 00:00:44 +00:00
|
|
|
ref="roomDirectory"
|
2016-11-03 18:42:26 +00:00
|
|
|
config={this.props.config.roomDirectory}
|
2017-01-20 14:22:27 +00:00
|
|
|
/>;
|
2016-11-03 18:42:26 +00:00
|
|
|
break;
|
2016-11-13 14:10:46 +00:00
|
|
|
|
|
|
|
case PageTypes.HomePage:
|
2017-05-25 13:38:12 +00:00
|
|
|
// If team server config is present, pass the teamServerURL. props.teamToken
|
|
|
|
// must also be set for the team page to be displayed, otherwise the
|
|
|
|
// welcomePageUrl is used (which might be undefined).
|
|
|
|
const teamServerUrl = this.props.config.teamServerConfig ?
|
|
|
|
this.props.config.teamServerConfig.teamServerURL : null;
|
|
|
|
|
2016-11-13 14:10:46 +00:00
|
|
|
page_element = <HomePage
|
2017-05-25 13:38:12 +00:00
|
|
|
teamServerUrl={teamServerUrl}
|
2017-02-03 11:48:24 +00:00
|
|
|
teamToken={this.props.teamToken}
|
2017-05-24 16:55:36 +00:00
|
|
|
homePageUrl={this.props.config.welcomePageUrl}
|
|
|
|
/>;
|
2016-11-13 14:10:46 +00:00
|
|
|
break;
|
|
|
|
|
2016-11-03 18:42:26 +00:00
|
|
|
case PageTypes.UserView:
|
|
|
|
page_element = null; // deliberately null for now
|
2017-05-18 23:20:32 +00:00
|
|
|
right_panel = <RightPanel userId={this.props.viewUserId} opacity={this.props.rightOpacity} />;
|
2016-11-03 18:42:26 +00:00
|
|
|
break;
|
2017-06-05 15:51:50 +00:00
|
|
|
case PageTypes.GroupView:
|
|
|
|
// TODO
|
|
|
|
page_element = <GroupView
|
|
|
|
groupId={this.props.currentGroupId}
|
|
|
|
/>
|
|
|
|
break;
|
2016-11-03 18:42:26 +00:00
|
|
|
}
|
|
|
|
|
2017-06-03 14:10:05 +00:00
|
|
|
let topBar;
|
2017-05-26 09:34:36 +00:00
|
|
|
const isGuest = this.props.matrixClient.isGuest();
|
2016-11-03 18:42:26 +00:00
|
|
|
if (this.props.hasNewVersion) {
|
|
|
|
topBar = <NewVersionBar version={this.props.version} newVersion={this.props.newVersion}
|
2017-06-03 14:10:05 +00:00
|
|
|
releaseNotes={this.props.newVersionReleaseNotes}
|
2016-11-03 18:42:26 +00:00
|
|
|
/>;
|
2017-06-03 14:10:05 +00:00
|
|
|
} else if (this.props.checkingForUpdate) {
|
2017-06-11 18:12:40 +00:00
|
|
|
topBar = <UpdateCheckBar {...this.props.checkingForUpdate} />;
|
2017-05-15 13:56:05 +00:00
|
|
|
} else if (this.state.userHasGeneratedPassword) {
|
2017-05-05 15:31:33 +00:00
|
|
|
topBar = <PasswordNagBar />;
|
2017-05-26 09:34:36 +00:00
|
|
|
} else if (!isGuest && Notifier.supportsDesktopNotifications() && !Notifier.isEnabled() && !Notifier.isToolbarHidden()) {
|
2016-11-03 18:42:26 +00:00
|
|
|
topBar = <MatrixToolbar />;
|
|
|
|
}
|
|
|
|
|
|
|
|
var bodyClasses = 'mx_MatrixChat';
|
|
|
|
if (topBar) {
|
|
|
|
bodyClasses += ' mx_MatrixChat_toolbarShowing';
|
|
|
|
}
|
2017-06-01 02:00:30 +00:00
|
|
|
if (this.state.useCompactLayout) {
|
|
|
|
bodyClasses += ' mx_MatrixChat_useCompactLayout';
|
|
|
|
}
|
2016-11-03 18:42:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='mx_MatrixChat_wrapper'>
|
|
|
|
{topBar}
|
|
|
|
<div className={bodyClasses}>
|
2017-02-10 09:57:28 +00:00
|
|
|
<LeftPanel
|
|
|
|
selectedRoom={this.props.currentRoomId}
|
|
|
|
collapsed={this.props.collapse_lhs || false}
|
2017-05-18 23:20:32 +00:00
|
|
|
opacity={this.props.leftOpacity}
|
2017-02-10 09:57:28 +00:00
|
|
|
/>
|
2016-11-03 18:42:26 +00:00
|
|
|
<main className='mx_MatrixChat_middlePanel'>
|
|
|
|
{page_element}
|
|
|
|
</main>
|
|
|
|
{right_panel}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|