2017-10-13 18:46:33 +03:00
|
|
|
/*
|
|
|
|
Copyright 2017 New Vector 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import sdk from '../../../index';
|
|
|
|
import dis from '../../../dispatcher';
|
|
|
|
import React from 'react';
|
|
|
|
import { _t } from '../../../languageHandler';
|
|
|
|
import linkifyString from 'linkifyjs/string';
|
|
|
|
import sanitizeHtml from 'sanitize-html';
|
|
|
|
import { ContentRepo } from 'matrix-js-sdk';
|
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
function getDisplayAliasForRoom(room) {
|
2017-10-24 12:13:38 +03:00
|
|
|
return room.canonicalAlias || (room.aliases ? room.aliases[0] : "");
|
2017-10-13 18:46:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const RoomDetailRow = React.createClass({
|
2017-11-01 20:12:22 +03:00
|
|
|
propTypes: {
|
|
|
|
room: PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
topic: PropTypes.string,
|
|
|
|
roomId: PropTypes.string,
|
|
|
|
avatarUrl: PropTypes.string,
|
|
|
|
numJoinedMembers: PropTypes.number,
|
|
|
|
canonicalAlias: PropTypes.string,
|
|
|
|
aliases: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
|
|
|
|
worldReadable: PropTypes.bool,
|
|
|
|
guestCanJoin: PropTypes.bool,
|
|
|
|
}),
|
|
|
|
},
|
2017-10-24 12:13:38 +03:00
|
|
|
|
2017-10-13 18:46:33 +03:00
|
|
|
onClick: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
dis.dispatch({
|
|
|
|
action: 'view_room',
|
2017-10-24 12:13:38 +03:00
|
|
|
room_id: this.props.room.roomId,
|
2017-11-03 20:52:36 +03:00
|
|
|
room_alias: this.props.room.canonicalAlias || (this.props.room.aliases || [])[0],
|
2017-10-13 18:46:33 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-13 19:57:28 +03:00
|
|
|
onTopicClick: function(ev) {
|
|
|
|
// When clicking a link in the topic, prevent the event being propagated
|
|
|
|
// to `onClick`.
|
|
|
|
ev.stopPropagation();
|
|
|
|
},
|
|
|
|
|
2017-10-13 18:46:33 +03:00
|
|
|
render: function() {
|
|
|
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
|
|
|
|
const room = this.props.room;
|
|
|
|
const name = room.name || getDisplayAliasForRoom(room) || _t('Unnamed room');
|
|
|
|
const topic = linkifyString(sanitizeHtml(room.topic || ''));
|
|
|
|
|
2017-10-24 12:13:38 +03:00
|
|
|
const guestRead = room.worldReadable ? (
|
2017-10-13 18:46:33 +03:00
|
|
|
<div className="mx_RoomDirectory_perm">{ _t('World readable') }</div>
|
|
|
|
) : <div />;
|
2017-10-24 12:13:38 +03:00
|
|
|
const guestJoin = room.guestCanJoin ? (
|
2017-10-13 18:46:33 +03:00
|
|
|
<div className="mx_RoomDirectory_perm">{ _t('Guests can join') }</div>
|
|
|
|
) : <div />;
|
|
|
|
|
|
|
|
const perms = (guestRead || guestJoin) ? (<div className="mx_RoomDirectory_perms">
|
|
|
|
{ guestRead }
|
|
|
|
{ guestJoin }
|
|
|
|
</div>) : <div />;
|
|
|
|
|
2017-10-24 12:13:38 +03:00
|
|
|
return <tr key={room.roomId} onClick={this.onClick}>
|
2017-10-13 18:46:33 +03:00
|
|
|
<td className="mx_RoomDirectory_roomAvatar">
|
|
|
|
<BaseAvatar width={24} height={24} resizeMethod='crop'
|
|
|
|
name={name} idName={name}
|
|
|
|
url={ContentRepo.getHttpUriForMxc(
|
|
|
|
MatrixClientPeg.get().getHomeserverUrl(),
|
2017-10-24 12:13:38 +03:00
|
|
|
room.avatarUrl, 24, 24, "crop")} />
|
2017-10-13 18:46:33 +03:00
|
|
|
</td>
|
|
|
|
<td className="mx_RoomDirectory_roomDescription">
|
|
|
|
<div className="mx_RoomDirectory_name">{ name }</div>
|
|
|
|
{ perms }
|
|
|
|
<div className="mx_RoomDirectory_topic"
|
2017-10-13 19:57:28 +03:00
|
|
|
onClick={this.onTopicClick}
|
2017-10-13 18:46:33 +03:00
|
|
|
dangerouslySetInnerHTML={{ __html: topic }} />
|
|
|
|
<div className="mx_RoomDirectory_alias">{ getDisplayAliasForRoom(room) }</div>
|
|
|
|
</td>
|
|
|
|
<td className="mx_RoomDirectory_roomMemberCount">
|
2017-10-24 12:13:38 +03:00
|
|
|
{ room.numJoinedMembers }
|
2017-10-13 18:46:33 +03:00
|
|
|
</td>
|
|
|
|
</tr>;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default React.createClass({
|
|
|
|
displayName: 'RoomDetailList',
|
|
|
|
|
|
|
|
propTypes: {
|
|
|
|
rooms: PropTypes.arrayOf(PropTypes.shape({
|
|
|
|
name: PropTypes.string,
|
|
|
|
topic: PropTypes.string,
|
2017-10-24 12:13:38 +03:00
|
|
|
roomId: PropTypes.string,
|
|
|
|
avatarUrl: PropTypes.string,
|
|
|
|
numJoinedMembers: PropTypes.number,
|
|
|
|
canonicalAlias: PropTypes.string,
|
2017-10-13 18:46:33 +03:00
|
|
|
aliases: PropTypes.arrayOf(PropTypes.string),
|
|
|
|
|
2017-10-24 12:13:38 +03:00
|
|
|
worldReadable: PropTypes.bool,
|
|
|
|
guestCanJoin: PropTypes.bool,
|
2017-10-13 18:46:33 +03:00
|
|
|
})),
|
|
|
|
},
|
|
|
|
|
|
|
|
getRows: function() {
|
|
|
|
if (!this.props.rooms) return [];
|
|
|
|
return this.props.rooms.map((room, index) => {
|
|
|
|
return <RoomDetailRow key={index} room={room} />;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const rows = this.getRows();
|
|
|
|
let rooms;
|
|
|
|
if (rows.length == 0) {
|
|
|
|
rooms = <i>{ _t('No rooms to show') }</i>;
|
|
|
|
} else {
|
|
|
|
rooms = <table ref="directory_table" className="mx_RoomDirectory_table">
|
|
|
|
<tbody>
|
|
|
|
{ this.getRows() }
|
|
|
|
</tbody>
|
|
|
|
</table>;
|
|
|
|
}
|
|
|
|
return <div className="mx_RoomDetailList">
|
|
|
|
{ rooms }
|
|
|
|
</div>;
|
|
|
|
},
|
|
|
|
});
|