2017-08-18 13:22:50 +03:00
|
|
|
/*
|
2018-06-12 17:22:45 +03:00
|
|
|
Copyright 2017, 2018 New Vector Ltd
|
2018-06-18 14:16:33 +03:00
|
|
|
Copyright 2018 Michael Telatynski <7t3chguy@gmail.com>
|
2019-11-11 20:53:17 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2017-08-18 13:22:50 +03: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.
|
|
|
|
*/
|
|
|
|
|
2019-12-10 03:14:36 +03:00
|
|
|
import React from 'react';
|
2017-08-18 13:22:50 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 20:35:52 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-08-18 13:22:50 +03:00
|
|
|
import sdk from '../../../index';
|
|
|
|
import dis from '../../../dispatcher';
|
2019-11-28 21:16:59 +03:00
|
|
|
import {_t} from '../../../languageHandler';
|
2018-06-12 17:22:45 +03:00
|
|
|
import classNames from 'classnames';
|
2018-06-18 14:16:33 +03:00
|
|
|
import MatrixClientPeg from "../../../MatrixClientPeg";
|
2019-12-03 02:21:59 +03:00
|
|
|
import {ContextMenu, ContextMenuButton, toRightOf} from "../../structures/ContextMenu";
|
2019-12-17 20:26:12 +03:00
|
|
|
import MatrixClientContext from "../../../contexts/MatrixClientContext";
|
2017-08-18 13:22:50 +03:00
|
|
|
|
2019-12-10 03:14:36 +03:00
|
|
|
// XXX this class copies a lot from RoomTile.js
|
2019-09-06 20:35:52 +03:00
|
|
|
export default createReactClass({
|
2017-08-18 13:22:50 +03:00
|
|
|
displayName: 'GroupInviteTile',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
group: PropTypes.object.isRequired,
|
|
|
|
},
|
|
|
|
|
2019-12-17 20:26:12 +03:00
|
|
|
statics: {
|
|
|
|
contextType: MatrixClientContext,
|
2017-11-09 17:34:04 +03:00
|
|
|
},
|
|
|
|
|
2018-06-12 17:22:45 +03:00
|
|
|
getInitialState: function() {
|
|
|
|
return ({
|
|
|
|
hover: false,
|
|
|
|
badgeHover: false,
|
|
|
|
menuDisplayed: false,
|
|
|
|
selected: this.props.group.groupId === null, // XXX: this needs linking to LoggedInView/GroupView state
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-08-18 13:22:50 +03:00
|
|
|
onClick: function(e) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_group',
|
|
|
|
group_id: this.props.group.groupId,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-06-12 17:22:45 +03:00
|
|
|
onMouseEnter: function() {
|
|
|
|
const state = {hover: true};
|
|
|
|
// Only allow non-guests to access the context menu
|
2019-12-17 20:26:12 +03:00
|
|
|
if (!this.context.isGuest()) {
|
2018-06-12 17:22:45 +03:00
|
|
|
state.badgeHover = true;
|
|
|
|
}
|
|
|
|
this.setState(state);
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseLeave: function() {
|
|
|
|
this.setState({
|
|
|
|
badgeHover: false,
|
|
|
|
hover: false,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-12-10 03:14:36 +03:00
|
|
|
_showContextMenu: function(boundingClientRect) {
|
2018-06-18 14:16:33 +03:00
|
|
|
// Only allow non-guests to access the context menu
|
|
|
|
if (MatrixClientPeg.get().isGuest()) return;
|
|
|
|
|
2019-11-11 20:53:17 +03:00
|
|
|
const state = {
|
2019-12-10 03:14:36 +03:00
|
|
|
contextMenuPosition: boundingClientRect,
|
2019-11-11 20:53:17 +03:00
|
|
|
};
|
2018-06-12 17:22:45 +03:00
|
|
|
|
|
|
|
// If the badge is clicked, then no longer show tooltip
|
|
|
|
if (this.props.collapsed) {
|
2019-11-11 20:53:17 +03:00
|
|
|
state.hover = false;
|
2018-06-12 17:22:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-11 20:53:17 +03:00
|
|
|
this.setState(state);
|
|
|
|
},
|
2018-06-12 17:22:45 +03:00
|
|
|
|
2019-12-10 03:14:36 +03:00
|
|
|
onContextMenuButtonClick: function(e) {
|
|
|
|
// Prevent the RoomTile onClick event firing as well
|
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this._showContextMenu(e.target.getBoundingClientRect());
|
|
|
|
},
|
|
|
|
|
|
|
|
onContextMenu: function(e) {
|
|
|
|
// Prevent the native context menu
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
this._showContextMenu({
|
|
|
|
right: e.clientX,
|
|
|
|
top: e.clientY,
|
|
|
|
height: 0,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-11-11 20:53:17 +03:00
|
|
|
closeMenu: function() {
|
|
|
|
this.setState({
|
2019-12-10 03:14:36 +03:00
|
|
|
contextMenuPosition: null,
|
2019-11-11 20:53:17 +03:00
|
|
|
});
|
2018-06-12 17:22:45 +03:00
|
|
|
},
|
|
|
|
|
2017-08-18 13:22:50 +03:00
|
|
|
render: function() {
|
2019-11-11 20:53:17 +03:00
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
2017-08-18 13:22:50 +03:00
|
|
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
|
2017-10-19 17:47:52 +03:00
|
|
|
const groupName = this.props.group.name || this.props.group.groupId;
|
2017-11-09 17:34:04 +03:00
|
|
|
const httpAvatarUrl = this.props.group.avatarUrl ?
|
2019-12-17 20:26:12 +03:00
|
|
|
this.context.mxcUrlToHttp(this.props.group.avatarUrl, 24, 24) : null;
|
2017-10-19 17:47:52 +03:00
|
|
|
|
2017-11-09 17:34:04 +03:00
|
|
|
const av = <BaseAvatar name={groupName} width={24} height={24} url={httpAvatarUrl} />;
|
2017-08-18 13:22:50 +03:00
|
|
|
|
2019-12-10 03:14:36 +03:00
|
|
|
const isMenuDisplayed = Boolean(this.state.contextMenuPosition);
|
2018-06-19 21:11:22 +03:00
|
|
|
const nameClasses = classNames('mx_RoomTile_name mx_RoomTile_invite mx_RoomTile_badgeShown', {
|
2019-12-10 03:14:36 +03:00
|
|
|
'mx_RoomTile_badgeShown': this.state.badgeHover || isMenuDisplayed,
|
2018-06-12 17:22:45 +03:00
|
|
|
});
|
|
|
|
|
2019-05-19 17:23:43 +03:00
|
|
|
const label = <div title={this.props.group.groupId} className={nameClasses} dir="auto">
|
2017-10-19 17:47:52 +03:00
|
|
|
{ groupName }
|
2019-05-19 17:23:43 +03:00
|
|
|
</div>;
|
2017-08-18 13:22:50 +03:00
|
|
|
|
2019-12-10 03:14:36 +03:00
|
|
|
const badgeEllipsis = this.state.badgeHover || isMenuDisplayed;
|
2018-06-27 11:50:32 +03:00
|
|
|
const badgeClasses = classNames('mx_RoomTile_badge mx_RoomTile_highlight', {
|
2018-06-12 17:22:45 +03:00
|
|
|
'mx_RoomTile_badgeButton': badgeEllipsis,
|
|
|
|
});
|
|
|
|
|
|
|
|
const badgeContent = badgeEllipsis ? '\u00B7\u00B7\u00B7' : '!';
|
2019-11-11 20:53:17 +03:00
|
|
|
const badge = (
|
2019-11-28 21:16:59 +03:00
|
|
|
<ContextMenuButton
|
|
|
|
className={badgeClasses}
|
2019-12-10 03:14:36 +03:00
|
|
|
onClick={this.onContextMenuButtonClick}
|
2019-11-28 21:16:59 +03:00
|
|
|
label={_t("Options")}
|
2019-12-10 03:14:36 +03:00
|
|
|
isExpanded={isMenuDisplayed}
|
2019-11-28 21:16:59 +03:00
|
|
|
>
|
2019-11-11 20:53:17 +03:00
|
|
|
{ badgeContent }
|
2019-11-28 21:16:59 +03:00
|
|
|
</ContextMenuButton>
|
2019-11-11 20:53:17 +03:00
|
|
|
);
|
2018-06-12 17:22:45 +03:00
|
|
|
|
|
|
|
let tooltip;
|
|
|
|
if (this.props.collapsed && this.state.hover) {
|
2019-02-01 02:36:19 +03:00
|
|
|
const Tooltip = sdk.getComponent("elements.Tooltip");
|
|
|
|
tooltip = <Tooltip className="mx_RoomTile_tooltip" label={groupName} dir="auto" />;
|
2018-06-12 17:22:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const classes = classNames('mx_RoomTile mx_RoomTile_highlight', {
|
2019-12-10 03:14:36 +03:00
|
|
|
'mx_RoomTile_menuDisplayed': isMenuDisplayed,
|
2018-06-12 17:22:45 +03:00
|
|
|
'mx_RoomTile_selected': this.state.selected,
|
2019-02-15 14:37:22 +03:00
|
|
|
'mx_GroupInviteTile': true,
|
2018-06-12 17:22:45 +03:00
|
|
|
});
|
2017-08-18 13:22:50 +03:00
|
|
|
|
2019-11-11 20:53:17 +03:00
|
|
|
let contextMenu;
|
2019-12-10 03:14:36 +03:00
|
|
|
if (isMenuDisplayed) {
|
2019-11-11 20:53:17 +03:00
|
|
|
const GroupInviteTileContextMenu = sdk.getComponent('context_menus.GroupInviteTileContextMenu');
|
|
|
|
contextMenu = (
|
2019-12-10 03:14:36 +03:00
|
|
|
<ContextMenu {...toRightOf(this.state.contextMenuPosition)} onFinished={this.closeMenu}>
|
2019-11-11 20:53:17 +03:00
|
|
|
<GroupInviteTileContextMenu group={this.props.group} onFinished={this.closeMenu} />
|
|
|
|
</ContextMenu>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return <React.Fragment>
|
|
|
|
<AccessibleButton
|
|
|
|
className={classes}
|
|
|
|
onClick={this.onClick}
|
|
|
|
onMouseEnter={this.onMouseEnter}
|
|
|
|
onMouseLeave={this.onMouseLeave}
|
|
|
|
onContextMenu={this.onContextMenu}
|
2018-06-16 11:07:16 +03:00
|
|
|
>
|
2017-11-03 15:19:37 +03:00
|
|
|
<div className="mx_RoomTile_avatar">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ av }
|
2017-08-18 13:22:50 +03:00
|
|
|
</div>
|
2017-11-03 15:19:37 +03:00
|
|
|
<div className="mx_RoomTile_nameContainer">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ label }
|
|
|
|
{ badge }
|
2017-08-18 13:22:50 +03:00
|
|
|
</div>
|
2018-06-12 17:22:45 +03:00
|
|
|
{ tooltip }
|
2017-08-18 13:22:50 +03:00
|
|
|
</AccessibleButton>
|
2019-11-11 20:53:17 +03:00
|
|
|
|
|
|
|
{ contextMenu }
|
|
|
|
</React.Fragment>;
|
2017-08-21 21:34:07 +03:00
|
|
|
},
|
2017-08-18 13:22:50 +03:00
|
|
|
});
|