2015-11-27 13:42:03 +03:00
|
|
|
/*
|
2016-01-07 07:06:39 +03:00
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
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';
|
2019-09-06 17:04:46 +03:00
|
|
|
import createReactClass from 'create-react-class';
|
2017-07-01 16:13:32 +03:00
|
|
|
import classNames from 'classnames';
|
|
|
|
import sdk from '../../../index';
|
2017-05-25 13:39:08 +03:00
|
|
|
import { _t } from '../../../languageHandler';
|
2017-07-01 16:13:32 +03:00
|
|
|
import MatrixClientPeg from '../../../MatrixClientPeg';
|
|
|
|
import Modal from "../../../Modal";
|
|
|
|
import RateLimitedFunc from '../../../ratelimitedfunc';
|
|
|
|
|
2019-02-01 00:35:58 +03:00
|
|
|
import { linkifyElement } from '../../../HtmlUtils';
|
2017-01-25 01:41:52 +03:00
|
|
|
import AccessibleButton from '../elements/AccessibleButton';
|
2017-08-09 13:44:24 +03:00
|
|
|
import ManageIntegsButton from '../elements/ManageIntegsButton';
|
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';
|
2016-01-11 15:46:12 +03:00
|
|
|
|
2019-09-06 17:04:46 +03:00
|
|
|
module.exports = createReactClass({
|
2015-11-27 13:42:03 +03:00
|
|
|
displayName: 'RoomHeader',
|
|
|
|
|
|
|
|
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,
|
2015-11-27 13:42:03 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
editing: false,
|
2017-05-11 19:35:06 +03:00
|
|
|
inRoom: false,
|
2017-09-12 17:48:13 +03:00
|
|
|
onCancelClick: null,
|
2015-11-27 13:42:03 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2019-12-08 15:16:17 +03:00
|
|
|
UNSAFE_componentWillMount: function() {
|
|
|
|
this._topic = createRef();
|
|
|
|
},
|
|
|
|
|
2016-03-29 18:31:13 +03:00
|
|
|
componentDidMount: function() {
|
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);
|
|
|
|
}
|
2016-03-29 18:31:13 +03:00
|
|
|
},
|
|
|
|
|
2016-01-11 15:46:12 +03:00
|
|
|
componentDidUpdate: function() {
|
2019-12-08 15:16:17 +03:00
|
|
|
if (this._topic.current) {
|
|
|
|
linkifyElement(this._topic.current);
|
2016-01-11 15:46:12 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-03-29 18:31:13 +03:00
|
|
|
componentWillUnmount: function() {
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_onRoomStateEvents: function(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();
|
2016-03-29 18:31:13 +03:00
|
|
|
},
|
|
|
|
|
2017-10-16 06:17:43 +03:00
|
|
|
_onRoomAccountData: function(event, room) {
|
|
|
|
if (!this.props.room || room.roomId !== this.props.room.roomId) return;
|
|
|
|
if (event.getType() !== "im.vector.room.read_pins") return;
|
|
|
|
|
|
|
|
this._rateLimitedUpdate();
|
|
|
|
},
|
|
|
|
|
2017-07-01 16:13:32 +03:00
|
|
|
_rateLimitedUpdate: new RateLimitedFunc(function() {
|
|
|
|
/* eslint-disable babel/no-invalid-this */
|
2016-10-26 15:09:53 +03:00
|
|
|
this.forceUpdate();
|
|
|
|
}, 500),
|
|
|
|
|
2016-04-15 11:59:23 +03:00
|
|
|
_onRoomNameChange: function(room) {
|
|
|
|
this.forceUpdate();
|
|
|
|
},
|
|
|
|
|
2018-06-12 13:15:00 +03:00
|
|
|
onShareRoomClick: function(ev) {
|
|
|
|
const ShareDialog = sdk.getComponent("dialogs.ShareDialog");
|
|
|
|
Modal.createTrackedDialog('share room dialog', '', ShareDialog, {
|
|
|
|
target: this.props.room,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2017-10-16 06:17:43 +03:00
|
|
|
_hasUnreadPins: function() {
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2017-11-04 05:00:48 +03:00
|
|
|
_hasPins: function() {
|
|
|
|
const currentPinEvent = this.props.room.currentState.getStateEvents("m.room.pinned_events", '');
|
|
|
|
if (!currentPinEvent) return false;
|
|
|
|
|
|
|
|
return !(currentPinEvent.getContent().pinned && currentPinEvent.getContent().pinned.length <= 0);
|
|
|
|
},
|
|
|
|
|
2015-11-27 13:42:03 +03:00
|
|
|
render: function() {
|
2017-07-01 16:13:32 +03:00
|
|
|
const RoomAvatar = sdk.getComponent("avatars.RoomAvatar");
|
2015-11-27 13:42:03 +03:00
|
|
|
|
2017-07-01 16:13:32 +03:00
|
|
|
let searchStatus = null;
|
|
|
|
let cancelButton = null;
|
|
|
|
let settingsButton = null;
|
2017-09-29 00:32:51 +03:00
|
|
|
let pinnedEventsButton = null;
|
2017-07-01 16:13:32 +03:00
|
|
|
|
2019-02-01 16:35:25 +03:00
|
|
|
const e2eIcon = this.props.e2eStatus ?
|
2019-03-13 15:58:23 +03:00
|
|
|
<E2EIcon status={this.props.e2eStatus} /> :
|
2019-02-01 16:35:25 +03:00
|
|
|
undefined;
|
2019-02-01 15:40:19 +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>;
|
2018-05-25 05:17:29 +03:00
|
|
|
const avatarSize = 28;
|
2019-02-08 20:35:49 +03:00
|
|
|
let roomAvatar;
|
|
|
|
if (this.props.room) {
|
|
|
|
roomAvatar = (<RoomAvatar
|
|
|
|
room={this.props.room}
|
|
|
|
width={avatarSize}
|
|
|
|
height={avatarSize}
|
|
|
|
oobData={this.props.oobData}
|
|
|
|
viewAvatarOnClick={true} />);
|
|
|
|
}
|
2015-11-27 13:42:03 +03:00
|
|
|
|
2016-07-13 18:02:18 +03:00
|
|
|
if (this.props.onSettingsClick) {
|
2017-07-01 16:13:32 +03:00
|
|
|
settingsButton =
|
2019-02-12 19:42:11 +03:00
|
|
|
<AccessibleButton className="mx_RoomHeader_button mx_RoomHeader_settingsButton"
|
|
|
|
onClick={this.props.onSettingsClick}
|
|
|
|
title={_t("Settings")}
|
|
|
|
>
|
2017-01-13 19:25:26 +03:00
|
|
|
</AccessibleButton>;
|
2016-07-13 18:02:18 +03:00
|
|
|
}
|
|
|
|
|
2017-10-29 05:21:34 +03:00
|
|
|
if (this.props.onPinnedClick && SettingsStore.isFeatureEnabled('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 =
|
2017-10-16 06:17:43 +03:00
|
|
|
<AccessibleButton className="mx_RoomHeader_button mx_RoomHeader_pinnedButton"
|
|
|
|
onClick={this.props.onPinnedClick} title={_t("Pinned Messages")}>
|
2017-11-04 05:00:48 +03:00
|
|
|
{ pinsIndicator }
|
2017-09-29 00:32:51 +03:00
|
|
|
</AccessibleButton>;
|
|
|
|
}
|
|
|
|
|
2016-08-10 18:34:49 +03:00
|
|
|
// var leave_button;
|
|
|
|
// if (this.props.onLeaveClick) {
|
|
|
|
// leave_button =
|
|
|
|
// <div className="mx_RoomHeader_button" onClick={this.props.onLeaveClick} title="Leave room">
|
2019-01-11 04:37:28 +03:00
|
|
|
// <TintableSvg src={require("../../../../res/img/leave.svg")} width="26" height="20"/>
|
2016-08-10 18:34:49 +03:00
|
|
|
// </div>;
|
|
|
|
// }
|
2015-12-16 19:06:29 +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 =
|
2019-02-12 19:42:11 +03:00
|
|
|
<AccessibleButton className="mx_RoomHeader_button mx_RoomHeader_forgetButton"
|
|
|
|
onClick={this.props.onForgetClick}
|
|
|
|
title={_t("Forget room")}
|
|
|
|
>
|
2017-01-13 19:25:26 +03:00
|
|
|
</AccessibleButton>;
|
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 =
|
2019-02-12 19:42:11 +03:00
|
|
|
<AccessibleButton className="mx_RoomHeader_button mx_RoomHeader_searchButton"
|
|
|
|
onClick={this.props.onSearchClick}
|
|
|
|
title={_t("Search")}
|
|
|
|
>
|
2017-05-11 19:35:06 +03:00
|
|
|
</AccessibleButton>;
|
|
|
|
}
|
|
|
|
|
2018-06-12 13:15:00 +03:00
|
|
|
let shareRoomButton;
|
|
|
|
if (this.props.inRoom) {
|
|
|
|
shareRoomButton =
|
2019-02-12 19:42:11 +03:00
|
|
|
<AccessibleButton className="mx_RoomHeader_button mx_RoomHeader_shareButton"
|
|
|
|
onClick={this.onShareRoomClick}
|
|
|
|
title={_t('Share room')}
|
|
|
|
>
|
2017-01-24 23:55:10 +03:00
|
|
|
</AccessibleButton>;
|
2016-04-15 20:45:40 +03:00
|
|
|
}
|
|
|
|
|
2017-08-17 20:10:50 +03:00
|
|
|
let manageIntegsButton;
|
2017-11-16 16:19:36 +03:00
|
|
|
if (this.props.room && this.props.room.roomId && this.props.inRoom) {
|
2017-08-17 20:10:50 +03:00
|
|
|
manageIntegsButton = <ManageIntegsButton
|
2018-02-09 14:44:27 +03:00
|
|
|
room={this.props.room}
|
2017-08-17 20:10:50 +03:00
|
|
|
/>;
|
|
|
|
}
|
2017-08-06 12:01:48 +03:00
|
|
|
|
2019-02-04 23:25:26 +03:00
|
|
|
const rightRow =
|
|
|
|
<div className="mx_RoomHeader_buttons">
|
|
|
|
{ settingsButton }
|
|
|
|
{ pinnedEventsButton }
|
|
|
|
{ shareRoomButton }
|
|
|
|
{ manageIntegsButton }
|
|
|
|
{ forgetButton }
|
|
|
|
{ searchButton }
|
|
|
|
</div>;
|
2016-01-10 15:56:45 +03:00
|
|
|
|
2015-11-27 13:42:03 +03:00
|
|
|
return (
|
2019-02-04 23:25:26 +03:00
|
|
|
<div className="mx_RoomHeader light-panel">
|
2017-07-01 16:13:32 +03:00
|
|
|
<div className="mx_RoomHeader_wrapper">
|
2018-10-23 17:57:56 +03:00
|
|
|
<div className="mx_RoomHeader_avatar">{ roomAvatar }</div>
|
2019-02-01 15:40:19 +03:00
|
|
|
{ e2eIcon }
|
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>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|