2015-11-27 10:42:03 +00:00
|
|
|
/*
|
2016-01-07 04:06:39 +00:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
2021-07-01 19:54:05 +01:00
|
|
|
Copyright 2019, 2021 The Matrix.org Foundation C.I.C.
|
2015-11-27 10:42:03 +00: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 15:16:59 +00:00
|
|
|
import React from 'react';
|
2017-07-01 14:13:32 +01:00
|
|
|
import classNames from 'classnames';
|
2017-05-25 11:39:08 +01:00
|
|
|
import { _t } from '../../../languageHandler';
|
2021-06-03 08:41:22 +01:00
|
|
|
import { MatrixClientPeg } from '../../../MatrixClientPeg';
|
2015-11-27 10:42:03 +00:00
|
|
|
|
2017-10-28 20:21:34 -06:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2018-10-30 17:15:19 +01:00
|
|
|
import RoomHeaderButtons from '../right_panel/RoomHeaderButtons';
|
2019-02-01 13:40:19 +01:00
|
|
|
import E2EIcon from './E2EIcon';
|
2020-07-13 23:56:25 +01:00
|
|
|
import DecoratedRoomAvatar from "../avatars/DecoratedRoomAvatar";
|
2020-07-17 18:16:21 +01:00
|
|
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
2021-02-18 15:16:59 +00:00
|
|
|
import RoomTopic from "../elements/RoomTopic";
|
|
|
|
|
import RoomName from "../elements/RoomName";
|
2021-06-04 08:32:30 +02:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-07-01 18:35:38 +01:00
|
|
|
import { throttle } from 'lodash';
|
2021-07-01 21:00:54 +01:00
|
|
|
import { MatrixEvent, Room, RoomState } from 'matrix-js-sdk/src';
|
2021-07-01 19:54:05 +01:00
|
|
|
import { E2EStatus } from '../../../utils/ShieldUtils';
|
|
|
|
|
import { IOOBData } from '../../../stores/ThreepidInviteStore';
|
|
|
|
|
import { SearchScope } from './SearchBar';
|
2021-11-30 19:09:13 +01:00
|
|
|
import { CallType } from "matrix-js-sdk/src/webrtc/call";
|
2021-11-15 11:39:25 +00:00
|
|
|
import { ContextMenuTooltipButton } from '../../structures/ContextMenu';
|
|
|
|
|
import RoomContextMenu from "../context_menus/RoomContextMenu";
|
|
|
|
|
import { contextMenuBelow } from './RoomTile';
|
2021-11-30 11:06:20 +01:00
|
|
|
import { RoomNotificationStateStore } from '../../../stores/notifications/RoomNotificationStateStore';
|
2021-11-29 19:01:47 +01:00
|
|
|
import { RightPanelPhases } from '../../../stores/RightPanelStorePhases';
|
2021-12-07 12:51:34 +00:00
|
|
|
import { NotificationStateEvents } from '../../../stores/notifications/NotificationState';
|
2021-07-01 19:54:05 +01:00
|
|
|
|
|
|
|
|
export interface ISearchInfo {
|
|
|
|
|
searchTerm: string;
|
|
|
|
|
searchScope: SearchScope;
|
|
|
|
|
searchCount: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IProps {
|
2021-07-01 20:57:56 +01:00
|
|
|
room: Room;
|
|
|
|
|
oobData?: IOOBData;
|
|
|
|
|
inRoom: boolean;
|
2021-07-01 19:54:05 +01:00
|
|
|
onSearchClick: () => void;
|
|
|
|
|
onForgetClick: () => void;
|
2021-11-30 19:09:13 +01:00
|
|
|
onCallPlaced: (type: CallType) => void;
|
2021-07-01 19:54:05 +01:00
|
|
|
onAppsClick: () => void;
|
|
|
|
|
e2eStatus: E2EStatus;
|
|
|
|
|
appsShown: boolean;
|
|
|
|
|
searchInfo: ISearchInfo;
|
2021-11-29 19:01:47 +01:00
|
|
|
excludedRightPanelPhaseButtons?: Array<RightPanelPhases>;
|
2021-07-01 19:54:05 +01:00
|
|
|
}
|
2016-01-11 12:46:12 +00:00
|
|
|
|
2021-11-15 11:39:25 +00:00
|
|
|
interface IState {
|
|
|
|
|
contextMenuPosition?: DOMRect;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 20:12:00 -07:00
|
|
|
@replaceableComponent("views.rooms.RoomHeader")
|
2021-11-15 11:39:25 +00:00
|
|
|
export default class RoomHeader extends React.Component<IProps, IState> {
|
2020-08-29 12:14:16 +01:00
|
|
|
static defaultProps = {
|
|
|
|
|
editing: false,
|
|
|
|
|
inRoom: false,
|
2021-11-29 19:01:47 +01:00
|
|
|
excludedRightPanelPhaseButtons: [],
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
|
|
|
|
|
2021-11-15 11:39:25 +00:00
|
|
|
constructor(props, context) {
|
|
|
|
|
super(props, context);
|
2021-11-30 11:06:20 +01:00
|
|
|
const notiStore = RoomNotificationStateStore.instance.getRoomState(props.room);
|
2021-12-07 12:51:34 +00:00
|
|
|
notiStore.on(NotificationStateEvents.Update, this.onNotificationUpdate);
|
2021-11-15 11:39:25 +00:00
|
|
|
this.state = {};
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-01 19:54:05 +01:00
|
|
|
public componentDidMount() {
|
2017-07-01 14:13:32 +01:00
|
|
|
const cli = MatrixClientPeg.get();
|
2021-07-01 19:54:05 +01:00
|
|
|
cli.on("RoomState.events", this.onRoomStateEvents);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2016-01-11 12:46:12 +00:00
|
|
|
|
2021-07-01 19:54:05 +01:00
|
|
|
public componentWillUnmount() {
|
2017-07-01 14:13:32 +01:00
|
|
|
const cli = MatrixClientPeg.get();
|
2016-03-29 16:31:13 +01:00
|
|
|
if (cli) {
|
2021-07-01 19:54:05 +01:00
|
|
|
cli.removeListener("RoomState.events", this.onRoomStateEvents);
|
2016-03-29 16:31:13 +01:00
|
|
|
}
|
2021-11-30 11:06:20 +01:00
|
|
|
const notiStore = RoomNotificationStateStore.instance.getRoomState(this.props.room);
|
2021-12-07 12:51:34 +00:00
|
|
|
notiStore.removeListener(NotificationStateEvents.Update, this.onNotificationUpdate);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2016-03-29 16:31:13 +01:00
|
|
|
|
2021-07-01 21:00:54 +01:00
|
|
|
private onRoomStateEvents = (event: MatrixEvent, state: RoomState) => {
|
2017-07-01 14:13:32 +01:00
|
|
|
if (!this.props.room || event.getRoomId() !== this.props.room.roomId) {
|
2016-03-29 16:31:13 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// redisplay the room name, topic, etc.
|
2021-07-01 19:54:05 +01:00
|
|
|
this.rateLimitedUpdate();
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2016-03-29 16:31:13 +01:00
|
|
|
|
2021-11-30 11:06:20 +01:00
|
|
|
private onNotificationUpdate = () => {
|
|
|
|
|
this.forceUpdate();
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-01 19:54:05 +01:00
|
|
|
private rateLimitedUpdate = throttle(() => {
|
2016-10-26 13:09:53 +01:00
|
|
|
this.forceUpdate();
|
2021-07-01 18:35:38 +01:00
|
|
|
}, 500, { leading: true, trailing: true });
|
2016-10-26 13:09:53 +01:00
|
|
|
|
2021-11-15 11:39:25 +00:00
|
|
|
private onContextMenuOpenClick = (ev: React.MouseEvent) => {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
const target = ev.target as HTMLButtonElement;
|
|
|
|
|
this.setState({ contextMenuPosition: target.getBoundingClientRect() });
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private onContextMenuCloseClick = () => {
|
|
|
|
|
this.setState({ contextMenuPosition: null });
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-01 19:54:05 +01:00
|
|
|
public render() {
|
2017-07-01 14:13:32 +01:00
|
|
|
let searchStatus = null;
|
2016-03-29 12:51:46 +01:00
|
|
|
|
2019-02-04 13:25:26 -07: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 18:01:49 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-04 13:25:26 -07: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 00:16:10 +00:00
|
|
|
}
|
2016-03-29 12:51:46 +01:00
|
|
|
}
|
2015-11-27 10:42:03 +00:00
|
|
|
}
|
|
|
|
|
|
2021-02-18 15:16:59 +00:00
|
|
|
let oobName = _t("Join Room");
|
2019-02-04 13:25:26 -07:00
|
|
|
if (this.props.oobData && this.props.oobData.name) {
|
2021-02-18 15:16:59 +00:00
|
|
|
oobName = this.props.oobData.name;
|
2016-03-29 12:51:46 +01:00
|
|
|
}
|
|
|
|
|
|
2021-11-15 11:39:25 +00:00
|
|
|
let contextMenu: JSX.Element;
|
|
|
|
|
if (this.state.contextMenuPosition && this.props.room) {
|
|
|
|
|
contextMenu = (
|
|
|
|
|
<RoomContextMenu
|
|
|
|
|
{...contextMenuBelow(this.state.contextMenuPosition)}
|
|
|
|
|
room={this.props.room}
|
|
|
|
|
onFinished={this.onContextMenuCloseClick}
|
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-19 15:23:43 +01:00
|
|
|
const textClasses = classNames('mx_RoomHeader_nametext', { mx_RoomHeader_settingsHint: settingsHint });
|
2021-11-15 11:39:25 +00:00
|
|
|
const name = (
|
|
|
|
|
<ContextMenuTooltipButton
|
|
|
|
|
className="mx_RoomHeader_name"
|
|
|
|
|
onClick={this.onContextMenuOpenClick}
|
|
|
|
|
isExpanded={!!this.state.contextMenuPosition}
|
|
|
|
|
title={_t("Room options")}
|
|
|
|
|
>
|
2021-02-18 15:16:59 +00:00
|
|
|
<RoomName room={this.props.room}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ (name) => {
|
2021-02-18 15:16:59 +00:00
|
|
|
const roomName = name || oobName;
|
|
|
|
|
return <div dir="auto" className={textClasses} title={roomName}>{ roomName }</div>;
|
2021-07-19 22:43:11 +01:00
|
|
|
} }
|
2021-02-18 15:16:59 +00:00
|
|
|
</RoomName>
|
2021-11-15 11:39:25 +00:00
|
|
|
{ this.props.room && <div className="mx_RoomHeader_chevron" /> }
|
|
|
|
|
{ contextMenu }
|
|
|
|
|
</ContextMenuTooltipButton>
|
|
|
|
|
);
|
2019-02-04 13:25:26 -07:00
|
|
|
|
2021-02-18 15:16:59 +00:00
|
|
|
const topicElement = <RoomTopic room={this.props.room}>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ (topic, ref) => <div className="mx_RoomHeader_topic" ref={ref} title={topic} dir="auto">
|
2021-02-18 15:16:59 +00:00
|
|
|
{ topic }
|
2021-07-19 22:43:11 +01:00
|
|
|
</div> }
|
2021-02-18 15:16:59 +00:00
|
|
|
</RoomTopic>;
|
2020-07-13 23:56:25 +01:00
|
|
|
|
2019-02-08 17:35:49 +00:00
|
|
|
let roomAvatar;
|
|
|
|
|
if (this.props.room) {
|
2020-07-13 23:56:25 +01:00
|
|
|
roomAvatar = <DecoratedRoomAvatar
|
2019-02-08 17:35:49 +00:00
|
|
|
room={this.props.room}
|
2021-11-15 11:39:25 +00:00
|
|
|
avatarSize={24}
|
2019-02-08 17:35:49 +00:00
|
|
|
oobData={this.props.oobData}
|
2020-07-13 23:56:25 +01:00
|
|
|
viewAvatarOnClick={true}
|
|
|
|
|
/>;
|
2019-02-08 17:35:49 +00:00
|
|
|
}
|
2016-03-29 12:51:46 +01:00
|
|
|
|
2021-10-14 15:27:35 +02:00
|
|
|
const buttons: JSX.Element[] = [];
|
2016-03-29 12:51:46 +01:00
|
|
|
|
2021-02-26 13:46:39 -07:00
|
|
|
if (this.props.inRoom && SettingsStore.getValue("showCallButtonsInComposer")) {
|
2021-10-14 15:27:35 +02:00
|
|
|
const voiceCallButton = <AccessibleTooltipButton
|
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_voiceCallButton"
|
2021-11-30 19:09:13 +01:00
|
|
|
onClick={() => this.props.onCallPlaced(CallType.Voice)}
|
2021-10-14 15:27:35 +02:00
|
|
|
title={_t("Voice call")}
|
2021-10-18 13:47:42 -06:00
|
|
|
key="voice"
|
2021-10-14 15:27:35 +02:00
|
|
|
/>;
|
|
|
|
|
const videoCallButton = <AccessibleTooltipButton
|
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_videoCallButton"
|
2021-12-02 16:36:36 +01:00
|
|
|
onClick={() => this.props.onCallPlaced(CallType.Video)}
|
2021-10-14 15:27:35 +02:00
|
|
|
title={_t("Video call")}
|
2021-10-18 13:47:42 -06:00
|
|
|
key="video"
|
2021-10-14 15:27:35 +02:00
|
|
|
/>;
|
|
|
|
|
buttons.push(voiceCallButton, videoCallButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.onForgetClick) {
|
|
|
|
|
const forgetButton = <AccessibleTooltipButton
|
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_forgetButton"
|
|
|
|
|
onClick={this.props.onForgetClick}
|
|
|
|
|
title={_t("Forget room")}
|
2021-10-18 13:47:42 -06:00
|
|
|
key="forget"
|
2021-10-14 15:27:35 +02:00
|
|
|
/>;
|
|
|
|
|
buttons.push(forgetButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.onAppsClick) {
|
|
|
|
|
const 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")}
|
2021-10-18 13:47:42 -06:00
|
|
|
key="apps"
|
2021-10-14 15:27:35 +02:00
|
|
|
/>;
|
|
|
|
|
buttons.push(appsButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.props.onSearchClick && this.props.inRoom) {
|
|
|
|
|
const searchButton = <AccessibleTooltipButton
|
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_searchButton"
|
|
|
|
|
onClick={this.props.onSearchClick}
|
|
|
|
|
title={_t("Search")}
|
2021-10-18 13:47:42 -06:00
|
|
|
key="search"
|
2021-10-14 15:27:35 +02:00
|
|
|
/>;
|
|
|
|
|
buttons.push(searchButton);
|
2021-02-26 13:46:39 -07:00
|
|
|
}
|
|
|
|
|
|
2019-02-04 13:25:26 -07:00
|
|
|
const rightRow =
|
|
|
|
|
<div className="mx_RoomHeader_buttons">
|
2021-10-14 15:27:35 +02:00
|
|
|
{ buttons }
|
2019-02-04 13:25:26 -07:00
|
|
|
</div>;
|
2016-03-29 12:51:46 +01:00
|
|
|
|
2020-07-13 23:56:25 +01:00
|
|
|
const e2eIcon = this.props.e2eStatus ? <E2EIcon status={this.props.e2eStatus} /> : undefined;
|
|
|
|
|
|
2015-11-27 10:42:03 +00:00
|
|
|
return (
|
2019-02-04 13:25:26 -07:00
|
|
|
<div className="mx_RoomHeader light-panel">
|
2020-02-13 19:18:21 +01:00
|
|
|
<div className="mx_RoomHeader_wrapper" aria-owns="mx_RightPanel">
|
2020-07-13 23:56:25 +01:00
|
|
|
<div className="mx_RoomHeader_avatar">{ roomAvatar }</div>
|
|
|
|
|
<div className="mx_RoomHeader_e2eIcon">{ e2eIcon }</div>
|
2018-10-23 16:57:56 +02:00
|
|
|
{ name }
|
2021-11-15 11:39:25 +00:00
|
|
|
{ searchStatus }
|
2018-10-23 16:57:56 +02:00
|
|
|
{ topicElement }
|
2017-09-28 11:21:06 +01:00
|
|
|
{ rightRow }
|
2021-11-29 19:01:47 +01:00
|
|
|
<RoomHeaderButtons room={this.props.room} excludedRightPanelPhaseButtons={this.props.excludedRightPanelPhaseButtons} />
|
2017-07-01 14:13:32 +01:00
|
|
|
</div>
|
2015-11-27 10:42:03 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|