/* Copyright 2015, 2016 OpenMarket Ltd Copyright 2017 New Vector Ltd 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 PropTypes from 'prop-types'; import createReactClass from 'create-react-class'; import {MatrixClientPeg} from "../../../MatrixClientPeg"; import * as sdk from '../../../index'; import dis from "../../../dispatcher/dispatcher"; import * as ObjectUtils from '../../../ObjectUtils'; import AppsDrawer from './AppsDrawer'; import { _t } from '../../../languageHandler'; import classNames from 'classnames'; import RateLimitedFunc from '../../../ratelimitedfunc'; import SettingsStore from "../../../settings/SettingsStore"; import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; export default createReactClass({ displayName: 'AuxPanel', propTypes: { // js-sdk room object room: PropTypes.object.isRequired, userId: PropTypes.string.isRequired, showApps: PropTypes.bool, // Render apps hideAppsDrawer: PropTypes.bool, // Do not display apps drawer and content (may still be rendered) // Conference Handler implementation conferenceHandler: PropTypes.object, // set to true to show the file drop target draggingFile: PropTypes.bool, // set to true to show the 'active conf call' banner displayConfCallNotification: PropTypes.bool, // maxHeight attribute for the aux panel and the video // therein maxHeight: PropTypes.number, // a callback which is called when the content of the aux panel changes // content in a way that is likely to make it change size. onResize: PropTypes.func, fullHeight: PropTypes.bool, }, getDefaultProps: () => ({ showApps: true, hideAppsDrawer: false, }), getInitialState: function() { return { counters: this._computeCounters() }; }, componentDidMount: function() { const cli = MatrixClientPeg.get(); cli.on("RoomState.events", this._rateLimitedUpdate); }, componentWillUnmount: function() { const cli = MatrixClientPeg.get(); if (cli) { cli.removeListener("RoomState.events", this._rateLimitedUpdate); } }, shouldComponentUpdate: function(nextProps, nextState) { return (!ObjectUtils.shallowEqual(this.props, nextProps) || !ObjectUtils.shallowEqual(this.state, nextState)); }, componentDidUpdate: function(prevProps, prevState) { // most changes are likely to cause a resize if (this.props.onResize) { this.props.onResize(); } }, onConferenceNotificationClick: function(ev, type) { dis.dispatch({ action: 'place_call', type: type, room_id: this.props.room.roomId, }); ev.stopPropagation(); ev.preventDefault(); }, _rateLimitedUpdate: new RateLimitedFunc(function() { if (SettingsStore.isFeatureEnabled("feature_state_counters")) { this.setState({counters: this._computeCounters()}); } }, 500), _computeCounters: function() { let counters = []; if (this.props.room && SettingsStore.isFeatureEnabled("feature_state_counters")) { const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter'); stateEvs.sort((a, b) => { return a.getStateKey() < b.getStateKey(); }); stateEvs.forEach((ev, idx) => { const title = ev.getContent().title; const value = ev.getContent().value; const link = ev.getContent().link; const severity = ev.getContent().severity || "normal"; const stateKey = ev.getStateKey(); // We want a non-empty title but can accept falsey values (e.g. // zero) if (title && value !== undefined) { counters.push({ "title": title, "value": value, "link": link, "severity": severity, "stateKey": stateKey }) } }); } return counters; }, render: function() { const CallView = sdk.getComponent("voip.CallView"); const TintableSvg = sdk.getComponent("elements.TintableSvg"); let fileDropTarget = null; if (this.props.draggingFile) { fileDropTarget = (