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.
|
|
|
|
*/
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
import React, {createRef} 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';
|
|
|
|
|
2019-02-01 00:35:58 +03:00
|
|
|
import { linkifyElement } from '../../../HtmlUtils';
|
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";
|
|
|
|
import {DefaultTagID} from "../../../stores/room-list/models";
|
2020-07-17 20:16:21 +03:00
|
|
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
2016-01-11 15:46:12 +03:00
|
|
|
|
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,
|
|
|
|
onPinnedClick: PropTypes.func,
|
|
|
|
onSearchClick: PropTypes.func,
|
|
|
|
onLeaveClick: PropTypes.func,
|
|
|
|
onCancelClick: PropTypes.func,
|
2019-02-01 15:40:19 +03:00
|
|
|
e2eStatus: PropTypes.string,
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
static defaultProps = {
|
|
|
|
editing: false,
|
|
|
|
inRoom: false,
|
|
|
|
onCancelClick: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
this._topic = createRef();
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2019-12-08 15:16:17 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
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);
|
2017-10-16 06:17:43 +03:00
|
|
|
cli.on("Room.accountData", this._onRoomAccountData);
|
2016-04-15 11:59:23 +03:00
|
|
|
|
|
|
|
// When a room name occurs, RoomState.events is fired *before*
|
|
|
|
// room.name is updated. So we have to listen to Room.name as well as
|
|
|
|
// RoomState.events.
|
|
|
|
if (this.props.room) {
|
|
|
|
this.props.room.on("Room.name", this._onRoomNameChange);
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2016-03-29 18:31:13 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
componentDidUpdate() {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._topic.current) {
|
|
|
|
linkifyElement(this._topic.current);
|
2016-01-11 15:46:12 +03:00
|
|
|
}
|
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() {
|
2016-04-15 11:59:23 +03:00
|
|
|
if (this.props.room) {
|
|
|
|
this.props.room.removeListener("Room.name", this._onRoomNameChange);
|
|
|
|
}
|
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);
|
2017-10-16 06:17:43 +03:00
|
|
|
cli.removeListener("Room.accountData", this._onRoomAccountData);
|
2016-03-29 18:31:13 +03:00
|
|
|
}
|
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
|
|
|
_onRoomAccountData = (event, room) => {
|
2017-10-16 06:17:43 +03:00
|
|
|
if (!this.props.room || room.roomId !== this.props.room.roomId) return;
|
|
|
|
if (event.getType() !== "im.vector.room.read_pins") return;
|
|
|
|
|
|
|
|
this._rateLimitedUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-10-16 06:17:43 +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
|
|
|
_onRoomNameChange = (room) => {
|
2016-04-15 11:59:23 +03:00
|
|
|
this.forceUpdate();
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2016-04-15 11:59:23 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_hasUnreadPins() {
|
2017-10-16 06:17:43 +03:00
|
|
|
const currentPinEvent = this.props.room.currentState.getStateEvents("m.room.pinned_events", '');
|
|
|
|
if (!currentPinEvent) return false;
|
|
|
|
if (currentPinEvent.getContent().pinned && currentPinEvent.getContent().pinned.length <= 0) {
|
|
|
|
return false; // no pins == nothing to read
|
|
|
|
}
|
|
|
|
|
|
|
|
const readPinsEvent = this.props.room.getAccountData("im.vector.room.read_pins");
|
2017-11-04 03:18:09 +03:00
|
|
|
if (readPinsEvent && readPinsEvent.getContent()) {
|
|
|
|
const readStateEvents = readPinsEvent.getContent().event_ids || [];
|
2017-11-04 03:12:57 +03:00
|
|
|
if (readStateEvents) {
|
|
|
|
return !readStateEvents.includes(currentPinEvent.getId());
|
2017-10-16 06:17:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// There's pins, and we haven't read any of them
|
|
|
|
return true;
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2017-10-16 06:17:43 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_hasPins() {
|
2017-11-04 05:00:48 +03:00
|
|
|
const currentPinEvent = this.props.room.currentState.getStateEvents("m.room.pinned_events", '');
|
|
|
|
if (!currentPinEvent) return false;
|
|
|
|
|
|
|
|
return !(currentPinEvent.getContent().pinned && currentPinEvent.getContent().pinned.length <= 0);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
2017-11-04 05:00:48 +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-09-29 00:32:51 +03:00
|
|
|
let pinnedEventsButton = null;
|
2017-07-01 16:13:32 +03:00
|
|
|
|
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
|
|
|
|
2019-02-04 23:25:26 +03:00
|
|
|
let roomName = _t("Join Room");
|
|
|
|
if (this.props.oobData && this.props.oobData.name) {
|
|
|
|
roomName = this.props.oobData.name;
|
|
|
|
} else if (this.props.room) {
|
|
|
|
roomName = this.props.room.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}>
|
2019-05-19 17:23:43 +03:00
|
|
|
<div dir="auto" className={textClasses} title={roomName}>{ roomName }</div>
|
2019-02-04 23:25:26 +03:00
|
|
|
{ searchStatus }
|
|
|
|
</div>;
|
|
|
|
|
|
|
|
let topic;
|
|
|
|
if (this.props.room) {
|
|
|
|
const ev = this.props.room.currentState.getStateEvents('m.room.topic', '');
|
|
|
|
if (ev) {
|
|
|
|
topic = ev.getContent().topic;
|
2016-03-29 17:21:16 +03:00
|
|
|
}
|
2016-03-29 14:51:46 +03:00
|
|
|
}
|
2019-02-04 23:25:26 +03:00
|
|
|
const topicElement =
|
2019-12-08 15:16:17 +03:00
|
|
|
<div className="mx_RoomHeader_topic" ref={this._topic} title={topic} dir="auto">{ topic }</div>;
|
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}
|
|
|
|
tag={DefaultTagID.Untagged} // to apply room publicity badging
|
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
|
|
|
|
2020-08-17 22:12:18 +03:00
|
|
|
if (this.props.onPinnedClick && SettingsStore.getValue('feature_pinning')) {
|
2017-11-04 05:00:48 +03:00
|
|
|
let pinsIndicator = null;
|
2017-10-16 06:17:43 +03:00
|
|
|
if (this._hasUnreadPins()) {
|
2017-11-04 05:00:48 +03:00
|
|
|
pinsIndicator = (<div className="mx_RoomHeader_pinsIndicator mx_RoomHeader_pinsIndicatorUnread" />);
|
|
|
|
} else if (this._hasPins()) {
|
|
|
|
pinsIndicator = (<div className="mx_RoomHeader_pinsIndicator" />);
|
2017-10-16 06:17:43 +03:00
|
|
|
}
|
2017-11-04 05:00:48 +03:00
|
|
|
|
2017-09-29 00:32:51 +03:00
|
|
|
pinnedEventsButton =
|
2020-07-17 20:16:21 +03:00
|
|
|
<AccessibleTooltipButton
|
|
|
|
className="mx_RoomHeader_button mx_RoomHeader_pinnedButton"
|
|
|
|
onClick={this.props.onPinnedClick}
|
|
|
|
title={_t("Pinned Messages")}
|
|
|
|
>
|
2017-11-04 05:00:48 +03:00
|
|
|
{ pinsIndicator }
|
2020-07-17 20:16:21 +03:00
|
|
|
</AccessibleTooltipButton>;
|
2017-09-29 00:32:51 +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
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-02-04 23:25:26 +03:00
|
|
|
const rightRow =
|
|
|
|
<div className="mx_RoomHeader_buttons">
|
|
|
|
{ pinnedEventsButton }
|
|
|
|
{ forgetButton }
|
|
|
|
{ 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 }
|
2019-12-06 03:47:18 +03:00
|
|
|
<RoomHeaderButtons />
|
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
|
|
|
}
|
|
|
|
}
|