/* 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 * as sdk from '../../../index'; import React, {createRef} from 'react'; import { _t } from '../../../languageHandler'; import { linkifyElement } from '../../../HtmlUtils'; import {MatrixClientPeg} from '../../../MatrixClientPeg'; import PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import {getHttpUriForMxc} from "matrix-js-sdk/src/content-repo"; export function getDisplayAliasForRoom(room) { 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, }); export default createReactClass({ propTypes: { room: roomShape, // passes ev, room as args onClick: PropTypes.func, onMouseDown: PropTypes.func, }, _linkifyTopic: function() { if (this._topic.current) { linkifyElement(this._topic.current); } }, // TODO: [REACT-WARNING] Replace component with real class, use constructor for refs UNSAFE_componentWillMount: function() { this._topic = createRef(); }, 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 ? (
{ _t('World readable') }
) :
; const guestJoin = room.guestCanJoin ? (
{ _t('Guests can join') }
) :
; const perms = (guestRead || guestJoin) ? (
{ guestRead }  { guestJoin }
) :
; return
{ name }
  { perms }
{ room.topic }
{ getDisplayAliasForRoom(room) }
{ room.numJoinedMembers } ; }, });