2016-02-23 15:46:27 +00:00
|
|
|
/*
|
2020-10-30 17:29:32 +00:00
|
|
|
Copyright 2015, 2016, 2017, 2020 The Matrix.org Foundation C.I.C.
|
2016-02-23 15:46:27 +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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-05-30 16:09:57 +02:00
|
|
|
import React from 'react';
|
2021-06-18 16:22:31 +01:00
|
|
|
import { lexicographicCompare } from 'matrix-js-sdk/src/utils';
|
2021-06-29 13:11:58 +01:00
|
|
|
import { Room } from 'matrix-js-sdk/src/models/room';
|
2021-06-18 16:22:31 +01:00
|
|
|
|
|
|
|
|
import { MatrixClientPeg } from "../../../MatrixClientPeg";
|
|
|
|
|
import AppsDrawer from './AppsDrawer';
|
2018-12-24 15:09:10 +00:00
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
2020-03-28 00:51:01 +00:00
|
|
|
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
|
2021-06-16 12:07:58 +01:00
|
|
|
import { UIFeature } from "../../../settings/UIFeature";
|
2021-06-22 17:23:13 +01:00
|
|
|
import ResizeNotifier from "../../../utils/ResizeNotifier";
|
2020-12-03 17:45:49 +00:00
|
|
|
import CallViewForRoom from '../voip/CallViewForRoom';
|
2021-06-16 12:07:58 +01:00
|
|
|
import { objectHasDiff } from "../../../utils/objects";
|
|
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2021-07-01 18:35:38 +01:00
|
|
|
import { throttle } from 'lodash';
|
2017-05-30 16:09:57 +02:00
|
|
|
|
2020-10-30 17:29:32 +00:00
|
|
|
interface IProps {
|
|
|
|
|
// js-sdk room object
|
2021-07-01 23:23:03 +01:00
|
|
|
room: Room;
|
|
|
|
|
userId: string;
|
|
|
|
|
showApps: boolean; // Render apps
|
|
|
|
|
resizeNotifier: ResizeNotifier;
|
2020-10-30 17:29:32 +00:00
|
|
|
}
|
2016-03-08 12:16:34 +00:00
|
|
|
|
2020-10-30 17:29:32 +00:00
|
|
|
interface Counter {
|
2021-07-01 23:23:03 +01:00
|
|
|
title: string;
|
|
|
|
|
value: number;
|
|
|
|
|
link: string;
|
|
|
|
|
severity: string;
|
|
|
|
|
stateKey: string;
|
2020-10-30 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
2021-07-01 23:23:03 +01:00
|
|
|
counters: Counter[];
|
2020-10-30 17:29:32 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-08 20:12:00 -07:00
|
|
|
@replaceableComponent("views.rooms.AuxPanel")
|
2020-10-30 17:29:32 +00:00
|
|
|
export default class AuxPanel extends React.Component<IProps, IState> {
|
2020-08-29 12:14:16 +01:00
|
|
|
static defaultProps = {
|
2018-02-09 13:23:34 +00:00
|
|
|
showApps: true,
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
2018-02-09 13:23:34 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
2019-01-08 11:14:31 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
this.state = {
|
2021-06-16 12:07:58 +01:00
|
|
|
counters: this.computeCounters(),
|
2020-08-29 12:14:16 +01:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount() {
|
2018-12-24 14:27:50 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2021-06-16 12:06:41 +01:00
|
|
|
if (SettingsStore.getValue("feature_state_counters")) {
|
2021-06-16 12:07:58 +01:00
|
|
|
cli.on("RoomState.events", this.rateLimitedUpdate);
|
2021-06-16 12:06:41 +01:00
|
|
|
}
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2018-12-24 14:27:50 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
componentWillUnmount() {
|
2018-12-24 14:27:50 +00:00
|
|
|
const cli = MatrixClientPeg.get();
|
2021-06-16 12:06:41 +01:00
|
|
|
if (cli && SettingsStore.getValue("feature_state_counters")) {
|
2021-06-16 12:07:58 +01:00
|
|
|
cli.removeListener("RoomState.events", this.rateLimitedUpdate);
|
2018-12-24 14:27:50 +00:00
|
|
|
}
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2018-12-24 14:27:50 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
shouldComponentUpdate(nextProps, nextState) {
|
2021-02-19 00:00:10 +00:00
|
|
|
return objectHasDiff(this.props, nextProps) || objectHasDiff(this.state, nextState);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2016-03-08 12:16:34 +00:00
|
|
|
|
2021-07-01 18:35:38 +01:00
|
|
|
private rateLimitedUpdate = throttle(() => {
|
2021-06-16 12:07:58 +01:00
|
|
|
this.setState({ counters: this.computeCounters() });
|
2021-07-01 18:35:38 +01:00
|
|
|
}, 500, { leading: true, trailing: true });
|
2018-12-24 14:27:50 +00:00
|
|
|
|
2021-06-16 12:07:58 +01:00
|
|
|
private computeCounters() {
|
2020-10-30 17:29:32 +00:00
|
|
|
const counters = [];
|
2019-01-08 11:14:31 +00:00
|
|
|
|
2020-08-17 13:12:18 -06:00
|
|
|
if (this.props.room && SettingsStore.getValue("feature_state_counters")) {
|
2019-01-08 11:14:31 +00:00
|
|
|
const stateEvs = this.props.room.currentState.getStateEvents('re.jki.counter');
|
2021-06-18 16:22:31 +01:00
|
|
|
stateEvs.sort((a, b) => lexicographicCompare(a.getStateKey(), b.getStateKey()));
|
2019-01-08 11:14:31 +00:00
|
|
|
|
2020-10-30 17:29:32 +00:00
|
|
|
for (const ev of stateEvs) {
|
2019-01-08 11:14:31 +00:00
|
|
|
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();
|
|
|
|
|
|
2019-03-11 14:04:12 +00:00
|
|
|
// We want a non-empty title but can accept falsey values (e.g.
|
|
|
|
|
// zero)
|
|
|
|
|
if (title && value !== undefined) {
|
2019-01-08 11:14:31 +00:00
|
|
|
counters.push({
|
2020-10-30 17:29:32 +00:00
|
|
|
title,
|
|
|
|
|
value,
|
|
|
|
|
link,
|
|
|
|
|
severity,
|
|
|
|
|
stateKey,
|
2021-06-29 13:11:58 +01:00
|
|
|
});
|
2019-01-08 11:14:31 +00:00
|
|
|
}
|
2020-10-30 17:29:32 +00:00
|
|
|
}
|
2019-01-08 11:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return counters;
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
2019-01-08 11:14:31 +00:00
|
|
|
|
2020-08-29 12:14:16 +01:00
|
|
|
render() {
|
2017-05-17 21:15:57 +01:00
|
|
|
const callView = (
|
2020-12-03 17:45:49 +00:00
|
|
|
<CallViewForRoom
|
|
|
|
|
roomId={this.props.room.roomId}
|
2021-03-02 14:09:11 +01:00
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
2016-02-23 15:46:27 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
|
2020-09-16 11:38:50 +01:00
|
|
|
let appsDrawer;
|
|
|
|
|
if (SettingsStore.getValue(UIFeature.Widgets)) {
|
|
|
|
|
appsDrawer = <AppsDrawer
|
|
|
|
|
room={this.props.room}
|
|
|
|
|
userId={this.props.userId}
|
|
|
|
|
showApps={this.props.showApps}
|
|
|
|
|
resizeNotifier={this.props.resizeNotifier}
|
|
|
|
|
/>;
|
|
|
|
|
}
|
2017-05-17 21:15:57 +01:00
|
|
|
|
2018-12-24 14:27:50 +00:00
|
|
|
let stateViews = null;
|
2020-08-17 13:12:18 -06:00
|
|
|
if (this.state.counters && SettingsStore.getValue("feature_state_counters")) {
|
2020-09-16 11:38:50 +01:00
|
|
|
const counters = [];
|
2018-12-24 14:27:50 +00:00
|
|
|
|
2019-01-08 11:14:31 +00:00
|
|
|
this.state.counters.forEach((counter, idx) => {
|
|
|
|
|
const title = counter.title;
|
|
|
|
|
const value = counter.value;
|
|
|
|
|
const link = counter.link;
|
|
|
|
|
const severity = counter.severity;
|
|
|
|
|
const stateKey = counter.stateKey;
|
2018-12-24 14:27:50 +00:00
|
|
|
|
2020-09-16 11:38:50 +01:00
|
|
|
let span = <span>{ title }: { value }</span>;
|
2018-12-24 14:27:50 +00:00
|
|
|
|
2019-03-12 10:00:10 +00:00
|
|
|
if (link) {
|
2018-12-24 14:27:50 +00:00
|
|
|
span = (
|
2020-02-23 22:14:29 +00:00
|
|
|
<a href={link} target="_blank" rel="noreferrer noopener">
|
2019-03-12 10:00:10 +00:00
|
|
|
{ span }
|
|
|
|
|
</a>
|
2018-12-24 14:27:50 +00:00
|
|
|
);
|
|
|
|
|
}
|
2019-03-12 10:00:10 +00:00
|
|
|
|
|
|
|
|
span = (
|
|
|
|
|
<span
|
|
|
|
|
className="m_RoomView_auxPanel_stateViews_span"
|
|
|
|
|
data-severity={severity}
|
2021-07-19 22:43:11 +01:00
|
|
|
key={"x-" + stateKey}
|
2019-03-12 10:00:10 +00:00
|
|
|
>
|
2021-07-19 22:43:11 +01:00
|
|
|
{ span }
|
2019-03-12 10:00:10 +00:00
|
|
|
</span>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
counters.push(span);
|
|
|
|
|
counters.push(
|
|
|
|
|
<span
|
|
|
|
|
className="m_RoomView_auxPanel_stateViews_delim"
|
|
|
|
|
key={"delim" + idx}
|
2020-10-30 17:29:32 +00:00
|
|
|
> ─ </span>,
|
2019-03-12 10:00:10 +00:00
|
|
|
);
|
2018-12-24 14:27:50 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (counters.length > 0) {
|
|
|
|
|
counters.pop(); // remove last deliminator
|
|
|
|
|
stateViews = (
|
|
|
|
|
<div className="m_RoomView_auxPanel_stateViews">
|
|
|
|
|
{ counters }
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-23 15:46:27 +00:00
|
|
|
return (
|
2021-08-27 13:31:43 +02:00
|
|
|
<AutoHideScrollbar className="mx_RoomView_auxPanel">
|
2018-12-24 14:27:50 +00:00
|
|
|
{ stateViews }
|
2021-08-27 13:31:43 +02:00
|
|
|
{ this.props.children }
|
2017-05-17 21:15:57 +01:00
|
|
|
{ appsDrawer }
|
2016-02-23 15:46:27 +00:00
|
|
|
{ callView }
|
2020-03-28 00:51:01 +00:00
|
|
|
</AutoHideScrollbar>
|
2016-02-23 15:46:27 +00:00
|
|
|
);
|
2020-08-29 12:14:16 +01:00
|
|
|
}
|
|
|
|
|
}
|