Files
ThreadNet-Web/src/components/structures/RightPanel.js
T

289 lines
12 KiB
JavaScript
Raw Normal View History

2015-07-13 01:51:24 +01:00
/*
2016-01-07 04:17:56 +00:00
Copyright 2015, 2016 OpenMarket Ltd
2017-07-25 15:56:40 +01:00
Copyright 2017 Vector Creations Ltd
2015-07-13 01:51:24 +01: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 React from 'react';
2017-05-25 11:39:56 +01:00
import { _t } from 'matrix-react-sdk/lib/languageHandler';
import sdk from 'matrix-react-sdk';
import Matrix from "matrix-js-sdk";
import dis from 'matrix-react-sdk/lib/dispatcher';
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
2017-05-27 20:39:52 +01:00
import Analytics from 'matrix-react-sdk/lib/Analytics';
import rate_limited_func from 'matrix-react-sdk/lib/ratelimitedfunc';
import Modal from 'matrix-react-sdk/lib/Modal';
import AccessibleButton from 'matrix-react-sdk/lib/components/views/elements/AccessibleButton';
2015-07-13 01:51:24 +01:00
module.exports = React.createClass({
displayName: 'RightPanel',
2016-09-07 15:43:29 +01:00
propTypes: {
userId: React.PropTypes.string, // if showing an orphaned MemberInfo page, this is set
roomId: React.PropTypes.string, // if showing panels for a given room, this is set
2017-07-25 15:56:40 +01:00
groupId: React.PropTypes.string, // if showing panels for a given group, this is set
2016-09-13 12:18:09 +01:00
collapsed: React.PropTypes.bool, // currently unused property to request for a minimized view of the panel
2016-09-07 15:43:29 +01:00
},
Phase: {
2017-07-25 15:56:40 +01:00
RoomMemberList: 'RoomMemberList',
GroupMemberList: 'GroupMemberList',
2016-08-31 11:57:45 +01:00
FilePanel: 'FilePanel',
2016-08-23 14:27:58 +01:00
NotificationPanel: 'NotificationPanel',
2017-07-25 15:56:40 +01:00
RoomMemberInfo: 'RoomMemberInfo',
2017-08-09 15:36:51 +01:00
GroupMemberInfo: 'GroupMemberInfo',
},
2015-10-25 01:16:41 +00:00
componentWillMount: function() {
2015-10-25 19:09:38 +00:00
this.dispatcherRef = dis.register(this.onAction);
2017-07-25 15:56:40 +01:00
const cli = MatrixClientPeg.get();
2015-10-25 01:16:41 +00:00
cli.on("RoomState.members", this.onRoomStateMember);
},
componentWillUnmount: function() {
2016-03-15 18:38:24 +00:00
dis.unregister(this.dispatcherRef);
2015-10-25 01:16:41 +00:00
if (MatrixClientPeg.get()) {
MatrixClientPeg.get().removeListener("RoomState.members", this.onRoomStateMember);
}
},
2017-08-09 15:36:51 +01:00
componentWillReceiveProps: function(newprops) {
this.setState(this.getInitialState());
},
getInitialState: function() {
2016-08-28 14:04:25 +01:00
if (this.props.userId) {
2017-07-25 15:56:40 +01:00
const member = new Matrix.RoomMember(null, this.props.userId);
2016-08-28 14:04:25 +01:00
return {
2017-07-25 15:56:40 +01:00
phase: this.Phase.RoomMemberInfo,
2016-08-28 14:04:25 +01:00
member: member,
2017-05-27 20:39:52 +01:00
};
2017-07-25 15:56:40 +01:00
} else if (this.props.groupId) {
return {
phase: this.Phase.GroupMemberList
};
2017-05-27 20:39:52 +01:00
} else {
2016-08-28 14:04:25 +01:00
return {
2017-07-25 15:56:40 +01:00
phase: this.Phase.RoomMemberList
2017-05-27 20:39:52 +01:00
};
}
},
onMemberListButtonClick: function() {
2017-05-28 13:08:09 +01:00
Analytics.trackEvent('Right Panel', 'Member List Button', 'click');
2017-07-25 15:56:40 +01:00
this.setState({ phase: this.Phase.RoomMemberList });
},
2016-09-06 01:45:12 +01:00
onFileListButtonClick: function() {
2017-05-28 13:08:09 +01:00
Analytics.trackEvent('Right Panel', 'File List Button', 'click');
2017-02-02 18:42:03 +00:00
this.setState({ phase: this.Phase.FilePanel });
2016-09-06 01:45:12 +01:00
},
2016-09-08 03:02:50 +01:00
onNotificationListButtonClick: function() {
2017-05-28 13:08:09 +01:00
Analytics.trackEvent('Right Panel', 'Notification List Button', 'click');
2017-02-02 18:42:03 +00:00
this.setState({ phase: this.Phase.NotificationPanel });
},
onCollapseClick: function() {
dis.dispatch({
action: 'hide_right_panel',
});
2016-09-08 03:02:50 +01:00
},
2016-09-13 14:27:23 +01:00
onInviteButtonClick: function() {
2016-09-17 02:05:01 +01:00
if (MatrixClientPeg.get().isGuest()) {
2017-05-16 11:39:30 +01:00
dis.dispatch({action: 'view_set_mxid'});
2016-09-17 02:05:01 +01:00
return;
}
2016-09-13 14:27:23 +01:00
// call ChatInviteDialog
dis.dispatch({
action: 'view_invite',
roomId: this.props.roomId,
});
},
2015-10-25 01:16:41 +00:00
onRoomStateMember: function(ev, state, member) {
// redraw the badge on the membership list
2017-07-25 15:56:40 +01:00
if (this.state.phase == this.Phase.RoomMemberList && member.roomId === this.props.roomId) {
this._delayedUpdate();
2015-10-25 01:16:41 +00:00
}
2017-07-25 15:56:40 +01:00
else if (this.state.phase === this.Phase.RoomMemberInfo && member.roomId === this.props.roomId &&
member.userId === this.state.member.userId) {
// refresh the member info (e.g. new power level)
this._delayedUpdate();
}
2015-10-25 01:16:41 +00:00
},
_delayedUpdate: new rate_limited_func(function() {
2016-02-05 10:57:49 +00:00
this.forceUpdate();
}, 500),
2015-10-25 19:09:38 +00:00
onAction: function(payload) {
if (payload.action === "view_user") {
dis.dispatch({
action: 'show_right_panel',
});
2015-10-25 19:09:38 +00:00
if (payload.member) {
this.setState({
2017-07-25 15:56:40 +01:00
phase: this.Phase.RoomMemberInfo,
2015-10-25 19:09:38 +00:00
member: payload.member,
});
2017-07-25 15:56:40 +01:00
} else {
if (this.props.roomId) {
this.setState({
phase: this.Phase.RoomMemberList
});
} else if (this.props.groupId) {
this.setState({
2017-08-09 15:36:51 +01:00
phase: this.Phase.GroupMemberList,
groupId: payload.groupId,
member: payload.member,
2017-07-25 15:56:40 +01:00
});
}
2015-10-25 19:09:38 +00:00
}
2017-08-09 15:36:51 +01:00
} else if (payload.action === "view_group_user") {
this.setState({
phase: this.Phase.GroupMemberInfo,
groupId: payload.groupId,
member: payload.member,
});
} else if (payload.action === "view_room") {
2017-07-25 15:56:40 +01:00
if (this.state.phase === this.Phase.RoomMemberInfo) {
2015-10-27 23:28:34 +00:00
this.setState({
2017-07-25 15:56:40 +01:00
phase: this.Phase.RoomMemberList
2015-10-27 23:28:34 +00:00
});
}
}
2015-10-25 19:09:38 +00:00
},
2015-07-13 01:51:24 +01:00
render: function() {
2017-07-25 15:56:40 +01:00
const MemberList = sdk.getComponent('rooms.MemberList');
const GroupMemberList = sdk.getComponent('groups.GroupMemberList');
const NotificationPanel = sdk.getComponent('structures.NotificationPanel');
const FilePanel = sdk.getComponent('structures.FilePanel');
const TintableSvg = sdk.getComponent("elements.TintableSvg");
let buttonGroup;
let inviteGroup;
let panel;
2017-07-25 15:56:40 +01:00
let filesHighlight;
let membersHighlight;
let notificationsHighlight;
2015-10-24 20:19:54 +01:00
if (!this.props.collapsed) {
2017-07-25 15:56:40 +01:00
if (this.state.phase == this.Phase.RoomMemberList || this.state.phase === this.Phase.RoomMemberInfo) {
2015-10-24 20:19:54 +01:00
membersHighlight = <div className="mx_RightPanel_headerButton_highlight"></div>;
}
2016-08-31 11:57:45 +01:00
else if (this.state.phase == this.Phase.FilePanel) {
2015-10-24 20:19:54 +01:00
filesHighlight = <div className="mx_RightPanel_headerButton_highlight"></div>;
}
2016-08-23 14:27:58 +01:00
else if (this.state.phase == this.Phase.NotificationPanel) {
notificationsHighlight = <div className="mx_RightPanel_headerButton_highlight"></div>;
}
2015-10-24 20:19:54 +01:00
}
2017-07-25 15:56:40 +01:00
let membersBadge;
if ((this.state.phase == this.Phase.RoomMemberList || this.state.phase === this.Phase.RoomMemberInfo) && this.props.roomId) {
const cli = MatrixClientPeg.get();
const room = cli.getRoom(this.props.roomId);
let user_is_in_room;
2015-10-24 20:57:05 +01:00
if (room) {
2016-09-06 01:45:12 +01:00
membersBadge = room.getJoinedMembers().length;
2016-09-17 03:02:14 +01:00
user_is_in_room = room.hasMembershipState(
MatrixClientPeg.get().credentials.userId, 'join'
);
2015-10-24 20:57:05 +01:00
}
2016-09-17 03:02:14 +01:00
if (user_is_in_room) {
inviteGroup =
<AccessibleButton className="mx_RightPanel_invite" onClick={ this.onInviteButtonClick } >
2016-09-17 03:02:14 +01:00
<div className="mx_RightPanel_icon" >
<TintableSvg src="img/icon-invite-people.svg" width="35" height="35" />
</div>
<div className="mx_RightPanel_message">{ _t('Invite to this room') }</div>
</AccessibleButton>;
2016-09-17 03:02:14 +01:00
}
2015-10-24 20:47:48 +01:00
}
if (this.props.roomId) {
buttonGroup =
2015-07-15 04:16:38 +01:00
<div className="mx_RightPanel_headerButtonGroup">
2017-02-03 12:00:33 +00:00
<AccessibleButton className="mx_RightPanel_headerButton"
2017-05-26 13:25:46 +01:00
title={ _t('Members') } onClick={ this.onMemberListButtonClick }>
2016-09-06 01:45:12 +01:00
<div className="mx_RightPanel_headerButton_badge">{ membersBadge ? membersBadge : <span>&nbsp;</span>}</div>
<TintableSvg src="img/icons-people.svg" width="25" height="25"/>
2015-10-24 20:47:48 +01:00
{ membersHighlight }
</AccessibleButton>
2017-02-03 12:00:33 +00:00
<AccessibleButton
className="mx_RightPanel_headerButton mx_RightPanel_filebutton"
2017-05-26 13:25:46 +01:00
title={ _t('Files') } onClick={ this.onFileListButtonClick }>
2016-09-06 01:45:12 +01:00
<div className="mx_RightPanel_headerButton_badge">&nbsp;</div>
<TintableSvg src="img/icons-files.svg" width="25" height="25"/>
2015-10-24 20:19:54 +01:00
{ filesHighlight }
</AccessibleButton>
2017-02-03 12:00:33 +00:00
<AccessibleButton
className="mx_RightPanel_headerButton mx_RightPanel_notificationbutton"
2017-05-26 13:25:46 +01:00
title={ _t('Notifications') } onClick={ this.onNotificationListButtonClick }>
2016-09-06 01:45:12 +01:00
<div className="mx_RightPanel_headerButton_badge">&nbsp;</div>
2016-08-23 14:27:58 +01:00
<TintableSvg src="img/icons-notifications.svg" width="25" height="25"/>
{ notificationsHighlight }
</AccessibleButton>
2017-05-30 16:27:48 +01:00
<div className="mx_RightPanel_headerButton mx_RightPanel_collapsebutton" title={ _t("Hide panel") } onClick={ this.onCollapseClick }>
2017-02-02 18:42:03 +00:00
<TintableSvg src="img/minimise.svg" width="10" height="16"/>
</div>
</div>;
2016-08-28 14:04:25 +01:00
}
2016-08-28 14:04:25 +01:00
if (!this.props.collapsed) {
2017-07-25 15:56:40 +01:00
if (this.props.roomId && this.state.phase == this.Phase.RoomMemberList) {
2016-08-28 14:04:25 +01:00
panel = <MemberList roomId={this.props.roomId} key={this.props.roomId} />
2017-07-25 15:56:40 +01:00
} else if (this.props.groupId && this.state.phase == this.Phase.GroupMemberList) {
panel = <GroupMemberList groupId={this.props.groupId} key={this.props.groupId} />
2017-08-09 15:36:51 +01:00
} else if (this.state.phase == this.Phase.RoomMemberInfo) {
2017-07-25 15:56:40 +01:00
const MemberInfo = sdk.getComponent('rooms.MemberInfo');
2016-08-28 14:04:25 +01:00
panel = <MemberInfo member={this.state.member} key={this.props.roomId || this.props.userId} />
2017-08-09 15:36:51 +01:00
} else if (this.state.phase == this.Phase.GroupMemberInfo) {
const GroupMemberInfo = sdk.getComponent('groups.GroupMemberInfo');
panel = <GroupMemberInfo member={this.state.member} groupId={this.props.groupId} key={this.state.member.user_id} />
2017-07-25 15:56:40 +01:00
} else if (this.state.phase == this.Phase.NotificationPanel) {
2016-08-28 18:49:49 +01:00
panel = <NotificationPanel />
2017-07-25 15:56:40 +01:00
} else if (this.state.phase == this.Phase.FilePanel) {
2016-09-06 01:45:12 +01:00
panel = <FilePanel roomId={this.props.roomId} />
2016-08-31 11:57:45 +01:00
}
2016-04-15 18:23:47 +01:00
}
2015-10-25 19:09:38 +00:00
2016-04-15 18:23:47 +01:00
if (!panel) {
panel = <div className="mx_RightPanel_blank"></div>;
}
2017-07-25 15:56:40 +01:00
let classes = "mx_RightPanel mx_fadable";
if (this.props.collapsed) {
classes += " collapsed";
}
return (
<aside className={classes} style={{ opacity: this.props.opacity }}>
<div className="mx_RightPanel_header">
{ buttonGroup }
2015-07-13 01:51:24 +01:00
</div>
{ panel }
2016-04-15 15:53:27 +01:00
<div className="mx_RightPanel_footer">
{ inviteGroup }
2016-04-15 15:53:27 +01:00
</div>
</aside>
2015-07-13 01:51:24 +01:00
);
}
});