2015-11-27 13:42:03 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2019-12-20 03:45:24 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2015-11-27 13:42:03 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2021-02-18 18:16:59 +03:00
|
|
|
import React from 'react';
|
2017-12-26 04:03:18 +03:00
|
|
|
import PropTypes from 'prop-types';
|
2017-07-01 16:13:32 +03:00
|
|
|
import classNames from 'classnames';
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2019-12-21 00:13:46 +03:00
|
|
|
import {MatrixClientPeg} from '../../../MatrixClientPeg';
|
2017-07-01 16:13:32 +03:00
|
|
|
import RateLimitedFunc from '../../../ratelimitedfunc';
|
|
|
|
|
2017-01-25 19:05:39 +03:00
|
|
|
import {CancelButton} from './SimpleRoomHeader';
|
2017-10-29 05:21:34 +03:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2018-10-30 19:15:19 +03:00
|
|
|
import RoomHeaderButtons from '../right_panel/RoomHeaderButtons';
|
2019-02-01 15:40:19 +03:00
|
|
|
import E2EIcon from './E2EIcon';
|
2020-07-14 01:56:25 +03:00
|
|
|
import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar";
|
2020-07-17 20:16:21 +03:00
|
|
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
2021-02-18 18:16:59 +03:00
|
|
|
import RoomTopic from "../elements/RoomTopic";
|
|
|
|
import RoomName from "../elements/RoomName";
|
2021-02-26 23:46:39 +03:00
|
|
|
import {PlaceCallType} from "../../../CallHandler";
|
2021-03-09 06:12:00 +03:00
|
|
|
import {replaceableComponent} from "../../../utils/replaceableComponent";
|
2016-01-11 15:46:12 +03:00
|
|
|
|
2021-03-09 06:12:00 +03:00
|
|
|
@replaceableComponent("views.rooms.RoomHeader")
|
2020-08-29 14:14:16 +03:00
|
|
|
export default class RoomHeader extends React.Component {
|
|
|
|
static propTypes = {
|
2017-12-26 04:03:18 +03:00
|
|
|
room: PropTypes.object,
|
|
|
|
oobData: PropTypes.object,
|
|
|
|
inRoom: PropTypes.bool,
|
|
|
|
onSettingsClick: PropTypes.func,
|
|
|
|
onSearchClick: PropTypes.func,
|
|
|
|
onLeaveClick: PropTypes.func,
|
|
|
|
onCancelClick: PropTypes.func,
|
2019-02-01 15:40:19 +03:00
|
|
|
e2eStatus: PropTypes.string,
|
2020-10-09 10:42:21 +03:00
|
|
|
onAppsClick: PropTypes.func,
|
|
|
|
appsShown: PropTypes.bool,
|
2021-02-26 23:46:39 +03:00
|
|
|
onCallPlaced: PropTypes.func, // (PlaceCallType) => void;
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
editing: false,
|
|
|
|
inRoom: false,
|
|
|
|
onCancelClick: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
2017-07-01 16:13:32 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2016-03-29 18:31:13 +03:00
|
|
|
cli.on("RoomState.events", this._onRoomStateEvents);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-01-11 15:46:12 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentWillUnmount() {
|
2017-07-01 16:13:32 +03:00
|
|
|
const cli = MatrixClientPeg.get();
|
2016-03-29 18:31:13 +03:00
|
|
|
if (cli) {
|
|
|
|
cli.removeListener("RoomState.events", this._onRoomStateEvents);
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-03-29 18:31:13 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_onRoomStateEvents = (event, state) => {
|
2017-07-01 16:13:32 +03:00
|
|
|
if (!this.props.room || event.getRoomId() !== this.props.room.roomId) {
|
2016-03-29 18:31:13 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// redisplay the room name, topic, etc.
|
2016-10-26 15:09:53 +03:00
|
|
|
this._rateLimitedUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-03-29 18:31:13 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_rateLimitedUpdate = new RateLimitedFunc(function() {
|
2017-07-01 16:13:32 +03:00
|
|
|
/* eslint-disable babel/no-invalid-this */
|
2016-10-26 15:09:53 +03:00
|
|
|
this.forceUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
}, 500);
|
2016-10-26 15:09:53 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2017-07-01 16:13:32 +03:00
|
|
|
let searchStatus = null;
|
|
|
|
let cancelButton = null;
|
|
|
|
|
2017-04-21 14:56:59 +03:00
|
|
|
if (this.props.onCancelClick) {
|
2017-09-28 13:21:06 +03:00
|
|
|
cancelButton = <CancelButton onClick={this.props.onCancelClick} />;
|
2016-03-29 14:51:46 +03:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:25:26 +03:00
|
|
|
// 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 = <div className="mx_RoomHeader_searchStatus">
|
|
|
|
{ _t("(~%(count)s results)", { count: this.props.searchInfo.searchCount }) }
|
|
|
|
</div>;
|
2016-04-12 20:01:49 +03:00
|
|
|
}
|
|
|
|
|
2019-02-04 23:25:26 +03:00
|
|
|
// 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;
|
2016-01-21 03:16:10 +03:00
|
|
|
}
|
2016-03-29 14:51:46 +03:00
|
|
|
}
|
2019-02-04 23:25:26 +03:00
|
|
|
}
|
2016-01-21 03:16:10 +03:00
|
|
|
|
2021-02-18 18:16:59 +03:00
|
|
|
let oobName = _t("Join Room");
|
2019-02-04 23:25:26 +03:00
|
|
|
if (this.props.oobData && this.props.oobData.name) {
|
2021-02-18 18:16:59 +03:00
|
|
|
oobName = this.props.oobData.name;
|
2016-03-29 14:51:46 +03:00
|
|
|
}
|
2016-01-10 15:56:45 +03:00
|
|
|
|
2019-05-19 17:23:43 +03:00
|
|
|
const textClasses = classNames('mx_RoomHeader_nametext', { mx_RoomHeader_settingsHint: settingsHint });
|
2019-02-04 23:25:26 +03:00
|
|
|
const name =
|
|
|
|
<div className="mx_RoomHeader_name" onClick={this.props.onSettingsClick}>
|
2021-02-18 18:16:59 +03:00
|
|
|
<RoomName room={this.props.room}>
|
|
|
|
{(name) => {
|
|
|
|
const roomName = name || oobName;
|
|
|
|
return <div dir="auto" className={textClasses} title={roomName}>{ roomName }</div>;
|
|
|
|
}}
|
|
|
|
</RoomName>
|
2019-02-04 23:25:26 +03:00
|
|
|
{ searchStatus }
|
|
|
|
</div>;
|
|
|
|
|
2021-02-18 18:16:59 +03:00
|
|
|
const topicElement = <RoomTopic room={this.props.room}>
|
|
|
|
{(topic, ref) => <div className="mx_RoomHeader_topic" ref={ref} title={topic} dir="auto">
|
|
|
|
{ topic }
|
|
|
|
</div>}
|
|
|
|
</RoomTopic>;
|
2020-07-14 01:56:25 +03:00
|
|
|
|
2019-02-08 20:35:49 +03:00
|
|
|
let roomAvatar;
|
|
|
|
if (this.props.room) {
|
2020-07-14 01:56:25 +03:00
|
|
|
roomAvatar = <DecoratedRoomAvatar
|
2019-02-08 20:35:49 +03:00
|
|
|
room={this.props.room}
|
2020-07-14 01:56:25 +03:00
|
|
|
avatarSize={32}
|
2019-02-08 20:35:49 +03:00
|
|
|
oobData={this.props.oobData}
|
2020-07-14 01:56:25 +03:00
|
|
|
viewAvatarOnClick={true}
|
|
|
|
/>;
|
2019-02-08 20:35:49 +03:00
|
|
|
}
|
2015-11-27 13:42:03 +03:00
|
|
|
|
2017-07-01 16:13:32 +03:00
|
|
|
let forgetButton;
|
2016-03-29 14:51:46 +03:00
|
|
|
if (this.props.onForgetClick) {
|
2017-07-01 16:13:32 +03:00
|
|
|
forgetButton =
|
2020-07-17 20:16:21 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_forgetButton"
|
2019-02-12 19:42:11 +03:00
|
|
|
onClick={this.props.onForgetClick}
|
2020-07-17 20:16:21 +03:00
|
|
|
title={_t("Forget room")} />;
|
2016-03-29 14:51:46 +03:00
|
|
|
}
|
2015-12-13 16:49:28 +03:00
|
|
|
|
2020-10-09 10:42:21 +03:00
|
|
|
let appsButton;
|
|
|
|
if (this.props.onAppsClick) {
|
|
|
|
appsButton =
|
|
|
|
<AccessibleTooltipButton
|
|
|
|
className={classNames("mx_RoomHeader_button mx_RoomHeader_appsButton", {
|
|
|
|
mx_RoomHeader_appsButton_highlight: this.props.appsShown,
|
|
|
|
})}
|
|
|
|
onClick={this.props.onAppsClick}
|
|
|
|
title={this.props.appsShown ? _t("Hide Widgets") : _t("Show Widgets")} />;
|
|
|
|
}
|
|
|
|
|
2017-07-01 16:13:32 +03:00
|
|
|
let searchButton;
|
2017-05-11 19:35:06 +03:00
|
|
|
if (this.props.onSearchClick && this.props.inRoom) {
|
2017-07-01 16:13:32 +03:00
|
|
|
searchButton =
|
2020-07-17 20:16:21 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_searchButton"
|
2019-02-12 19:42:11 +03:00
|
|
|
onClick={this.props.onSearchClick}
|
2020-07-17 20:16:21 +03:00
|
|
|
title={_t("Search")} />;
|
2017-05-11 19:35:06 +03:00
|
|
|
}
|
|
|
|
|
2021-02-26 23:46:39 +03:00
|
|
|
let voiceCallButton;
|
|
|
|
let videoCallButton;
|
|
|
|
if (this.props.inRoom && SettingsStore.getValue("showCallButtonsInComposer")) {
|
|
|
|
voiceCallButton =
|
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_voiceCallButton"
|
|
|
|
onClick={() => this.props.onCallPlaced(PlaceCallType.Voice)}
|
|
|
|
title={_t("Voice call")} />;
|
|
|
|
videoCallButton =
|
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_videoCallButton"
|
|
|
|
onClick={(ev) => this.props.onCallPlaced(
|
|
|
|
ev.shiftKey ? PlaceCallType.ScreenSharing : PlaceCallType.Video)}
|
|
|
|
title={_t("Video call")} />;
|
|
|
|
}
|
|
|
|
|
2019-02-04 23:25:26 +03:00
|
|
|
const rightRow =
|
|
|
|
<div className="mx_RoomHeader_buttons">
|
2021-02-26 23:46:39 +03:00
|
|
|
{ videoCallButton }
|
|
|
|
{ voiceCallButton }
|
2019-02-04 23:25:26 +03:00
|
|
|
{ forgetButton }
|
2020-10-09 10:42:21 +03:00
|
|
|
{ appsButton }
|
2019-02-04 23:25:26 +03:00
|
|
|
{ searchButton }
|
|
|
|
</div>;
|
2016-01-10 15:56:45 +03:00
|
|
|
|
2020-07-14 01:56:25 +03:00
|
|
|
const e2eIcon = this.props.e2eStatus ? <E2EIcon status={this.props.e2eStatus} /> : undefined;
|
|
|
|
|
2015-11-27 13:42:03 +03:00
|
|
|
return (
|
2019-02-04 23:25:26 +03:00
|
|
|
<div className="mx_RoomHeader light-panel">
|
2020-02-13 21:18:21 +03:00
|
|
|
<div className="mx_RoomHeader_wrapper" aria-owns="mx_RightPanel">
|
2020-07-14 01:56:25 +03:00
|
|
|
<div className="mx_RoomHeader_avatar">{ roomAvatar }</div>
|
|
|
|
<div className="mx_RoomHeader_e2eIcon">{ e2eIcon }</div>
|
2018-10-23 17:57:56 +03:00
|
|
|
{ name }
|
|
|
|
{ topicElement }
|
2017-09-28 13:21:06 +03:00
|
|
|
{ cancelButton }
|
|
|
|
{ rightRow }
|
2021-05-25 18:10:44 +03:00
|
|
|
<RoomHeaderButtons room={this.props.room} />
|
2017-07-01 16:13:32 +03:00
|
|
|
</div>
|
2015-11-27 13:42:03 +03:00
|
|
|
</div>
|
|
|
|
);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|