2017-06-05 15:51:50 +00:00
|
|
|
/*
|
|
|
|
Copyright 2017 Vector Creations Ltd.
|
|
|
|
|
|
|
|
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 08:58:29 +00:00
|
|
|
import React from 'react';
|
2017-06-05 15:51:50 +00:00
|
|
|
import MatrixClientPeg from '../../MatrixClientPeg';
|
|
|
|
import sdk from '../../index';
|
2017-06-23 16:02:54 +00:00
|
|
|
import { sanitizedHtmlNode } from '../../HtmlUtils';
|
2017-06-26 16:47:17 +00:00
|
|
|
import { _t } from '../../languageHandler';
|
2017-06-05 15:51:50 +00:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = React.createClass({
|
|
|
|
displayName: 'GroupView',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
groupId: React.PropTypes.string.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
summary: null,
|
2017-06-26 16:47:17 +00:00
|
|
|
error: null,
|
2017-06-05 15:51:50 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount: function() {
|
2017-06-27 09:28:46 +00:00
|
|
|
this._loadGroupFromServer(this.props.groupId);
|
2017-06-05 15:51:50 +00:00
|
|
|
},
|
|
|
|
|
2017-06-27 12:13:00 +00:00
|
|
|
componentWillReceiveProps: function(newProps) {
|
|
|
|
if (this.props.groupId != newProps.groupId) {
|
2017-06-05 15:51:50 +00:00
|
|
|
this.setState({
|
|
|
|
summary: null,
|
2017-06-27 09:28:46 +00:00
|
|
|
error: null,
|
2017-06-27 12:13:00 +00:00
|
|
|
});
|
|
|
|
this._loadGroupFromServer(newProps.groupId);
|
2017-06-05 15:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_loadGroupFromServer: function(groupId) {
|
2017-06-23 16:02:54 +00:00
|
|
|
MatrixClientPeg.get().getGroupSummary(groupId).done((res) => {
|
|
|
|
this.setState({
|
2017-06-05 15:51:50 +00:00
|
|
|
summary: res,
|
2017-06-27 09:28:46 +00:00
|
|
|
error: null,
|
2017-06-05 15:51:50 +00:00
|
|
|
});
|
2017-06-23 16:02:54 +00:00
|
|
|
}, (err) => {
|
|
|
|
this.setState({
|
2017-06-05 15:51:50 +00:00
|
|
|
summary: null,
|
2017-06-26 16:47:17 +00:00
|
|
|
error: err,
|
2017-06-05 15:51:50 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
2017-06-23 16:02:54 +00:00
|
|
|
const BaseAvatar = sdk.getComponent("avatars.BaseAvatar");
|
|
|
|
const Loader = sdk.getComponent("elements.Spinner");
|
2017-06-05 15:51:50 +00:00
|
|
|
|
2017-06-27 09:28:46 +00:00
|
|
|
if (this.state.summary === null && this.state.error === null) {
|
2017-06-23 16:02:54 +00:00
|
|
|
return <Loader />;
|
2017-06-27 09:28:46 +00:00
|
|
|
} else if (this.state.summary) {
|
2017-06-05 15:51:50 +00:00
|
|
|
const summary = this.state.summary;
|
2017-06-27 09:05:05 +00:00
|
|
|
let avatarUrl = null;
|
2017-06-27 12:41:43 +00:00
|
|
|
if (summary.profile && summary.profile.avatar_url) {
|
2017-06-27 09:32:21 +00:00
|
|
|
avatarUrl = MatrixClientPeg.get().mxcUrlToHttp(summary.profile.avatar_url);
|
2017-06-05 15:51:50 +00:00
|
|
|
}
|
|
|
|
let description = null;
|
2017-06-27 12:41:43 +00:00
|
|
|
if (summary.profile && summary.profile.long_description) {
|
2017-06-23 16:02:54 +00:00
|
|
|
description = sanitizedHtmlNode(summary.profile.long_description);
|
2017-06-05 15:51:50 +00:00
|
|
|
}
|
|
|
|
return (
|
2017-06-27 10:52:23 +00:00
|
|
|
<div className="mx_GroupView">
|
2017-06-05 15:51:50 +00:00
|
|
|
<div className="mx_RoomHeader">
|
|
|
|
<div className="mx_RoomHeader_wrapper">
|
|
|
|
<div className="mx_RoomHeader_avatar">
|
2017-06-27 09:05:05 +00:00
|
|
|
<BaseAvatar url={avatarUrl} name={summary.profile.name}
|
2017-06-05 15:51:50 +00:00
|
|
|
width={48} height={48} />
|
|
|
|
</div>
|
|
|
|
<div className="mx_RoomHeader_info">
|
|
|
|
<div className="mx_RoomHeader_name">
|
|
|
|
<span>{summary.profile.name}</span>
|
2017-06-27 10:52:23 +00:00
|
|
|
<span className="mx_GroupView_header_groupid">
|
2017-06-05 15:51:50 +00:00
|
|
|
({this.props.groupId})
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
<div className="mx_RoomHeader_topic">
|
|
|
|
{summary.profile.short_description}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-06-23 16:02:54 +00:00
|
|
|
{description}
|
2017-06-05 15:51:50 +00:00
|
|
|
</div>
|
|
|
|
);
|
2017-06-27 09:28:46 +00:00
|
|
|
} else if (this.state.error) {
|
|
|
|
if (this.state.error.httpStatus === 404) {
|
|
|
|
return (
|
2017-06-27 10:52:23 +00:00
|
|
|
<div className="mx_GroupView_error">
|
2017-06-27 09:28:46 +00:00
|
|
|
Group {this.props.groupId} not found
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
let extraText;
|
|
|
|
if (this.state.error.errcode === 'M_UNRECOGNIZED') {
|
|
|
|
extraText = <div>{_t('This Home server does not support groups')}</div>;
|
|
|
|
}
|
|
|
|
return (
|
2017-06-27 10:52:23 +00:00
|
|
|
<div className="mx_GroupView_error">
|
2017-06-27 09:28:46 +00:00
|
|
|
Failed to load {this.props.groupId}
|
|
|
|
{extraText}
|
|
|
|
</div>
|
|
|
|
);
|
2017-06-26 16:47:17 +00:00
|
|
|
}
|
2017-06-27 12:41:43 +00:00
|
|
|
} else {
|
|
|
|
console.error("Invalid state for GroupView");
|
|
|
|
return <div />;
|
2017-06-05 15:51:50 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|