2017-06-29 16:03:05 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
2019-08-05 11:26:31 +00:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
2017-06-29 16:03:05 +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 React from 'react';
|
2019-08-30 09:34:59 +00:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-12-26 01:03:18 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2019-08-06 13:04:33 +00:00
|
|
|
import { MatrixClient } from 'matrix-js-sdk';
|
2017-06-29 16:03:05 +00:00
|
|
|
import sdk from '../../index';
|
2017-11-13 19:19:33 +00:00
|
|
|
import { _t } from '../../languageHandler';
|
2017-11-28 12:08:53 +00:00
|
|
|
import dis from '../../dispatcher';
|
2017-06-29 16:03:05 +00:00
|
|
|
import AccessibleButton from '../views/elements/AccessibleButton';
|
|
|
|
|
2019-08-30 09:34:59 +00:00
|
|
|
export default createReactClass({
|
2017-06-30 12:59:49 +00:00
|
|
|
displayName: 'MyGroups',
|
2017-06-29 16:03:05 +00:00
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
groups: null,
|
|
|
|
error: null,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2019-08-05 11:26:31 +00:00
|
|
|
contextTypes: {
|
2019-08-06 13:04:33 +00:00
|
|
|
matrixClient: PropTypes.instanceOf(MatrixClient).isRequired,
|
2019-08-05 11:26:31 +00:00
|
|
|
},
|
|
|
|
|
2017-06-29 16:03:05 +00:00
|
|
|
componentWillMount: function() {
|
|
|
|
this._fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
_onCreateGroupClick: function() {
|
2017-11-28 12:08:53 +00:00
|
|
|
dis.dispatch({action: 'view_create_group'});
|
2017-06-29 16:03:05 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_fetch: function() {
|
2019-11-18 10:03:05 +00:00
|
|
|
this.context.matrixClient.getJoinedGroups().then((result) => {
|
2017-06-29 16:03:05 +00:00
|
|
|
this.setState({groups: result.groups, error: null});
|
|
|
|
}, (err) => {
|
2017-11-28 12:08:53 +00:00
|
|
|
if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN') {
|
|
|
|
// Indicate that the guest isn't in any groups (which should be true)
|
|
|
|
this.setState({groups: [], error: null});
|
|
|
|
return;
|
|
|
|
}
|
2017-07-07 17:34:40 +00:00
|
|
|
this.setState({groups: null, error: err});
|
2017-06-29 16:03:05 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
|
|
|
const SimpleRoomHeader = sdk.getComponent('rooms.SimpleRoomHeader');
|
2017-11-21 11:50:41 +00:00
|
|
|
const GroupTile = sdk.getComponent("groups.GroupTile");
|
2018-03-21 12:00:56 +00:00
|
|
|
const GeminiScrollbarWrapper = sdk.getComponent("elements.GeminiScrollbarWrapper");
|
|
|
|
|
2017-06-29 16:03:05 +00:00
|
|
|
|
|
|
|
let content;
|
2017-11-03 11:19:29 +00:00
|
|
|
let contentHeader;
|
2017-06-29 16:03:05 +00:00
|
|
|
if (this.state.groups) {
|
2017-07-07 09:41:59 +00:00
|
|
|
const groupNodes = [];
|
2017-06-29 16:03:05 +00:00
|
|
|
this.state.groups.forEach((g) => {
|
2018-06-15 17:55:37 +00:00
|
|
|
groupNodes.push(<GroupTile key={g} groupId={g} />);
|
2017-06-29 16:03:05 +00:00
|
|
|
});
|
2017-11-03 11:19:29 +00:00
|
|
|
contentHeader = groupNodes.length > 0 ? <h3>{ _t('Your Communities') }</h3> : <div />;
|
2017-10-20 16:28:33 +00:00
|
|
|
content = groupNodes.length > 0 ?
|
2018-03-21 12:00:56 +00:00
|
|
|
<GeminiScrollbarWrapper>
|
2018-02-27 09:20:06 +00:00
|
|
|
<div className="mx_MyGroups_microcopy">
|
|
|
|
<p>
|
|
|
|
{ _t(
|
|
|
|
"Did you know: you can use communities to filter your Riot.im experience!",
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{ _t(
|
|
|
|
"To set up a filter, drag a community avatar over to the filter panel on " +
|
|
|
|
"the far left hand side of the screen. You can click on an avatar in the " +
|
|
|
|
"filter panel at any time to see only the rooms and people associated " +
|
|
|
|
"with that community.",
|
|
|
|
) }
|
|
|
|
</p>
|
|
|
|
</div>
|
2018-02-14 17:53:54 +00:00
|
|
|
<div className="mx_MyGroups_joinedGroups">
|
|
|
|
{ groupNodes }
|
|
|
|
</div>
|
2018-03-21 12:00:56 +00:00
|
|
|
</GeminiScrollbarWrapper> :
|
2017-10-20 16:28:33 +00:00
|
|
|
<div className="mx_MyGroups_placeholder">
|
|
|
|
{ _t(
|
2017-10-20 17:10:14 +00:00
|
|
|
"You're not currently a member of any communities.",
|
2017-10-20 16:28:33 +00:00
|
|
|
) }
|
|
|
|
</div>;
|
2017-06-29 16:03:05 +00:00
|
|
|
} else if (this.state.error) {
|
|
|
|
content = <div className="mx_MyGroups_error">
|
2017-10-16 12:18:39 +00:00
|
|
|
{ _t('Error whilst fetching joined communities') }
|
2017-06-29 16:03:05 +00:00
|
|
|
</div>;
|
2017-06-29 17:30:16 +00:00
|
|
|
} else {
|
|
|
|
content = <Loader />;
|
2017-06-29 16:03:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return <div className="mx_MyGroups">
|
2019-01-11 01:37:28 +00:00
|
|
|
<SimpleRoomHeader title={_t("Communities")} icon={require("../../../res/img/icons-groups.svg")} />
|
2017-10-20 16:28:33 +00:00
|
|
|
<div className='mx_MyGroups_header'>
|
|
|
|
<div className="mx_MyGroups_headerCard">
|
|
|
|
<AccessibleButton className='mx_MyGroups_headerCard_button' onClick={this._onCreateGroupClick}>
|
2017-06-30 12:59:49 +00:00
|
|
|
</AccessibleButton>
|
2017-10-20 16:28:33 +00:00
|
|
|
<div className="mx_MyGroups_headerCard_content">
|
|
|
|
<div className="mx_MyGroups_headerCard_header">
|
|
|
|
{ _t('Create a new community') }
|
|
|
|
</div>
|
|
|
|
{ _t(
|
|
|
|
'Create a community to group together users and rooms! ' +
|
|
|
|
'Build a custom homepage to mark out your space in the Matrix universe.',
|
|
|
|
) }
|
2017-06-30 12:59:49 +00:00
|
|
|
</div>
|
2017-10-20 16:28:33 +00:00
|
|
|
</div>
|
2018-06-15 17:42:51 +00:00
|
|
|
{/*<div className="mx_MyGroups_joinBox mx_MyGroups_headerCard">
|
2017-10-20 16:28:33 +00:00
|
|
|
<AccessibleButton className='mx_MyGroups_headerCard_button' onClick={this._onJoinGroupClick}>
|
2019-01-11 01:37:28 +00:00
|
|
|
<TintableSvg src={require("../../../res/img/icons-create-room.svg")} width="50" height="50" />
|
2017-06-30 12:59:49 +00:00
|
|
|
</AccessibleButton>
|
2017-10-20 16:28:33 +00:00
|
|
|
<div className="mx_MyGroups_headerCard_content">
|
|
|
|
<div className="mx_MyGroups_headerCard_header">
|
|
|
|
{ _t('Join an existing community') }
|
|
|
|
</div>
|
2017-11-13 19:19:33 +00:00
|
|
|
{ _t(
|
2017-10-20 16:28:33 +00:00
|
|
|
'To join an existing community you\'ll have to '+
|
|
|
|
'know its community identifier; this will look '+
|
|
|
|
'something like <i>+example:matrix.org</i>.',
|
2017-11-13 19:19:33 +00:00
|
|
|
{},
|
|
|
|
{ 'i': (sub) => <i>{ sub }</i> })
|
|
|
|
}
|
2017-10-20 16:28:33 +00:00
|
|
|
</div>
|
2018-06-15 17:42:51 +00:00
|
|
|
</div>*/}
|
2017-06-30 12:59:49 +00:00
|
|
|
</div>
|
|
|
|
<div className="mx_MyGroups_content">
|
2017-11-03 11:19:29 +00:00
|
|
|
{ contentHeader }
|
2017-09-28 10:21:06 +00:00
|
|
|
{ content }
|
2017-06-29 16:03:05 +00:00
|
|
|
</div>
|
|
|
|
</div>;
|
|
|
|
},
|
2019-08-05 11:26:31 +00:00
|
|
|
});
|