2017-06-05 18:51:50 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd.
|
2018-04-05 18:56:35 +03:00
|
|
|
Copyright 2017, 2018 New Vector Ltd.
|
2019-06-19 13:26:11 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2017-06-05 18:51: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.
|
|
|
|
*/
|
|
|
|
|
2017-06-27 11:58:29 +03:00
|
|
|
import React from 'react';
|
2019-08-30 12:34:59 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-06-29 19:51:38 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../MatrixClientPeg';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../index';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from '../../dispatcher/dispatcher';
|
2019-03-05 19:42:22 +03:00
|
|
|
import { getHostingLink } from '../../utils/HostingLink';
|
2017-06-23 19:02:54 +03:00
|
|
|
import { sanitizedHtmlNode } from '../../HtmlUtils';
|
2017-11-13 22:19:33 +03:00
|
|
|
import { _t, _td } from '../../languageHandler';
|
2017-07-06 21:13:14 +03:00
|
|
|
import AccessibleButton from '../views/elements/AccessibleButton';
|
2018-10-30 19:15:19 +03:00
|
|
|
import GroupHeaderButtons from '../views/right_panel/GroupHeaderButtons';
|
2018-10-31 14:09:24 +03:00
|
|
|
import MainSplit from './MainSplit';
|
|
|
|
import RightPanel from './RightPanel';
|
2017-07-21 16:03:10 +03:00
|
|
|
import Modal from '../../Modal';
|
2017-07-21 16:13:57 +03:00
|
|
|
import classnames from 'classnames';
|
2017-06-05 18:51:50 +03:00
|
|
|
|
2017-10-04 18:56:35 +03:00
|
|
|
import GroupStore from '../../stores/GroupStore';
|
2018-03-01 17:40:03 +03:00
|
|
|
import FlairStore from '../../stores/FlairStore';
|
2017-10-13 18:46:33 +03:00
|
|
|
import { showGroupAddRoomDialog } from '../../GroupAddressPicker';
|
2019-10-01 05:39:58 +03:00
|
|
|
import {makeGroupPermalink, makeUserPermalink} from "../../utils/permalinks/Permalinks";
|
2019-02-24 06:25:02 +03:00
|
|
|
import {Group} from "matrix-js-sdk";
|
2019-11-14 16:52:17 +03:00
|
|
|
import {allSettled, sleep} from "../../utils/promise";
|
2019-12-06 03:47:18 +03:00
|
|
|
import RightPanelStore from "../../stores/RightPanelStore";
|
2020-03-17 13:09:47 +03:00
|
|
|
import AutoHideScrollbar from "./AutoHideScrollbar";
|
2017-09-22 20:52:06 +03:00
|
|
|
|
2017-11-07 13:47:32 +03:00
|
|
|
const LONG_DESC_PLACEHOLDER = _td(
|
|
|
|
`<h1>HTML for your community's page</h1>
|
2017-11-06 21:52:55 +03:00
|
|
|
<p>
|
|
|
|
Use the long description to introduce new members to the community, or distribute
|
|
|
|
some important <a href="foo">links</a>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
You can even use 'img' tags
|
|
|
|
</p>
|
|
|
|
`);
|
|
|
|
|
2017-07-11 16:28:44 +03:00
|
|
|
const RoomSummaryType = PropTypes.shape({
|
|
|
|
room_id: PropTypes.string.isRequired,
|
|
|
|
profile: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
avatar_url: PropTypes.string,
|
|
|
|
canonical_alias: PropTypes.string,
|
2017-07-11 17:16:58 +03:00
|
|
|
}).isRequired,
|
2017-07-11 16:28:44 +03:00
|
|
|
});
|
2017-06-05 18:51:50 +03:00
|
|
|
|
2017-07-11 16:28:44 +03:00
|
|
|
const UserSummaryType = PropTypes.shape({
|
|
|
|
summaryInfo: PropTypes.shape({
|
|
|
|
user_id: PropTypes.string.isRequired,
|
2017-09-20 18:54:12 +03:00
|
|
|
role_id: PropTypes.string,
|
|
|
|
avatar_url: PropTypes.string,
|
|
|
|
displayname: PropTypes.string,
|
2017-07-11 16:28:44 +03:00
|
|
|
}).isRequired,
|
|
|
|
});
|
2017-07-06 21:13:14 +03:00
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
const CategoryRoomList = createReactClass({
|
2017-07-11 16:28:44 +03:00
|
|
|
displayName: 'CategoryRoomList',
|
2017-07-06 21:13:14 +03:00
|
|
|
|
|
|
|
props: {
|
2017-07-11 17:16:58 +03:00
|
|
|
rooms: PropTypes.arrayOf(RoomSummaryType).isRequired,
|
2017-07-11 16:28:44 +03:00
|
|
|
category: PropTypes.shape({
|
2017-07-11 15:41:00 +03:00
|
|
|
profile: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
}).isRequired,
|
2017-07-11 16:28:44 +03:00
|
|
|
}),
|
2017-09-21 18:53:10 +03:00
|
|
|
groupId: PropTypes.string.isRequired,
|
2017-09-21 14:44:17 +03:00
|
|
|
|
|
|
|
// Whether the list should be editable
|
|
|
|
editing: PropTypes.bool.isRequired,
|
2017-07-11 16:28:44 +03:00
|
|
|
},
|
|
|
|
|
2017-10-13 18:46:33 +03:00
|
|
|
onAddRoomsToSummaryClicked: function(ev) {
|
2017-09-21 18:53:10 +03:00
|
|
|
ev.preventDefault();
|
|
|
|
const AddressPickerDialog = sdk.getComponent("dialogs.AddressPickerDialog");
|
|
|
|
Modal.createTrackedDialog('Add Rooms to Group Summary', '', AddressPickerDialog, {
|
2017-10-16 15:18:39 +03:00
|
|
|
title: _t('Add rooms to the community summary'),
|
2017-09-21 18:53:10 +03:00
|
|
|
description: _t("Which rooms would you like to add to this summary?"),
|
2020-04-14 12:06:57 +03:00
|
|
|
placeholder: _t("Room name or address"),
|
2017-09-21 18:53:10 +03:00
|
|
|
button: _t("Add to summary"),
|
|
|
|
pickerType: 'room',
|
2017-09-27 17:30:58 +03:00
|
|
|
validAddressTypes: ['mx-room-id'],
|
2017-09-21 18:53:10 +03:00
|
|
|
groupId: this.props.groupId,
|
|
|
|
onFinished: (success, addrs) => {
|
|
|
|
if (!success) return;
|
|
|
|
const errorList = [];
|
2019-11-14 16:52:17 +03:00
|
|
|
allSettled(addrs.map((addr) => {
|
2018-05-01 13:18:45 +03:00
|
|
|
return GroupStore
|
|
|
|
.addRoomToGroupSummary(this.props.groupId, addr.address)
|
2019-11-14 16:52:17 +03:00
|
|
|
.catch(() => { errorList.push(addr.address); });
|
2017-09-21 18:53:10 +03:00
|
|
|
})).then(() => {
|
|
|
|
if (errorList.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog(
|
|
|
|
'Failed to add the following room to the group summary',
|
|
|
|
'', ErrorDialog,
|
|
|
|
{
|
|
|
|
title: _t(
|
|
|
|
"Failed to add the following rooms to the summary of %(groupId)s:",
|
|
|
|
{groupId: this.props.groupId},
|
|
|
|
),
|
|
|
|
description: errorList.join(", "),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-09-10 20:01:20 +03:00
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
2017-09-21 18:53:10 +03:00
|
|
|
},
|
|
|
|
|
2017-07-11 16:28:44 +03:00
|
|
|
render: function() {
|
2017-09-21 18:53:10 +03:00
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
|
|
|
const addButton = this.props.editing ?
|
2017-10-13 18:57:52 +03:00
|
|
|
(<AccessibleButton className="mx_GroupView_featuredThings_addButton"
|
|
|
|
onClick={this.onAddRoomsToSummaryClicked}
|
|
|
|
>
|
2019-01-11 04:37:28 +03:00
|
|
|
<TintableSvg src={require("../../../res/img/icons-create-room.svg")} width="64" height="64" />
|
2017-09-21 18:53:10 +03:00
|
|
|
<div className="mx_GroupView_featuredThings_addButton_label">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ _t('Add a Room') }
|
2017-09-21 18:53:10 +03:00
|
|
|
</div>
|
|
|
|
</AccessibleButton>) : <div />;
|
|
|
|
|
2017-07-11 16:28:44 +03:00
|
|
|
const roomNodes = this.props.rooms.map((r) => {
|
2017-09-22 17:55:42 +03:00
|
|
|
return <FeaturedRoom
|
|
|
|
key={r.room_id}
|
|
|
|
groupId={this.props.groupId}
|
|
|
|
editing={this.props.editing}
|
2017-09-28 13:21:06 +03:00
|
|
|
summaryInfo={r} />;
|
2017-07-11 16:28:44 +03:00
|
|
|
});
|
2017-09-20 16:41:29 +03:00
|
|
|
|
2017-09-21 18:53:10 +03:00
|
|
|
let catHeader = <div />;
|
2017-07-11 16:28:44 +03:00
|
|
|
if (this.props.category && this.props.category.profile) {
|
2017-09-28 13:21:06 +03:00
|
|
|
catHeader = <div className="mx_GroupView_featuredThings_category">
|
|
|
|
{ this.props.category.profile.name }
|
|
|
|
</div>;
|
2017-07-11 16:28:44 +03:00
|
|
|
}
|
2017-09-20 16:41:29 +03:00
|
|
|
return <div className="mx_GroupView_featuredThings_container">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ catHeader }
|
|
|
|
{ roomNodes }
|
|
|
|
{ addButton }
|
2017-07-11 16:28:44 +03:00
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
const FeaturedRoom = createReactClass({
|
2017-07-11 16:28:44 +03:00
|
|
|
displayName: 'FeaturedRoom',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
summaryInfo: RoomSummaryType.isRequired,
|
2017-09-22 17:55:42 +03:00
|
|
|
editing: PropTypes.bool.isRequired,
|
|
|
|
groupId: PropTypes.string.isRequired,
|
2017-07-06 21:13:14 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(e) {
|
|
|
|
e.preventDefault();
|
2017-07-10 21:32:02 +03:00
|
|
|
e.stopPropagation();
|
2017-07-06 21:13:14 +03:00
|
|
|
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
|
|
|
room_alias: this.props.summaryInfo.profile.canonical_alias,
|
|
|
|
room_id: this.props.summaryInfo.room_id,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-09-22 17:55:42 +03:00
|
|
|
onDeleteClicked: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.removeRoomFromGroupSummary(
|
|
|
|
this.props.groupId,
|
2017-09-22 17:55:42 +03:00
|
|
|
this.props.summaryInfo.room_id,
|
|
|
|
).catch((err) => {
|
|
|
|
console.error('Error whilst removing room from group summary', err);
|
|
|
|
const roomName = this.props.summaryInfo.name ||
|
|
|
|
this.props.summaryInfo.canonical_alias ||
|
|
|
|
this.props.summaryInfo.room_id;
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog(
|
|
|
|
'Failed to remove room from group summary',
|
|
|
|
'', ErrorDialog,
|
|
|
|
{
|
|
|
|
title: _t(
|
|
|
|
"Failed to remove the room from the summary of %(groupId)s",
|
|
|
|
{groupId: this.props.groupId},
|
|
|
|
),
|
|
|
|
description: _t("The room '%(roomName)s' could not be removed from the summary.", {roomName}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-06 21:13:14 +03:00
|
|
|
render: function() {
|
|
|
|
const RoomAvatar = sdk.getComponent("avatars.RoomAvatar");
|
|
|
|
|
2017-09-27 18:18:15 +03:00
|
|
|
const roomName = this.props.summaryInfo.profile.name ||
|
|
|
|
this.props.summaryInfo.profile.canonical_alias ||
|
|
|
|
_t("Unnamed Room");
|
|
|
|
|
2017-07-06 21:13:14 +03:00
|
|
|
const oobData = {
|
|
|
|
roomId: this.props.summaryInfo.room_id,
|
|
|
|
avatarUrl: this.props.summaryInfo.profile.avatar_url,
|
2017-09-27 18:18:15 +03:00
|
|
|
name: roomName,
|
2017-07-06 21:13:14 +03:00
|
|
|
};
|
2017-09-27 18:18:15 +03:00
|
|
|
|
2017-07-06 21:13:14 +03:00
|
|
|
let permalink = null;
|
|
|
|
if (this.props.summaryInfo.profile && this.props.summaryInfo.profile.canonical_alias) {
|
2017-12-13 02:33:40 +03:00
|
|
|
permalink = makeGroupPermalink(this.props.summaryInfo.profile.canonical_alias);
|
2017-07-06 21:13:14 +03:00
|
|
|
}
|
2017-09-27 18:18:15 +03:00
|
|
|
|
2017-07-06 21:13:14 +03:00
|
|
|
let roomNameNode = null;
|
|
|
|
if (permalink) {
|
2017-09-28 13:21:06 +03:00
|
|
|
roomNameNode = <a href={permalink} onClick={this.onClick} >{ roomName }</a>;
|
2017-07-06 21:13:14 +03:00
|
|
|
} else {
|
2017-09-28 13:21:06 +03:00
|
|
|
roomNameNode = <span>{ roomName }</span>;
|
2017-07-06 21:13:14 +03:00
|
|
|
}
|
|
|
|
|
2017-09-22 17:55:42 +03:00
|
|
|
const deleteButton = this.props.editing ?
|
|
|
|
<img
|
|
|
|
className="mx_GroupView_featuredThing_deleteButton"
|
2019-01-11 04:37:28 +03:00
|
|
|
src={require("../../../res/img/cancel-small.svg")}
|
2017-09-22 17:55:42 +03:00
|
|
|
width="14"
|
|
|
|
height="14"
|
|
|
|
alt="Delete"
|
2017-09-28 13:21:06 +03:00
|
|
|
onClick={this.onDeleteClicked} />
|
2017-09-22 17:55:42 +03:00
|
|
|
: <div />;
|
|
|
|
|
2017-07-10 21:32:02 +03:00
|
|
|
return <AccessibleButton className="mx_GroupView_featuredThing" onClick={this.onClick}>
|
2017-07-06 21:13:14 +03:00
|
|
|
<RoomAvatar oobData={oobData} width={64} height={64} />
|
2017-09-28 13:21:06 +03:00
|
|
|
<div className="mx_GroupView_featuredThing_name">{ roomNameNode }</div>
|
|
|
|
{ deleteButton }
|
2017-07-10 21:32:02 +03:00
|
|
|
</AccessibleButton>;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
const RoleUserList = createReactClass({
|
2017-07-11 16:28:44 +03:00
|
|
|
displayName: 'RoleUserList',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
users: PropTypes.arrayOf(UserSummaryType).isRequired,
|
|
|
|
role: PropTypes.shape({
|
|
|
|
profile: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
}).isRequired,
|
|
|
|
}),
|
2017-09-20 17:29:31 +03:00
|
|
|
groupId: PropTypes.string.isRequired,
|
2017-09-21 14:44:17 +03:00
|
|
|
|
|
|
|
// Whether the list should be editable
|
|
|
|
editing: PropTypes.bool.isRequired,
|
2017-09-20 17:29:31 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onAddUsersClicked: function(ev) {
|
|
|
|
ev.preventDefault();
|
2017-09-21 18:53:10 +03:00
|
|
|
const AddressPickerDialog = sdk.getComponent("dialogs.AddressPickerDialog");
|
|
|
|
Modal.createTrackedDialog('Add Users to Group Summary', '', AddressPickerDialog, {
|
2017-10-16 15:18:39 +03:00
|
|
|
title: _t('Add users to the community summary'),
|
2017-09-20 17:29:31 +03:00
|
|
|
description: _t("Who would you like to add to this summary?"),
|
2019-05-16 23:35:43 +03:00
|
|
|
placeholder: _t("Name or Matrix ID"),
|
2017-09-20 17:29:31 +03:00
|
|
|
button: _t("Add to summary"),
|
2017-09-27 17:30:58 +03:00
|
|
|
validAddressTypes: ['mx-user-id'],
|
2017-09-20 17:29:31 +03:00
|
|
|
groupId: this.props.groupId,
|
2017-09-27 13:04:41 +03:00
|
|
|
shouldOmitSelf: false,
|
2017-09-20 17:29:31 +03:00
|
|
|
onFinished: (success, addrs) => {
|
|
|
|
if (!success) return;
|
2017-09-21 14:34:16 +03:00
|
|
|
const errorList = [];
|
2019-11-14 16:52:17 +03:00
|
|
|
allSettled(addrs.map((addr) => {
|
2018-05-01 13:18:45 +03:00
|
|
|
return GroupStore
|
2017-09-22 20:52:06 +03:00
|
|
|
.addUserToGroupSummary(addr.address)
|
2019-11-14 16:52:17 +03:00
|
|
|
.catch(() => { errorList.push(addr.address); });
|
2017-09-21 14:34:16 +03:00
|
|
|
})).then(() => {
|
|
|
|
if (errorList.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog(
|
2017-10-16 15:18:39 +03:00
|
|
|
'Failed to add the following users to the community summary',
|
2017-09-21 14:34:16 +03:00
|
|
|
'', ErrorDialog,
|
|
|
|
{
|
|
|
|
title: _t(
|
|
|
|
"Failed to add the following users to the summary of %(groupId)s:",
|
|
|
|
{groupId: this.props.groupId},
|
|
|
|
),
|
|
|
|
description: errorList.join(", "),
|
|
|
|
});
|
2017-09-20 18:32:02 +03:00
|
|
|
});
|
2017-09-20 17:29:31 +03:00
|
|
|
},
|
2019-09-10 20:01:20 +03:00
|
|
|
}, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true);
|
2017-07-11 16:28:44 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-09-20 16:41:29 +03:00
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
2017-09-21 14:44:17 +03:00
|
|
|
const addButton = this.props.editing ?
|
|
|
|
(<AccessibleButton className="mx_GroupView_featuredThings_addButton" onClick={this.onAddUsersClicked}>
|
2019-01-11 04:37:28 +03:00
|
|
|
<TintableSvg src={require("../../../res/img/icons-create-room.svg")} width="64" height="64" />
|
2017-09-21 14:44:17 +03:00
|
|
|
<div className="mx_GroupView_featuredThings_addButton_label">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ _t('Add a User') }
|
2017-09-21 14:44:17 +03:00
|
|
|
</div>
|
2017-09-21 18:53:10 +03:00
|
|
|
</AccessibleButton>) : <div />;
|
2017-07-11 16:28:44 +03:00
|
|
|
const userNodes = this.props.users.map((u) => {
|
2017-09-22 17:55:42 +03:00
|
|
|
return <FeaturedUser
|
|
|
|
key={u.user_id}
|
|
|
|
summaryInfo={u}
|
|
|
|
editing={this.props.editing}
|
2017-09-28 13:21:06 +03:00
|
|
|
groupId={this.props.groupId} />;
|
2017-07-11 16:28:44 +03:00
|
|
|
});
|
2017-09-21 18:53:10 +03:00
|
|
|
let roleHeader = <div />;
|
2017-07-11 16:28:44 +03:00
|
|
|
if (this.props.role && this.props.role.profile) {
|
2017-09-28 13:21:06 +03:00
|
|
|
roleHeader = <div className="mx_GroupView_featuredThings_category">{ this.props.role.profile.name }</div>;
|
2017-07-11 16:28:44 +03:00
|
|
|
}
|
2017-09-20 16:41:29 +03:00
|
|
|
return <div className="mx_GroupView_featuredThings_container">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ roleHeader }
|
|
|
|
{ userNodes }
|
|
|
|
{ addButton }
|
2017-07-11 16:28:44 +03:00
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
});
|
2017-07-10 21:32:02 +03:00
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
const FeaturedUser = createReactClass({
|
2017-07-10 21:32:02 +03:00
|
|
|
displayName: 'FeaturedUser',
|
|
|
|
|
|
|
|
props: {
|
2017-07-11 16:28:44 +03:00
|
|
|
summaryInfo: UserSummaryType.isRequired,
|
2017-09-22 17:55:42 +03:00
|
|
|
editing: PropTypes.bool.isRequired,
|
|
|
|
groupId: PropTypes.string.isRequired,
|
2017-07-10 21:32:02 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_start_chat_or_reuse',
|
|
|
|
user_id: this.props.summaryInfo.user_id,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-09-22 17:55:42 +03:00
|
|
|
onDeleteClicked: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.removeUserFromGroupSummary(
|
|
|
|
this.props.groupId,
|
2017-09-22 17:55:42 +03:00
|
|
|
this.props.summaryInfo.user_id,
|
|
|
|
).catch((err) => {
|
|
|
|
console.error('Error whilst removing user from group summary', err);
|
|
|
|
const displayName = this.props.summaryInfo.displayname || this.props.summaryInfo.user_id;
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog(
|
2017-10-16 15:18:39 +03:00
|
|
|
'Failed to remove user from community summary',
|
2017-09-22 17:55:42 +03:00
|
|
|
'', ErrorDialog,
|
|
|
|
{
|
|
|
|
title: _t(
|
|
|
|
"Failed to remove a user from the summary of %(groupId)s",
|
|
|
|
{groupId: this.props.groupId},
|
|
|
|
),
|
|
|
|
description: _t("The user '%(displayName)s' could not be removed from the summary.", {displayName}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-10 21:32:02 +03:00
|
|
|
render: function() {
|
2017-09-20 18:54:12 +03:00
|
|
|
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
2017-09-21 12:34:11 +03:00
|
|
|
const name = this.props.summaryInfo.displayname || this.props.summaryInfo.user_id;
|
2017-07-10 21:32:02 +03:00
|
|
|
|
2017-12-13 02:33:40 +03:00
|
|
|
const permalink = makeUserPermalink(this.props.summaryInfo.user_id);
|
2017-09-28 13:21:06 +03:00
|
|
|
const userNameNode = <a href={permalink} onClick={this.onClick}>{ name }</a>;
|
2017-09-20 18:54:12 +03:00
|
|
|
const httpUrl = MatrixClientPeg.get()
|
|
|
|
.mxcUrlToHttp(this.props.summaryInfo.avatar_url, 64, 64);
|
2017-07-10 21:32:02 +03:00
|
|
|
|
2017-09-22 17:55:42 +03:00
|
|
|
const deleteButton = this.props.editing ?
|
|
|
|
<img
|
|
|
|
className="mx_GroupView_featuredThing_deleteButton"
|
2019-01-11 04:37:28 +03:00
|
|
|
src={require("../../../res/img/cancel-small.svg")}
|
2017-09-22 17:55:42 +03:00
|
|
|
width="14"
|
|
|
|
height="14"
|
|
|
|
alt="Delete"
|
2017-09-28 13:21:06 +03:00
|
|
|
onClick={this.onDeleteClicked} />
|
2017-09-22 17:55:42 +03:00
|
|
|
: <div />;
|
|
|
|
|
2017-07-10 21:32:02 +03:00
|
|
|
return <AccessibleButton className="mx_GroupView_featuredThing" onClick={this.onClick}>
|
2017-09-20 18:54:12 +03:00
|
|
|
<BaseAvatar name={name} url={httpUrl} width={64} height={64} />
|
2017-09-28 13:21:06 +03:00
|
|
|
<div className="mx_GroupView_featuredThing_name">{ userNameNode }</div>
|
|
|
|
{ deleteButton }
|
2017-07-06 21:13:14 +03:00
|
|
|
</AccessibleButton>;
|
2017-07-07 15:46:05 +03:00
|
|
|
},
|
2017-07-06 21:13:14 +03:00
|
|
|
});
|
|
|
|
|
2018-04-05 18:56:35 +03:00
|
|
|
const GROUP_JOINPOLICY_OPEN = "open";
|
|
|
|
const GROUP_JOINPOLICY_INVITE = "invite";
|
2018-03-29 19:25:06 +03:00
|
|
|
|
2019-08-30 12:34:59 +03:00
|
|
|
export default createReactClass({
|
2017-06-05 18:51:50 +03:00
|
|
|
displayName: 'GroupView',
|
|
|
|
|
|
|
|
propTypes: {
|
2017-06-29 19:51:38 +03:00
|
|
|
groupId: PropTypes.string.isRequired,
|
2017-11-06 21:02:50 +03:00
|
|
|
// Whether this is the first time the group admin is viewing the group
|
|
|
|
groupIsNew: PropTypes.bool,
|
2017-06-05 18:51:50 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
summary: null,
|
2017-10-31 14:42:09 +03:00
|
|
|
isGroupPublicised: null,
|
|
|
|
isUserPrivileged: null,
|
|
|
|
groupRooms: null,
|
|
|
|
groupRoomsLoading: null,
|
2017-06-26 19:47:17 +03:00
|
|
|
error: null,
|
2017-07-06 21:13:14 +03:00
|
|
|
editing: false,
|
2017-07-21 13:12:15 +03:00
|
|
|
saving: false,
|
2017-07-21 16:03:10 +03:00
|
|
|
uploadingAvatar: false,
|
2018-03-01 17:40:03 +03:00
|
|
|
avatarChanged: false,
|
2017-08-21 21:18:32 +03:00
|
|
|
membershipBusy: false,
|
2017-09-22 21:27:02 +03:00
|
|
|
publicityBusy: false,
|
2017-11-08 13:07:43 +03:00
|
|
|
inviterProfile: null,
|
2020-03-20 03:18:24 +03:00
|
|
|
showRightPanel: RightPanelStore.getSharedInstance().isOpenForGroup,
|
2017-06-05 18:51:50 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2020-03-31 23:14:17 +03:00
|
|
|
componentDidMount: function() {
|
2018-05-01 13:18:45 +03:00
|
|
|
this._unmounted = false;
|
2017-11-10 13:49:14 +03:00
|
|
|
this._matrixClient = MatrixClientPeg.get();
|
|
|
|
this._matrixClient.on("Group.myMembership", this._onGroupMyMembership);
|
|
|
|
|
2017-11-06 21:02:50 +03:00
|
|
|
this._initGroupStore(this.props.groupId, true);
|
2018-05-29 15:16:39 +03:00
|
|
|
|
|
|
|
this._dispatcherRef = dis.register(this._onAction);
|
2020-03-20 03:18:24 +03:00
|
|
|
this._rightPanelStoreToken = RightPanelStore.getSharedInstance().addListener(this._onRightPanelStoreUpdate);
|
2017-08-21 21:18:32 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
componentWillUnmount: function() {
|
2018-05-01 13:18:45 +03:00
|
|
|
this._unmounted = true;
|
2017-11-10 13:49:14 +03:00
|
|
|
this._matrixClient.removeListener("Group.myMembership", this._onGroupMyMembership);
|
2018-05-29 15:16:39 +03:00
|
|
|
dis.unregister(this._dispatcherRef);
|
2020-03-20 03:18:24 +03:00
|
|
|
|
|
|
|
// Remove RightPanelStore listener
|
|
|
|
if (this._rightPanelStoreToken) {
|
|
|
|
this._rightPanelStoreToken.remove();
|
|
|
|
}
|
2017-06-05 18:51:50 +03:00
|
|
|
},
|
|
|
|
|
2020-04-01 23:35:39 +03:00
|
|
|
// TODO: [REACT-WARNING] Replace with appropriate lifecycle event
|
|
|
|
UNSAFE_componentWillReceiveProps: function(newProps) {
|
|
|
|
if (this.props.groupId !== newProps.groupId) {
|
2017-06-05 18:51:50 +03:00
|
|
|
this.setState({
|
|
|
|
summary: null,
|
2017-06-27 12:28:46 +03:00
|
|
|
error: null,
|
2017-07-07 12:08:29 +03:00
|
|
|
}, () => {
|
2017-10-04 18:56:35 +03:00
|
|
|
this._initGroupStore(newProps.groupId);
|
2017-06-27 15:13:00 +03:00
|
|
|
});
|
2017-06-05 18:51:50 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-03-20 03:18:24 +03:00
|
|
|
_onRightPanelStoreUpdate: function() {
|
|
|
|
this.setState({
|
|
|
|
showRightPanel: RightPanelStore.getSharedInstance().isOpenForGroup,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-08-21 21:18:32 +03:00
|
|
|
_onGroupMyMembership: function(group) {
|
2018-05-01 13:18:45 +03:00
|
|
|
if (this._unmounted || group.groupId !== this.props.groupId) return;
|
2018-04-10 13:49:35 +03:00
|
|
|
if (group.myMembership === 'leave') {
|
|
|
|
// Leave settings - the user might have clicked the "Leave" button
|
2018-04-10 15:28:42 +03:00
|
|
|
this._closeSettings();
|
2018-04-10 13:49:35 +03:00
|
|
|
}
|
2017-08-21 21:18:32 +03:00
|
|
|
this.setState({membershipBusy: false});
|
|
|
|
},
|
|
|
|
|
2017-11-06 21:02:50 +03:00
|
|
|
_initGroupStore: function(groupId, firstInit) {
|
2017-11-10 13:49:14 +03:00
|
|
|
const group = this._matrixClient.getGroup(groupId);
|
2017-11-07 19:42:43 +03:00
|
|
|
if (group && group.inviter && group.inviter.userId) {
|
|
|
|
this._fetchInviterProfile(group.inviter.userId);
|
|
|
|
}
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.registerListener(groupId, this.onGroupStoreUpdated.bind(this, firstInit));
|
2017-11-28 14:27:33 +03:00
|
|
|
let willDoOnboarding = false;
|
2018-05-01 13:18:45 +03:00
|
|
|
// XXX: This should be more fluxy - let's get the error from GroupStore .getError or something
|
2018-12-04 05:38:29 +03:00
|
|
|
GroupStore.on('error', (err, errorGroupId, stateKey) => {
|
2018-05-01 13:18:45 +03:00
|
|
|
if (this._unmounted || groupId !== errorGroupId) return;
|
2017-11-28 14:27:33 +03:00
|
|
|
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN' && !willDoOnboarding) {
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'do_after_sync_prepared',
|
|
|
|
deferred_action: {
|
|
|
|
action: 'view_group',
|
|
|
|
group_id: groupId,
|
|
|
|
},
|
|
|
|
});
|
2020-02-28 13:47:23 +03:00
|
|
|
dis.dispatch({action: 'require_registration', screen_after: {screen: `group/${groupId}`}});
|
2017-11-28 14:27:33 +03:00
|
|
|
willDoOnboarding = true;
|
|
|
|
}
|
2018-12-04 05:38:29 +03:00
|
|
|
if (stateKey === GroupStore.STATE_KEY.Summary) {
|
|
|
|
this.setState({
|
|
|
|
summary: null,
|
|
|
|
error: err,
|
|
|
|
editing: false,
|
|
|
|
});
|
|
|
|
}
|
2017-06-05 18:51:50 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-05-01 13:18:45 +03:00
|
|
|
onGroupStoreUpdated(firstInit) {
|
|
|
|
if (this._unmounted) return;
|
|
|
|
const summary = GroupStore.getSummary(this.props.groupId);
|
|
|
|
if (summary.profile) {
|
|
|
|
// Default profile fields should be "" for later sending to the server (which
|
|
|
|
// requires that the fields are strings, not null)
|
|
|
|
["avatar_url", "long_description", "name", "short_description"].forEach((k) => {
|
|
|
|
summary.profile[k] = summary.profile[k] || "";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.setState({
|
|
|
|
summary,
|
|
|
|
summaryLoading: !GroupStore.isStateReady(this.props.groupId, GroupStore.STATE_KEY.Summary),
|
|
|
|
isGroupPublicised: GroupStore.getGroupPublicity(this.props.groupId),
|
|
|
|
isUserPrivileged: GroupStore.isUserPrivileged(this.props.groupId),
|
|
|
|
groupRooms: GroupStore.getGroupRooms(this.props.groupId),
|
|
|
|
groupRoomsLoading: !GroupStore.isStateReady(this.props.groupId, GroupStore.STATE_KEY.GroupRooms),
|
|
|
|
isUserMember: GroupStore.getGroupMembers(this.props.groupId).some(
|
|
|
|
(m) => m.userId === this._matrixClient.credentials.userId,
|
|
|
|
),
|
|
|
|
});
|
|
|
|
// XXX: This might not work but this.props.groupIsNew unused anyway
|
|
|
|
if (this.props.groupIsNew && firstInit) {
|
|
|
|
this._onEditClick();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2017-11-07 19:42:43 +03:00
|
|
|
_fetchInviterProfile(userId) {
|
|
|
|
this.setState({
|
|
|
|
inviterProfileBusy: true,
|
|
|
|
});
|
2017-11-10 13:49:14 +03:00
|
|
|
this._matrixClient.getProfileInfo(userId).then((resp) => {
|
2018-05-01 13:18:45 +03:00
|
|
|
if (this._unmounted) return;
|
2017-11-07 19:42:43 +03:00
|
|
|
this.setState({
|
|
|
|
inviterProfile: {
|
|
|
|
avatarUrl: resp.avatar_url,
|
|
|
|
displayName: resp.displayname,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}).catch((e) => {
|
|
|
|
console.error('Error getting group inviter profile', e);
|
|
|
|
}).finally(() => {
|
2018-05-01 13:18:45 +03:00
|
|
|
if (this._unmounted) return;
|
2017-11-07 19:42:43 +03:00
|
|
|
this.setState({
|
|
|
|
inviterProfileBusy: false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-17 19:17:18 +03:00
|
|
|
_onEditClick: function() {
|
2017-07-13 20:41:51 +03:00
|
|
|
this.setState({
|
|
|
|
editing: true,
|
|
|
|
profileForm: Object.assign({}, this.state.summary.profile),
|
2018-03-29 18:57:07 +03:00
|
|
|
joinableForm: {
|
2018-04-06 16:58:10 +03:00
|
|
|
policyType:
|
|
|
|
this.state.summary.profile.is_openly_joinable ?
|
|
|
|
GROUP_JOINPOLICY_OPEN :
|
|
|
|
GROUP_JOINPOLICY_INVITE,
|
2018-03-29 18:57:07 +03:00
|
|
|
},
|
2017-07-13 20:41:51 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-06-12 13:15:00 +03:00
|
|
|
_onShareClick: function() {
|
|
|
|
const ShareDialog = sdk.getComponent("dialogs.ShareDialog");
|
|
|
|
Modal.createTrackedDialog('share community dialog', '', ShareDialog, {
|
2019-02-24 06:25:02 +03:00
|
|
|
target: this._matrixClient.getGroup(this.props.groupId) || new Group(this.props.groupId),
|
2018-06-12 13:15:00 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-13 20:41:51 +03:00
|
|
|
_onCancelClick: function() {
|
2018-04-10 15:28:42 +03:00
|
|
|
this._closeSettings();
|
|
|
|
},
|
|
|
|
|
2018-05-29 15:16:39 +03:00
|
|
|
_onAction(payload) {
|
|
|
|
switch (payload.action) {
|
|
|
|
// NOTE: close_settings is an app-wide dispatch; as it is dispatched from MatrixChat
|
|
|
|
case 'close_settings':
|
|
|
|
this.setState({
|
|
|
|
editing: false,
|
|
|
|
profileForm: null,
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-10 15:28:42 +03:00
|
|
|
_closeSettings() {
|
2018-05-29 15:16:39 +03:00
|
|
|
dis.dispatch({action: 'close_settings'});
|
2017-07-13 20:41:51 +03:00
|
|
|
},
|
|
|
|
|
2017-10-18 19:32:46 +03:00
|
|
|
_onNameChange: function(value) {
|
|
|
|
const newProfileForm = Object.assign(this.state.profileForm, { name: value });
|
2017-07-17 16:40:38 +03:00
|
|
|
this.setState({
|
|
|
|
profileForm: newProfileForm,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-18 19:32:46 +03:00
|
|
|
_onShortDescChange: function(value) {
|
|
|
|
const newProfileForm = Object.assign(this.state.profileForm, { short_description: value });
|
2017-07-17 16:40:38 +03:00
|
|
|
this.setState({
|
|
|
|
profileForm: newProfileForm,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_onLongDescChange: function(e) {
|
|
|
|
const newProfileForm = Object.assign(this.state.profileForm, { long_description: e.target.value });
|
|
|
|
this.setState({
|
|
|
|
profileForm: newProfileForm,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-21 16:03:10 +03:00
|
|
|
_onAvatarSelected: function(ev) {
|
|
|
|
const file = ev.target.files[0];
|
|
|
|
if (!file) return;
|
2017-07-21 13:12:15 +03:00
|
|
|
|
2017-07-21 16:03:10 +03:00
|
|
|
this.setState({uploadingAvatar: true});
|
2017-11-10 13:49:14 +03:00
|
|
|
this._matrixClient.uploadContent(file).then((url) => {
|
2017-07-21 16:03:10 +03:00
|
|
|
const newProfileForm = Object.assign(this.state.profileForm, { avatar_url: url });
|
|
|
|
this.setState({
|
|
|
|
uploadingAvatar: false,
|
|
|
|
profileForm: newProfileForm,
|
2018-03-01 17:40:03 +03:00
|
|
|
|
|
|
|
// Indicate that FlairStore needs to be poked to show this change
|
|
|
|
// in TagTile (TagPanel), Flair and GroupTile (MyGroups).
|
|
|
|
avatarChanged: true,
|
2017-07-21 16:03:10 +03:00
|
|
|
});
|
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({uploadingAvatar: false});
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
console.error("Failed to upload avatar image", e);
|
2017-08-10 17:17:52 +03:00
|
|
|
Modal.createTrackedDialog('Failed to upload image', '', ErrorDialog, {
|
2017-07-21 16:03:10 +03:00
|
|
|
title: _t('Error'),
|
|
|
|
description: _t('Failed to upload image'),
|
|
|
|
});
|
2019-11-18 13:03:05 +03:00
|
|
|
});
|
2017-07-21 13:12:15 +03:00
|
|
|
},
|
|
|
|
|
2018-03-29 18:57:07 +03:00
|
|
|
_onJoinableChange: function(ev) {
|
|
|
|
this.setState({
|
2018-04-05 18:56:35 +03:00
|
|
|
joinableForm: { policyType: ev.target.value },
|
2018-03-29 18:57:07 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-07-13 20:41:51 +03:00
|
|
|
_onSaveClick: function() {
|
2017-07-21 13:12:15 +03:00
|
|
|
this.setState({saving: true});
|
2018-03-29 18:57:07 +03:00
|
|
|
const savePromise = this.state.isUserPrivileged ? this._saveGroup() : Promise.resolve();
|
2017-10-24 17:25:35 +03:00
|
|
|
savePromise.then((result) => {
|
2017-07-21 13:12:15 +03:00
|
|
|
this.setState({
|
|
|
|
saving: false,
|
|
|
|
editing: false,
|
2017-07-21 16:18:28 +03:00
|
|
|
summary: null,
|
2017-07-21 13:12:15 +03:00
|
|
|
});
|
2017-10-25 13:09:48 +03:00
|
|
|
dis.dispatch({action: 'panel_disable'});
|
2017-10-04 18:56:35 +03:00
|
|
|
this._initGroupStore(this.props.groupId);
|
2018-03-01 17:40:03 +03:00
|
|
|
|
|
|
|
if (this.state.avatarChanged) {
|
|
|
|
// XXX: Evil - poking a store should be done from an async action
|
|
|
|
FlairStore.refreshGroupProfile(this._matrixClient, this.props.groupId);
|
|
|
|
}
|
2017-07-21 13:12:15 +03:00
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({
|
|
|
|
saving: false,
|
|
|
|
});
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2017-10-16 15:18:39 +03:00
|
|
|
console.error("Failed to save community profile", e);
|
2017-08-10 17:17:52 +03:00
|
|
|
Modal.createTrackedDialog('Failed to update group', '', ErrorDialog, {
|
2017-07-21 13:12:15 +03:00
|
|
|
title: _t('Error'),
|
2017-10-16 15:18:39 +03:00
|
|
|
description: _t('Failed to update community'),
|
2017-07-21 13:12:15 +03:00
|
|
|
});
|
2018-03-01 17:40:03 +03:00
|
|
|
}).finally(() => {
|
|
|
|
this.setState({
|
|
|
|
avatarChanged: false,
|
|
|
|
});
|
2019-11-18 13:03:05 +03:00
|
|
|
});
|
2017-07-06 21:13:14 +03:00
|
|
|
},
|
|
|
|
|
2018-03-29 18:57:07 +03:00
|
|
|
_saveGroup: async function() {
|
|
|
|
await this._matrixClient.setGroupProfile(this.props.groupId, this.state.profileForm);
|
2018-04-05 18:56:35 +03:00
|
|
|
await this._matrixClient.setGroupJoinPolicy(this.props.groupId, {
|
|
|
|
type: this.state.joinableForm.policyType,
|
|
|
|
});
|
2018-03-29 18:57:07 +03:00
|
|
|
},
|
|
|
|
|
2018-04-10 17:31:04 +03:00
|
|
|
_onAcceptInviteClick: async function() {
|
2017-08-21 21:18:32 +03:00
|
|
|
this.setState({membershipBusy: true});
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-04-10 17:56:57 +03:00
|
|
|
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
|
|
|
|
// spinner disappearing after we have fetched new group data.
|
2019-11-12 14:46:58 +03:00
|
|
|
await sleep(500);
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.acceptGroupInvite(this.props.groupId).then(() => {
|
2017-08-21 21:18:32 +03:00
|
|
|
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({membershipBusy: false});
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog('Error accepting invite', '', ErrorDialog, {
|
|
|
|
title: _t("Error"),
|
|
|
|
description: _t("Unable to accept invite"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-04-10 17:31:04 +03:00
|
|
|
_onRejectInviteClick: async function() {
|
2017-08-21 21:18:32 +03:00
|
|
|
this.setState({membershipBusy: true});
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-04-10 17:56:57 +03:00
|
|
|
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
|
|
|
|
// spinner disappearing after we have fetched new group data.
|
2019-11-12 14:46:58 +03:00
|
|
|
await sleep(500);
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.leaveGroup(this.props.groupId).then(() => {
|
2017-08-21 21:18:32 +03:00
|
|
|
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({membershipBusy: false});
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog('Error rejecting invite', '', ErrorDialog, {
|
|
|
|
title: _t("Error"),
|
|
|
|
description: _t("Unable to reject invite"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-04-10 17:31:04 +03:00
|
|
|
_onJoinClick: async function() {
|
2018-07-16 00:48:25 +03:00
|
|
|
if (this._matrixClient.isGuest()) {
|
2020-02-28 13:47:23 +03:00
|
|
|
dis.dispatch({action: 'require_registration', screen_after: {screen: `group/${this.props.groupId}`}});
|
2018-07-16 00:48:25 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-29 14:36:59 +03:00
|
|
|
this.setState({membershipBusy: true});
|
2018-04-10 12:03:54 +03:00
|
|
|
|
2018-04-10 17:56:57 +03:00
|
|
|
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
|
|
|
|
// spinner disappearing after we have fetched new group data.
|
2019-11-12 14:46:58 +03:00
|
|
|
await sleep(500);
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.joinGroup(this.props.groupId).then(() => {
|
2018-03-29 14:36:59 +03:00
|
|
|
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({membershipBusy: false});
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
|
|
|
Modal.createTrackedDialog('Error joining room', '', ErrorDialog, {
|
|
|
|
title: _t("Error"),
|
|
|
|
description: _t("Unable to join community"),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-23 20:25:08 +03:00
|
|
|
_leaveGroupWarnings: function() {
|
|
|
|
const warnings = [];
|
|
|
|
|
|
|
|
if (this.state.isUserPrivileged) {
|
|
|
|
warnings.push((
|
|
|
|
<span className="warning">
|
|
|
|
{ " " /* Whitespace, otherwise the sentences get smashed together */ }
|
2018-10-24 01:20:54 +03:00
|
|
|
{ _t("You are an administrator of this community. You will not be " +
|
|
|
|
"able to rejoin without an invite from another administrator.") }
|
2018-10-23 20:25:08 +03:00
|
|
|
</span>
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return warnings;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
2017-08-21 21:18:32 +03:00
|
|
|
_onLeaveClick: function() {
|
|
|
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
2018-10-23 20:25:08 +03:00
|
|
|
const warnings = this._leaveGroupWarnings();
|
|
|
|
|
2017-08-21 21:18:32 +03:00
|
|
|
Modal.createTrackedDialog('Leave Group', '', QuestionDialog, {
|
2017-10-16 15:18:39 +03:00
|
|
|
title: _t("Leave Community"),
|
2018-10-23 20:25:08 +03:00
|
|
|
description: (
|
|
|
|
<span>
|
|
|
|
{ _t("Leave %(groupName)s?", {groupName: this.props.groupId}) }
|
|
|
|
{ warnings }
|
|
|
|
</span>
|
|
|
|
),
|
2017-08-21 21:18:32 +03:00
|
|
|
button: _t("Leave"),
|
2018-10-23 20:25:08 +03:00
|
|
|
danger: this.state.isUserPrivileged,
|
2019-01-09 21:10:35 +03:00
|
|
|
onFinished: async (confirmed) => {
|
2017-08-21 21:18:32 +03:00
|
|
|
if (!confirmed) return;
|
|
|
|
|
|
|
|
this.setState({membershipBusy: true});
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-04-10 17:56:57 +03:00
|
|
|
// Wait 500ms to prevent flashing. Do this before sending a request otherwise we risk the
|
|
|
|
// spinner disappearing after we have fetched new group data.
|
2019-11-12 14:46:58 +03:00
|
|
|
await sleep(500);
|
2018-04-10 17:31:04 +03:00
|
|
|
|
2018-05-01 13:18:45 +03:00
|
|
|
GroupStore.leaveGroup(this.props.groupId).then(() => {
|
2017-08-21 21:18:32 +03:00
|
|
|
// don't reset membershipBusy here: wait for the membership change to come down the sync
|
|
|
|
}).catch((e) => {
|
|
|
|
this.setState({membershipBusy: false});
|
|
|
|
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
2018-03-29 14:36:59 +03:00
|
|
|
Modal.createTrackedDialog('Error leaving community', '', ErrorDialog, {
|
2017-08-21 21:18:32 +03:00
|
|
|
title: _t("Error"),
|
2018-03-29 14:36:59 +03:00
|
|
|
description: _t("Unable to leave community"),
|
2017-08-21 21:18:32 +03:00
|
|
|
});
|
|
|
|
});
|
2017-08-21 21:34:07 +03:00
|
|
|
},
|
2017-08-21 21:18:32 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-13 18:46:33 +03:00
|
|
|
_onAddRoomsClick: function() {
|
|
|
|
showGroupAddRoomDialog(this.props.groupId);
|
|
|
|
},
|
|
|
|
|
2017-10-24 17:25:35 +03:00
|
|
|
_getGroupSection: function() {
|
|
|
|
const groupSettingsSectionClasses = classnames({
|
|
|
|
"mx_GroupView_group": this.state.editing,
|
|
|
|
"mx_GroupView_group_disabled": this.state.editing && !this.state.isUserPrivileged,
|
|
|
|
});
|
|
|
|
|
|
|
|
const header = this.state.editing ? <h2> { _t('Community Settings') } </h2> : <div />;
|
2019-03-05 19:12:02 +03:00
|
|
|
|
2019-03-05 19:42:22 +03:00
|
|
|
const hostingSignupLink = getHostingLink('community-settings');
|
2019-03-05 19:12:02 +03:00
|
|
|
let hostingSignup = null;
|
2019-03-06 13:32:30 +03:00
|
|
|
if (hostingSignupLink && this.state.isUserPrivileged) {
|
2019-03-05 19:12:02 +03:00
|
|
|
hostingSignup = <div className="mx_GroupView_hostingSignup">
|
|
|
|
{_t(
|
|
|
|
"Want more than a community? <a>Get your own server</a>", {},
|
|
|
|
{
|
2020-02-24 01:14:29 +03:00
|
|
|
a: sub => <a href={hostingSignupLink} target="_blank" rel="noreferrer noopener">{sub}</a>,
|
2019-03-05 19:12:02 +03:00
|
|
|
},
|
|
|
|
)}
|
2020-02-24 01:14:29 +03:00
|
|
|
<a href={hostingSignupLink} target="_blank" rel="noreferrer noopener">
|
2019-03-05 19:12:02 +03:00
|
|
|
<img src={require("../../../res/img/external-link.svg")} width="11" height="10" alt='' />
|
|
|
|
</a>
|
2019-03-05 19:20:18 +03:00
|
|
|
</div>;
|
2019-03-05 19:12:02 +03:00
|
|
|
}
|
|
|
|
|
2018-03-14 21:13:39 +03:00
|
|
|
const changeDelayWarning = this.state.editing && this.state.isUserPrivileged ?
|
|
|
|
<div className="mx_GroupView_changeDelayWarning">
|
2018-03-29 16:33:54 +03:00
|
|
|
{ _t(
|
|
|
|
'Changes made to your community <bold1>name</bold1> and <bold2>avatar</bold2> ' +
|
|
|
|
'might not be seen by other users for up to 30 minutes.',
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
'bold1': (sub) => <b> { sub } </b>,
|
|
|
|
'bold2': (sub) => <b> { sub } </b>,
|
|
|
|
},
|
2018-03-14 21:13:39 +03:00
|
|
|
) }
|
|
|
|
</div> : <div />;
|
2017-10-24 17:25:35 +03:00
|
|
|
return <div className={groupSettingsSectionClasses}>
|
|
|
|
{ header }
|
2019-03-05 19:12:02 +03:00
|
|
|
{ hostingSignup }
|
2018-03-14 21:13:39 +03:00
|
|
|
{ changeDelayWarning }
|
2018-03-29 18:57:07 +03:00
|
|
|
{ this._getJoinableNode() }
|
2017-10-24 17:25:35 +03:00
|
|
|
{ this._getLongDescriptionNode() }
|
|
|
|
{ this._getRoomsNode() }
|
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
|
2017-10-13 18:46:33 +03:00
|
|
|
_getRoomsNode: function() {
|
|
|
|
const RoomDetailList = sdk.getComponent('rooms.RoomDetailList');
|
|
|
|
const AccessibleButton = sdk.getComponent('elements.AccessibleButton');
|
|
|
|
const TintableSvg = sdk.getComponent('elements.TintableSvg');
|
2017-10-31 17:21:00 +03:00
|
|
|
const Spinner = sdk.getComponent('elements.Spinner');
|
2019-06-19 13:26:11 +03:00
|
|
|
const TooltipButton = sdk.getComponent('elements.TooltipButton');
|
2017-11-07 17:07:31 +03:00
|
|
|
|
2019-06-19 13:26:11 +03:00
|
|
|
const roomsHelpNode = this.state.editing ? <TooltipButton helpText={
|
2017-11-07 17:07:31 +03:00
|
|
|
_t(
|
|
|
|
'These rooms are displayed to community members on the community page. '+
|
|
|
|
'Community members can join the rooms by clicking on them.',
|
|
|
|
)
|
|
|
|
} /> : <div />;
|
2017-10-24 17:25:35 +03:00
|
|
|
|
|
|
|
const addRoomRow = this.state.editing ?
|
|
|
|
(<AccessibleButton className="mx_GroupView_rooms_header_addRow"
|
|
|
|
onClick={this._onAddRoomsClick}
|
|
|
|
>
|
|
|
|
<div className="mx_GroupView_rooms_header_addRow_button">
|
2019-01-11 04:37:28 +03:00
|
|
|
<TintableSvg src={require("../../../res/img/icons-room-add.svg")} width="24" height="24" />
|
2017-10-13 18:46:33 +03:00
|
|
|
</div>
|
2017-10-24 17:25:35 +03:00
|
|
|
<div className="mx_GroupView_rooms_header_addRow_label">
|
2017-10-16 15:18:39 +03:00
|
|
|
{ _t('Add rooms to this community') }
|
2017-10-13 18:46:33 +03:00
|
|
|
</div>
|
|
|
|
</AccessibleButton>) : <div />;
|
2017-11-07 19:54:28 +03:00
|
|
|
const roomDetailListClassName = classnames({
|
|
|
|
"mx_fadable": true,
|
|
|
|
"mx_fadable_faded": this.state.editing,
|
|
|
|
});
|
2017-10-13 18:46:33 +03:00
|
|
|
return <div className="mx_GroupView_rooms">
|
|
|
|
<div className="mx_GroupView_rooms_header">
|
2017-11-07 17:07:31 +03:00
|
|
|
<h3>
|
|
|
|
{ _t('Rooms') }
|
|
|
|
{ roomsHelpNode }
|
|
|
|
</h3>
|
2017-10-24 17:25:35 +03:00
|
|
|
{ addRoomRow }
|
2017-10-13 18:46:33 +03:00
|
|
|
</div>
|
2017-10-31 17:21:00 +03:00
|
|
|
{ this.state.groupRoomsLoading ?
|
|
|
|
<Spinner /> :
|
2017-11-07 19:54:28 +03:00
|
|
|
<RoomDetailList
|
|
|
|
rooms={this.state.groupRooms}
|
|
|
|
className={roomDetailListClassName} />
|
2017-10-31 17:21:00 +03:00
|
|
|
}
|
2017-10-13 18:46:33 +03:00
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
|
2017-09-22 21:27:02 +03:00
|
|
|
_getFeaturedRoomsNode: function() {
|
2017-07-10 21:32:02 +03:00
|
|
|
const summary = this.state.summary;
|
|
|
|
|
|
|
|
const defaultCategoryRooms = [];
|
|
|
|
const categoryRooms = {};
|
|
|
|
summary.rooms_section.rooms.forEach((r) => {
|
|
|
|
if (r.category_id === null) {
|
|
|
|
defaultCategoryRooms.push(r);
|
|
|
|
} else {
|
|
|
|
let list = categoryRooms[r.category_id];
|
|
|
|
if (list === undefined) {
|
|
|
|
list = [];
|
|
|
|
categoryRooms[r.category_id] = list;
|
|
|
|
}
|
|
|
|
list.push(r);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-21 14:44:17 +03:00
|
|
|
const defaultCategoryNode = <CategoryRoomList
|
|
|
|
rooms={defaultCategoryRooms}
|
2017-09-21 18:53:10 +03:00
|
|
|
groupId={this.props.groupId}
|
2017-09-28 13:21:06 +03:00
|
|
|
editing={this.state.editing} />;
|
2017-07-10 21:32:02 +03:00
|
|
|
const categoryRoomNodes = Object.keys(categoryRooms).map((catId) => {
|
|
|
|
const cat = summary.rooms_section.categories[catId];
|
2017-09-21 14:44:17 +03:00
|
|
|
return <CategoryRoomList
|
|
|
|
key={catId}
|
|
|
|
rooms={categoryRooms[catId]}
|
|
|
|
category={cat}
|
2017-09-21 18:53:10 +03:00
|
|
|
groupId={this.props.groupId}
|
2017-09-28 13:21:06 +03:00
|
|
|
editing={this.state.editing} />;
|
2017-07-10 21:32:02 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return <div className="mx_GroupView_featuredThings">
|
|
|
|
<div className="mx_GroupView_featuredThings_header">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ _t('Featured Rooms:') }
|
2017-07-10 21:32:02 +03:00
|
|
|
</div>
|
2017-09-28 13:21:06 +03:00
|
|
|
{ defaultCategoryNode }
|
|
|
|
{ categoryRoomNodes }
|
2017-07-10 21:32:02 +03:00
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
|
2017-09-22 21:27:02 +03:00
|
|
|
_getFeaturedUsersNode: function() {
|
2017-07-10 21:32:02 +03:00
|
|
|
const summary = this.state.summary;
|
|
|
|
|
|
|
|
const noRoleUsers = [];
|
|
|
|
const roleUsers = {};
|
|
|
|
summary.users_section.users.forEach((u) => {
|
|
|
|
if (u.role_id === null) {
|
|
|
|
noRoleUsers.push(u);
|
|
|
|
} else {
|
|
|
|
let list = roleUsers[u.role_id];
|
|
|
|
if (list === undefined) {
|
|
|
|
list = [];
|
|
|
|
roleUsers[u.role_id] = list;
|
|
|
|
}
|
|
|
|
list.push(u);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-21 14:44:17 +03:00
|
|
|
const noRoleNode = <RoleUserList
|
|
|
|
users={noRoleUsers}
|
|
|
|
groupId={this.props.groupId}
|
2017-09-28 13:21:06 +03:00
|
|
|
editing={this.state.editing} />;
|
2017-07-10 21:32:02 +03:00
|
|
|
const roleUserNodes = Object.keys(roleUsers).map((roleId) => {
|
|
|
|
const role = summary.users_section.roles[roleId];
|
2017-09-21 14:44:17 +03:00
|
|
|
return <RoleUserList
|
|
|
|
key={roleId}
|
|
|
|
users={roleUsers[roleId]}
|
|
|
|
role={role}
|
|
|
|
groupId={this.props.groupId}
|
2017-09-28 13:21:06 +03:00
|
|
|
editing={this.state.editing} />;
|
2017-07-10 21:32:02 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return <div className="mx_GroupView_featuredThings">
|
|
|
|
<div className="mx_GroupView_featuredThings_header">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ _t('Featured Users:') }
|
2017-07-10 21:32:02 +03:00
|
|
|
</div>
|
2017-09-28 13:21:06 +03:00
|
|
|
{ noRoleNode }
|
|
|
|
{ roleUserNodes }
|
2017-07-10 21:32:02 +03:00
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
|
2017-08-21 21:18:32 +03:00
|
|
|
_getMembershipSection: function() {
|
2017-09-22 21:27:02 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2017-11-07 19:42:43 +03:00
|
|
|
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
2017-09-22 21:27:02 +03:00
|
|
|
|
2017-11-10 13:49:14 +03:00
|
|
|
const group = this._matrixClient.getGroup(this.props.groupId);
|
2017-08-21 21:18:32 +03:00
|
|
|
|
2018-03-29 14:36:59 +03:00
|
|
|
if (group && group.myMembership === 'invite') {
|
2017-11-07 19:42:43 +03:00
|
|
|
if (this.state.membershipBusy || this.state.inviterProfileBusy) {
|
2017-09-21 17:03:30 +03:00
|
|
|
return <div className="mx_GroupView_membershipSection">
|
2017-08-21 21:18:32 +03:00
|
|
|
<Spinner />
|
|
|
|
</div>;
|
|
|
|
}
|
2017-11-07 19:42:43 +03:00
|
|
|
const httpInviterAvatar = this.state.inviterProfile ?
|
2017-11-10 13:49:14 +03:00
|
|
|
this._matrixClient.mxcUrlToHttp(
|
2017-11-07 19:42:43 +03:00
|
|
|
this.state.inviterProfile.avatarUrl, 36, 36,
|
|
|
|
) : null;
|
|
|
|
|
2020-08-17 12:59:43 +03:00
|
|
|
const inviter = group.inviter || {};
|
|
|
|
let inviterName = inviter.userId;
|
2017-11-08 13:08:04 +03:00
|
|
|
if (this.state.inviterProfile) {
|
2020-08-17 12:59:43 +03:00
|
|
|
inviterName = this.state.inviterProfile.displayName || inviter.userId;
|
2017-11-07 19:42:43 +03:00
|
|
|
}
|
2017-09-21 17:03:30 +03:00
|
|
|
return <div className="mx_GroupView_membershipSection mx_GroupView_membershipSection_invited">
|
2017-10-17 13:59:16 +03:00
|
|
|
<div className="mx_GroupView_membershipSubSection">
|
|
|
|
<div className="mx_GroupView_membershipSection_description">
|
2017-11-07 19:42:43 +03:00
|
|
|
<BaseAvatar url={httpInviterAvatar}
|
|
|
|
name={inviterName}
|
|
|
|
width={36}
|
|
|
|
height={36}
|
|
|
|
/>
|
|
|
|
{ _t("%(inviter)s has invited you to join this community", {
|
2020-08-17 12:59:43 +03:00
|
|
|
inviter: inviterName || _t("Someone"),
|
2017-11-07 19:42:43 +03:00
|
|
|
}) }
|
2017-09-22 21:27:02 +03:00
|
|
|
</div>
|
|
|
|
<div className="mx_GroupView_membership_buttonContainer">
|
2017-10-17 13:59:16 +03:00
|
|
|
<AccessibleButton className="mx_GroupView_textButton mx_RoomHeader_textButton"
|
|
|
|
onClick={this._onAcceptInviteClick}
|
|
|
|
>
|
|
|
|
{ _t("Accept") }
|
|
|
|
</AccessibleButton>
|
|
|
|
<AccessibleButton className="mx_GroupView_textButton mx_RoomHeader_textButton"
|
|
|
|
onClick={this._onRejectInviteClick}
|
|
|
|
>
|
|
|
|
{ _t("Decline") }
|
|
|
|
</AccessibleButton>
|
2017-09-22 21:27:02 +03:00
|
|
|
</div>
|
2017-08-21 21:18:32 +03:00
|
|
|
</div>
|
|
|
|
</div>;
|
2018-03-29 14:36:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
let membershipContainerExtraClasses;
|
|
|
|
let membershipButtonExtraClasses;
|
|
|
|
let membershipButtonTooltip;
|
|
|
|
let membershipButtonText;
|
|
|
|
let membershipButtonOnClick;
|
|
|
|
|
|
|
|
// User is not in the group
|
|
|
|
if ((!group || group.myMembership === 'leave') &&
|
|
|
|
this.state.summary &&
|
|
|
|
this.state.summary.profile &&
|
2018-04-09 18:57:27 +03:00
|
|
|
Boolean(this.state.summary.profile.is_openly_joinable)
|
2018-03-29 14:36:59 +03:00
|
|
|
) {
|
|
|
|
membershipButtonText = _t("Join this community");
|
|
|
|
membershipButtonOnClick = this._onJoinClick;
|
|
|
|
|
|
|
|
membershipButtonExtraClasses = 'mx_GroupView_joinButton';
|
|
|
|
membershipContainerExtraClasses = 'mx_GroupView_membershipSection_leave';
|
|
|
|
} else if (
|
|
|
|
group &&
|
|
|
|
group.myMembership === 'join' &&
|
|
|
|
this.state.editing
|
|
|
|
) {
|
|
|
|
membershipButtonText = _t("Leave this community");
|
|
|
|
membershipButtonOnClick = this._onLeaveClick;
|
|
|
|
membershipButtonTooltip = this.state.isUserPrivileged ?
|
2017-10-25 14:09:13 +03:00
|
|
|
_t("You are an administrator of this community") :
|
|
|
|
_t("You are a member of this community");
|
2018-03-29 14:36:59 +03:00
|
|
|
|
|
|
|
membershipButtonExtraClasses = {
|
|
|
|
'mx_GroupView_leaveButton': true,
|
|
|
|
'mx_RoomHeader_textButton_danger': this.state.isUserPrivileged,
|
|
|
|
};
|
|
|
|
membershipContainerExtraClasses = 'mx_GroupView_membershipSection_joined';
|
|
|
|
} else {
|
|
|
|
return null;
|
2017-08-21 21:18:32 +03:00
|
|
|
}
|
2018-03-29 14:36:59 +03:00
|
|
|
|
|
|
|
const membershipButtonClasses = classnames([
|
|
|
|
'mx_RoomHeader_textButton',
|
|
|
|
'mx_GroupView_textButton',
|
|
|
|
],
|
|
|
|
membershipButtonExtraClasses,
|
|
|
|
);
|
|
|
|
|
|
|
|
const membershipContainerClasses = classnames(
|
|
|
|
'mx_GroupView_membershipSection',
|
|
|
|
membershipContainerExtraClasses,
|
|
|
|
);
|
|
|
|
|
|
|
|
return <div className={membershipContainerClasses}>
|
|
|
|
<div className="mx_GroupView_membershipSubSection">
|
2018-04-10 13:49:59 +03:00
|
|
|
{ /* The <div /> is for flex alignment */ }
|
|
|
|
{ this.state.membershipBusy ? <Spinner /> : <div /> }
|
2018-03-29 14:36:59 +03:00
|
|
|
<div className="mx_GroupView_membership_buttonContainer">
|
|
|
|
<AccessibleButton
|
|
|
|
className={membershipButtonClasses}
|
|
|
|
onClick={membershipButtonOnClick}
|
|
|
|
title={membershipButtonTooltip}
|
|
|
|
>
|
|
|
|
{ membershipButtonText }
|
|
|
|
</AccessibleButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>;
|
2017-08-21 21:18:32 +03:00
|
|
|
},
|
|
|
|
|
2018-03-29 18:57:07 +03:00
|
|
|
_getJoinableNode: function() {
|
2018-12-18 04:47:33 +03:00
|
|
|
const InlineSpinner = sdk.getComponent('elements.InlineSpinner');
|
2018-03-29 18:57:07 +03:00
|
|
|
return this.state.editing ? <div>
|
|
|
|
<h3>
|
|
|
|
{ _t('Who can join this community?') }
|
|
|
|
{ this.state.groupJoinableLoading ?
|
|
|
|
<InlineSpinner /> : <div />
|
|
|
|
}
|
|
|
|
</h3>
|
|
|
|
<div>
|
|
|
|
<label>
|
|
|
|
<input type="radio"
|
2018-04-05 18:56:35 +03:00
|
|
|
value={GROUP_JOINPOLICY_INVITE}
|
|
|
|
checked={this.state.joinableForm.policyType === GROUP_JOINPOLICY_INVITE}
|
2018-06-15 21:01:12 +03:00
|
|
|
onChange={this._onJoinableChange}
|
2018-03-29 18:57:07 +03:00
|
|
|
/>
|
|
|
|
<div className="mx_GroupView_label_text">
|
|
|
|
{ _t('Only people who have been invited') }
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label>
|
|
|
|
<input type="radio"
|
2018-04-05 18:56:35 +03:00
|
|
|
value={GROUP_JOINPOLICY_OPEN}
|
|
|
|
checked={this.state.joinableForm.policyType === GROUP_JOINPOLICY_OPEN}
|
2018-06-15 21:01:12 +03:00
|
|
|
onChange={this._onJoinableChange}
|
2018-03-29 18:57:07 +03:00
|
|
|
/>
|
|
|
|
<div className="mx_GroupView_label_text">
|
|
|
|
{ _t('Everyone') }
|
|
|
|
</div>
|
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div> : null;
|
|
|
|
},
|
|
|
|
|
2017-10-17 18:10:34 +03:00
|
|
|
_getLongDescriptionNode: function() {
|
|
|
|
const summary = this.state.summary;
|
|
|
|
let description = null;
|
|
|
|
if (summary.profile && summary.profile.long_description) {
|
|
|
|
description = sanitizedHtmlNode(summary.profile.long_description);
|
2017-11-06 21:35:52 +03:00
|
|
|
} else if (this.state.isUserPrivileged) {
|
|
|
|
description = <div
|
|
|
|
className="mx_GroupView_groupDesc_placeholder"
|
|
|
|
onClick={this._onEditClick}
|
|
|
|
>
|
2017-11-13 22:19:33 +03:00
|
|
|
{ _t(
|
2017-11-06 21:35:52 +03:00
|
|
|
'Your community hasn\'t got a Long Description, a HTML page to show to community members.<br />' +
|
|
|
|
'Click here to open settings and give it one!',
|
2017-11-13 22:19:33 +03:00
|
|
|
{},
|
2017-11-14 22:09:52 +03:00
|
|
|
{ 'br': <br /> },
|
2017-11-13 22:19:33 +03:00
|
|
|
) }
|
2017-11-06 21:35:52 +03:00
|
|
|
</div>;
|
2017-10-17 18:10:34 +03:00
|
|
|
}
|
2017-10-24 17:25:35 +03:00
|
|
|
const groupDescEditingClasses = classnames({
|
|
|
|
"mx_GroupView_groupDesc": true,
|
|
|
|
"mx_GroupView_groupDesc_disabled": !this.state.isUserPrivileged,
|
|
|
|
});
|
|
|
|
|
|
|
|
return this.state.editing ?
|
|
|
|
<div className={groupDescEditingClasses}>
|
2017-10-17 18:10:34 +03:00
|
|
|
<h3> { _t("Long Description (HTML)") } </h3>
|
|
|
|
<textarea
|
|
|
|
value={this.state.profileForm.long_description}
|
2017-11-06 21:52:55 +03:00
|
|
|
placeholder={_t(LONG_DESC_PLACEHOLDER)}
|
2017-10-17 18:10:34 +03:00
|
|
|
onChange={this._onLongDescChange}
|
|
|
|
tabIndex="4"
|
|
|
|
key="editLongDesc"
|
|
|
|
/>
|
|
|
|
</div> :
|
|
|
|
<div className="mx_GroupView_groupDesc">
|
|
|
|
{ description }
|
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
|
2017-06-05 18:51:50 +03:00
|
|
|
render: function() {
|
2017-06-29 19:51:38 +03:00
|
|
|
const GroupAvatar = sdk.getComponent("avatars.GroupAvatar");
|
2017-10-17 18:10:34 +03:00
|
|
|
const Spinner = sdk.getComponent("elements.Spinner");
|
2017-06-05 18:51:50 +03:00
|
|
|
|
2017-10-31 14:42:09 +03:00
|
|
|
if (this.state.summaryLoading && this.state.error === null || this.state.saving) {
|
2017-10-17 18:10:34 +03:00
|
|
|
return <Spinner />;
|
2018-12-04 05:38:29 +03:00
|
|
|
} else if (this.state.summary && !this.state.error) {
|
2017-07-13 20:41:51 +03:00
|
|
|
const summary = this.state.summary;
|
2017-07-06 21:13:14 +03:00
|
|
|
|
2017-07-13 20:41:51 +03:00
|
|
|
let avatarNode;
|
2017-06-29 19:17:43 +03:00
|
|
|
let nameNode;
|
2017-07-13 20:41:51 +03:00
|
|
|
let shortDescNode;
|
2017-08-21 21:34:07 +03:00
|
|
|
const rightButtons = [];
|
2017-10-24 17:25:35 +03:00
|
|
|
if (this.state.editing && this.state.isUserPrivileged) {
|
2017-07-21 16:03:10 +03:00
|
|
|
let avatarImage;
|
|
|
|
if (this.state.uploadingAvatar) {
|
2017-10-17 18:10:34 +03:00
|
|
|
avatarImage = <Spinner />;
|
2017-07-21 16:03:10 +03:00
|
|
|
} else {
|
|
|
|
const GroupAvatar = sdk.getComponent('avatars.GroupAvatar');
|
|
|
|
avatarImage = <GroupAvatar groupId={this.props.groupId}
|
2017-10-30 18:04:12 +03:00
|
|
|
groupName={this.state.profileForm.name}
|
2017-07-21 16:03:10 +03:00
|
|
|
groupAvatarUrl={this.state.profileForm.avatar_url}
|
2019-01-30 18:24:02 +03:00
|
|
|
width={28} height={28} resizeMethod='crop'
|
2017-07-21 16:03:10 +03:00
|
|
|
/>;
|
|
|
|
}
|
|
|
|
|
2017-07-13 20:41:51 +03:00
|
|
|
avatarNode = (
|
|
|
|
<div className="mx_GroupView_avatarPicker">
|
2017-07-21 13:12:15 +03:00
|
|
|
<label htmlFor="avatarInput" className="mx_GroupView_avatarPicker_label">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ avatarImage }
|
2017-07-21 13:12:15 +03:00
|
|
|
</label>
|
2017-07-13 20:41:51 +03:00
|
|
|
<div className="mx_GroupView_avatarPicker_edit">
|
2017-07-21 13:12:15 +03:00
|
|
|
<label htmlFor="avatarInput" className="mx_GroupView_avatarPicker_label">
|
2019-01-11 04:37:28 +03:00
|
|
|
<img src={require("../../../res/img/camera.svg")}
|
2017-09-28 13:21:06 +03:00
|
|
|
alt={_t("Upload avatar")} title={_t("Upload avatar")}
|
2017-07-13 20:41:51 +03:00
|
|
|
width="17" height="15" />
|
|
|
|
</label>
|
2017-09-28 13:21:06 +03:00
|
|
|
<input id="avatarInput" className="mx_GroupView_uploadInput" type="file" onChange={this._onAvatarSelected} />
|
2017-07-13 20:41:51 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
2017-10-19 14:03:59 +03:00
|
|
|
|
2017-10-18 19:32:46 +03:00
|
|
|
const EditableText = sdk.getComponent("elements.EditableText");
|
|
|
|
|
2019-12-08 15:12:06 +03:00
|
|
|
nameNode = <EditableText
|
|
|
|
className="mx_GroupView_editable"
|
|
|
|
placeholderClassName="mx_GroupView_placeholder"
|
|
|
|
placeholder={_t('Community Name')}
|
|
|
|
blurToCancel={false}
|
|
|
|
initialValue={this.state.profileForm.name}
|
|
|
|
onValueChanged={this._onNameChange}
|
|
|
|
tabIndex="0"
|
|
|
|
dir="auto" />;
|
|
|
|
|
|
|
|
shortDescNode = <EditableText
|
|
|
|
className="mx_GroupView_editable"
|
|
|
|
placeholderClassName="mx_GroupView_placeholder"
|
|
|
|
placeholder={_t("Description")}
|
|
|
|
blurToCancel={false}
|
|
|
|
initialValue={this.state.profileForm.short_description}
|
|
|
|
onValueChanged={this._onShortDescChange}
|
|
|
|
tabIndex="0"
|
|
|
|
dir="auto" />;
|
2017-06-29 19:17:43 +03:00
|
|
|
} else {
|
2017-10-31 13:54:44 +03:00
|
|
|
const onGroupHeaderItemClick = this.state.isUserMember ? this._onEditClick : null;
|
2017-07-13 20:41:51 +03:00
|
|
|
const groupAvatarUrl = summary.profile ? summary.profile.avatar_url : null;
|
2017-10-30 18:04:12 +03:00
|
|
|
const groupName = summary.profile ? summary.profile.name : null;
|
2017-07-13 20:41:51 +03:00
|
|
|
avatarNode = <GroupAvatar
|
|
|
|
groupId={this.props.groupId}
|
|
|
|
groupAvatarUrl={groupAvatarUrl}
|
2017-10-30 18:04:12 +03:00
|
|
|
groupName={groupName}
|
2017-10-31 13:54:44 +03:00
|
|
|
onClick={onGroupHeaderItemClick}
|
2019-01-30 18:24:02 +03:00
|
|
|
width={28} height={28}
|
2017-07-13 20:41:51 +03:00
|
|
|
/>;
|
|
|
|
if (summary.profile && summary.profile.name) {
|
2017-10-31 13:54:44 +03:00
|
|
|
nameNode = <div onClick={onGroupHeaderItemClick}>
|
2017-09-28 13:21:06 +03:00
|
|
|
<span>{ summary.profile.name }</span>
|
2017-07-13 20:41:51 +03:00
|
|
|
<span className="mx_GroupView_header_groupid">
|
2017-09-28 13:21:06 +03:00
|
|
|
({ this.props.groupId })
|
2017-07-13 20:41:51 +03:00
|
|
|
</span>
|
|
|
|
</div>;
|
|
|
|
} else {
|
2017-10-31 13:54:44 +03:00
|
|
|
nameNode = <span onClick={onGroupHeaderItemClick}>{ this.props.groupId }</span>;
|
2017-07-13 20:41:51 +03:00
|
|
|
}
|
2017-10-13 18:46:33 +03:00
|
|
|
if (summary.profile && summary.profile.short_description) {
|
2017-10-31 13:54:44 +03:00
|
|
|
shortDescNode = <span onClick={onGroupHeaderItemClick}>{ summary.profile.short_description }</span>;
|
2017-10-13 18:46:33 +03:00
|
|
|
}
|
2017-10-24 17:25:35 +03:00
|
|
|
}
|
2018-06-12 13:15:00 +03:00
|
|
|
|
2017-10-24 17:25:35 +03:00
|
|
|
if (this.state.editing) {
|
|
|
|
rightButtons.push(
|
|
|
|
<AccessibleButton className="mx_GroupView_textButton mx_RoomHeader_textButton"
|
2019-02-12 20:48:27 +03:00
|
|
|
key="_saveButton"
|
|
|
|
onClick={this._onSaveClick}
|
2017-10-24 17:25:35 +03:00
|
|
|
>
|
|
|
|
{ _t('Save') }
|
|
|
|
</AccessibleButton>,
|
|
|
|
);
|
|
|
|
rightButtons.push(
|
2019-02-12 20:48:27 +03:00
|
|
|
<AccessibleButton className="mx_RoomHeader_cancelButton"
|
|
|
|
key="_cancelButton"
|
|
|
|
onClick={this._onCancelClick}
|
|
|
|
>
|
2019-01-11 04:37:28 +03:00
|
|
|
<img src={require("../../../res/img/cancel.svg")} className="mx_filterFlipColor"
|
2017-10-24 17:25:35 +03:00
|
|
|
width="18" height="18" alt={_t("Cancel")} />
|
|
|
|
</AccessibleButton>,
|
|
|
|
);
|
|
|
|
} else {
|
2017-10-26 16:31:27 +03:00
|
|
|
if (summary.user && summary.user.membership === 'join') {
|
|
|
|
rightButtons.push(
|
2019-02-12 20:48:27 +03:00
|
|
|
<AccessibleButton className="mx_GroupHeader_button mx_GroupHeader_editButton"
|
|
|
|
key="_editButton"
|
|
|
|
onClick={this._onEditClick}
|
|
|
|
title={_t("Community Settings")}
|
2017-10-26 16:31:27 +03:00
|
|
|
>
|
|
|
|
</AccessibleButton>,
|
|
|
|
);
|
|
|
|
}
|
2018-06-12 13:15:00 +03:00
|
|
|
rightButtons.push(
|
2019-02-12 20:48:27 +03:00
|
|
|
<AccessibleButton className="mx_GroupHeader_button mx_GroupHeader_shareButton"
|
|
|
|
key="_shareButton"
|
|
|
|
onClick={this._onShareClick}
|
|
|
|
title={_t('Share Community')}
|
|
|
|
>
|
2018-06-12 13:15:00 +03:00
|
|
|
</AccessibleButton>,
|
|
|
|
);
|
2017-07-13 20:41:51 +03:00
|
|
|
}
|
2017-07-07 20:34:40 +03:00
|
|
|
|
2020-03-20 03:18:24 +03:00
|
|
|
const rightPanel = this.state.showRightPanel ? <RightPanel groupId={this.props.groupId} /> : undefined;
|
2018-10-31 14:09:24 +03:00
|
|
|
|
2017-10-24 17:25:35 +03:00
|
|
|
const headerClasses = {
|
2018-11-05 14:15:03 +03:00
|
|
|
"mx_GroupView_header": true,
|
|
|
|
"light-panel": true,
|
|
|
|
"mx_GroupView_header_view": !this.state.editing,
|
|
|
|
"mx_GroupView_header_isUserMember": this.state.isUserMember,
|
2017-10-24 17:25:35 +03:00
|
|
|
};
|
|
|
|
|
2017-06-05 18:51:50 +03:00
|
|
|
return (
|
2018-11-02 17:05:55 +03:00
|
|
|
<main className="mx_GroupView">
|
2017-07-21 16:13:57 +03:00
|
|
|
<div className={classnames(headerClasses)}>
|
2017-07-13 20:41:51 +03:00
|
|
|
<div className="mx_GroupView_header_leftCol">
|
|
|
|
<div className="mx_GroupView_header_avatar">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ avatarNode }
|
2017-06-05 18:51:50 +03:00
|
|
|
</div>
|
2017-07-13 20:41:51 +03:00
|
|
|
<div className="mx_GroupView_header_info">
|
|
|
|
<div className="mx_GroupView_header_name">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ nameNode }
|
2017-07-13 20:41:51 +03:00
|
|
|
</div>
|
|
|
|
<div className="mx_GroupView_header_shortDesc">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ shortDescNode }
|
2017-06-05 18:51:50 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
2017-07-13 20:41:51 +03:00
|
|
|
</div>
|
|
|
|
<div className="mx_GroupView_header_rightCol">
|
2017-09-28 13:21:06 +03:00
|
|
|
{ rightButtons }
|
2017-06-05 18:51:50 +03:00
|
|
|
</div>
|
2019-12-06 03:47:18 +03:00
|
|
|
<GroupHeaderButtons />
|
2017-06-05 18:51:50 +03:00
|
|
|
</div>
|
2019-12-06 03:47:18 +03:00
|
|
|
<MainSplit panel={rightPanel}>
|
2020-03-17 13:09:47 +03:00
|
|
|
<AutoHideScrollbar className="mx_GroupView_body">
|
2018-10-31 14:09:24 +03:00
|
|
|
{ this._getMembershipSection() }
|
|
|
|
{ this._getGroupSection() }
|
2020-03-17 13:09:47 +03:00
|
|
|
</AutoHideScrollbar>
|
2018-10-31 14:09:24 +03:00
|
|
|
</MainSplit>
|
2018-11-02 17:05:55 +03:00
|
|
|
</main>
|
2017-06-05 18:51:50 +03:00
|
|
|
);
|
2017-06-27 12:28:46 +03:00
|
|
|
} else if (this.state.error) {
|
|
|
|
if (this.state.error.httpStatus === 404) {
|
|
|
|
return (
|
2017-06-27 13:52:23 +03:00
|
|
|
<div className="mx_GroupView_error">
|
2017-10-19 14:03:59 +03:00
|
|
|
{ _t('Community %(groupId)s not found', {groupId: this.props.groupId}) }
|
2017-06-27 12:28:46 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
let extraText;
|
|
|
|
if (this.state.error.errcode === 'M_UNRECOGNIZED') {
|
2019-02-01 03:52:39 +03:00
|
|
|
extraText = <div>{ _t('This homeserver does not support communities') }</div>;
|
2017-06-27 12:28:46 +03:00
|
|
|
}
|
|
|
|
return (
|
2017-06-27 13:52:23 +03:00
|
|
|
<div className="mx_GroupView_error">
|
2017-10-19 20:06:32 +03:00
|
|
|
{ _t('Failed to load %(groupId)s', {groupId: this.props.groupId }) }
|
2017-09-28 13:21:06 +03:00
|
|
|
{ extraText }
|
2017-06-27 12:28:46 +03:00
|
|
|
</div>
|
|
|
|
);
|
2017-06-26 19:47:17 +03:00
|
|
|
}
|
2017-06-27 15:41:43 +03:00
|
|
|
} else {
|
|
|
|
console.error("Invalid state for GroupView");
|
|
|
|
return <div />;
|
2017-06-05 18:51:50 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|