2017-11-19 15:49:26 +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.
|
|
|
|
*/
|
|
|
|
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2019-12-08 15:16:17 +03:00
|
|
|
import React, {createRef} from 'react';
|
2017-11-19 15:49:26 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-02-01 00:35:58 +03:00
|
|
|
import { linkifyElement } from '../../../HtmlUtils';
|
2017-11-19 15:49:26 +03:00
|
|
|
import { ContentRepo } from 'matrix-js-sdk';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
2017-11-19 15:49:26 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2019-09-06 17:04:46 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-11-19 15:49:26 +03:00
|
|
|
|
2017-11-19 16:18:06 +03:00
|
|
|
export function getDisplayAliasForRoom(room) {
|
2017-11-19 15:49:26 +03:00
|
|
|
return room.canonicalAlias || (room.aliases ? room.aliases[0] : "");
|
|
|
|
}
|
|
|
|
|
|
|
|
export const roomShape = 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,
|
|
|
|
});
|
|
|
|
|
2019-09-06 17:04:46 +03:00
|
|
|
export default createReactClass({
|
2017-11-19 15:49:26 +03:00
|
|
|
propTypes: {
|
|
|
|
room: roomShape,
|
|
|
|
// passes ev, room as args
|
|
|
|
onClick: PropTypes.func,
|
|
|
|
onMouseDown: PropTypes.func,
|
|
|
|
},
|
|
|
|
|
|
|
|
_linkifyTopic: function() {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._topic.current) {
|
|
|
|
linkifyElement(this._topic.current);
|
2017-11-19 15:49:26 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
UNSAFE_componentWillMount: function() {
|
|
|
|
this._topic = createRef();
|
|
|
|
},
|
|
|
|
|
2017-11-19 15:49:26 +03:00
|
|
|
componentDidMount: function() {
|
|
|
|
this._linkifyTopic();
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidUpdate: function() {
|
|
|
|
this._linkifyTopic();
|
|
|
|
},
|
|
|
|
|
|
|
|
onClick: function(ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
if (this.props.onClick) {
|
|
|
|
this.props.onClick(ev, this.props.room);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onTopicClick: function(ev) {
|
|
|
|
// When clicking a link in the topic, prevent the event being propagated
|
|
|
|
// to `onClick`.
|
|
|
|
ev.stopPropagation();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
const BaseAvatar = sdk.getComponent('avatars.BaseAvatar');
|
|
|
|
|
|
|
|
const room = this.props.room;
|
|
|
|
const name = room.name || getDisplayAliasForRoom(room) || _t('Unnamed room');
|
|
|
|
|
|
|
|
const guestRead = room.worldReadable ? (
|
|
|
|
<div className="mx_RoomDirectory_perm">{ _t('World readable') }</div>
|
|
|
|
) : <div />;
|
|
|
|
const guestJoin = room.guestCanJoin ? (
|
|
|
|
<div className="mx_RoomDirectory_perm">{ _t('Guests can join') }</div>
|
|
|
|
) : <div />;
|
|
|
|
|
|
|
|
const perms = (guestRead || guestJoin) ? (<div className="mx_RoomDirectory_perms">
|
|
|
|
{ guestRead }
|
|
|
|
{ guestJoin }
|
|
|
|
</div>) : <div />;
|
|
|
|
|
|
|
|
return <tr key={room.roomId} onClick={this.onClick} onMouseDown={this.props.onMouseDown}>
|
|
|
|
<td className="mx_RoomDirectory_roomAvatar">
|
|
|
|
<BaseAvatar width={24} height={24} resizeMethod='crop'
|
|
|
|
name={name} idName={name}
|
|
|
|
url={ContentRepo.getHttpUriForMxc(
|
|
|
|
MatrixClientPeg.get().getHomeserverUrl(),
|
|
|
|
room.avatarUrl, 24, 24, "crop")} />
|
|
|
|
</td>
|
|
|
|
<td className="mx_RoomDirectory_roomDescription">
|
|
|
|
<div className="mx_RoomDirectory_name">{ name }</div>
|
|
|
|
{ perms }
|
2019-12-08 15:16:17 +03:00
|
|
|
<div className="mx_RoomDirectory_topic" ref={this._topic} onClick={this.onTopicClick}>
|
2017-11-19 15:49:26 +03:00
|
|
|
{ room.topic }
|
|
|
|
</div>
|
|
|
|
<div className="mx_RoomDirectory_alias">{ getDisplayAliasForRoom(room) }</div>
|
|
|
|
</td>
|
|
|
|
<td className="mx_RoomDirectory_roomMemberCount">
|
|
|
|
{ room.numJoinedMembers }
|
|
|
|
</td>
|
|
|
|
</tr>;
|
|
|
|
},
|
|
|
|
});
|