/* Copyright 2015, 2016 OpenMarket Ltd Copyright 2019, 2021 The Matrix.org Foundation C.I.C. 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'; import classNames from 'classnames'; import { _t } from '../../../languageHandler'; import { MatrixClientPeg } from '../../../MatrixClientPeg'; import SettingsStore from "../../../settings/SettingsStore"; import RoomHeaderButtons from '../right_panel/RoomHeaderButtons'; import E2EIcon from './E2EIcon'; import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar"; import AccessibleTooltipButton from "../elements/AccessibleTooltipButton"; import RoomTopic from "../elements/RoomTopic"; import RoomName from "../elements/RoomName"; import { PlaceCallType } from "../../../CallHandler"; import { replaceableComponent } from "../../../utils/replaceableComponent"; import { throttle } from 'lodash'; import { MatrixEvent, Room, RoomState } from 'matrix-js-sdk/src'; import { E2EStatus } from '../../../utils/ShieldUtils'; import { IOOBData } from '../../../stores/ThreepidInviteStore'; import { SearchScope } from './SearchBar'; export interface ISearchInfo { searchTerm: string; searchScope: SearchScope; searchCount: number; } interface IProps { room: Room; oobData?: IOOBData; inRoom: boolean; onSettingsClick: () => void; onSearchClick: () => void; onForgetClick: () => void; onCallPlaced: (type: PlaceCallType) => void; onAppsClick: () => void; e2eStatus: E2EStatus; appsShown: boolean; searchInfo: ISearchInfo; } @replaceableComponent("views.rooms.RoomHeader") export default class RoomHeader extends React.Component { static defaultProps = { editing: false, inRoom: false, }; public componentDidMount() { const cli = MatrixClientPeg.get(); cli.on("RoomState.events", this.onRoomStateEvents); } public componentWillUnmount() { const cli = MatrixClientPeg.get(); if (cli) { cli.removeListener("RoomState.events", this.onRoomStateEvents); } } private onRoomStateEvents = (event: MatrixEvent, state: RoomState) => { if (!this.props.room || event.getRoomId() !== this.props.room.roomId) { return; } // redisplay the room name, topic, etc. this.rateLimitedUpdate(); }; private rateLimitedUpdate = throttle(() => { this.forceUpdate(); }, 500, { leading: true, trailing: true }); public render() { let searchStatus = null; // don't display the search count until the search completes and // gives us a valid (possibly zero) searchCount. if (this.props.searchInfo && this.props.searchInfo.searchCount !== undefined && this.props.searchInfo.searchCount !== null) { searchStatus =
  { _t("(~%(count)s results)", { count: this.props.searchInfo.searchCount }) }
; } // XXX: this is a bit inefficient - we could just compare room.name for 'Empty room'... let settingsHint = false; const members = this.props.room ? this.props.room.getJoinedMembers() : undefined; if (members) { if (members.length === 1 && members[0].userId === MatrixClientPeg.get().credentials.userId) { const nameEvent = this.props.room.currentState.getStateEvents('m.room.name', ''); if (!nameEvent || !nameEvent.getContent().name) { settingsHint = true; } } } let oobName = _t("Join Room"); if (this.props.oobData && this.props.oobData.name) { oobName = this.props.oobData.name; } const textClasses = classNames('mx_RoomHeader_nametext', { mx_RoomHeader_settingsHint: settingsHint }); const name =
{(name) => { const roomName = name || oobName; return
{ roomName }
; }}
{ searchStatus }
; const topicElement = {(topic, ref) =>
{ topic }
}
; let roomAvatar; if (this.props.room) { roomAvatar = ; } let forgetButton; if (this.props.onForgetClick) { forgetButton = ; } let appsButton; if (this.props.onAppsClick) { appsButton = ; } let searchButton; if (this.props.onSearchClick && this.props.inRoom) { searchButton = ; } let voiceCallButton; let videoCallButton; if (this.props.inRoom && SettingsStore.getValue("showCallButtonsInComposer")) { voiceCallButton = this.props.onCallPlaced(PlaceCallType.Voice)} title={_t("Voice call")} />; videoCallButton = this.props.onCallPlaced( ev.shiftKey ? PlaceCallType.ScreenSharing : PlaceCallType.Video)} title={_t("Video call")} />; } const rightRow =
{ videoCallButton } { voiceCallButton } { forgetButton } { appsButton } { searchButton }
; const e2eIcon = this.props.e2eStatus ? : undefined; return (
{ roomAvatar }
{ e2eIcon }
{ name } { topicElement } { rightRow }
); } }