From 6775552ee96e28db0d08176a3f10ee603e62f79b Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 22 Nov 2023 10:22:11 +0100 Subject: [PATCH] Remove feature_state_counters Relates to: vector-im/element-web#25884 --- src/components/views/rooms/AuxPanel.tsx | 129 +----------------------- src/settings/Settings.tsx | 7 -- 2 files changed, 2 insertions(+), 134 deletions(-) diff --git a/src/components/views/rooms/AuxPanel.tsx b/src/components/views/rooms/AuxPanel.tsx index b1b04581edf2..340d91e7ef3a 100644 --- a/src/components/views/rooms/AuxPanel.tsx +++ b/src/components/views/rooms/AuxPanel.tsx @@ -16,10 +16,8 @@ limitations under the License. import React, { ReactNode } from "react"; import { lexicographicCompare } from "matrix-js-sdk/src/utils"; -import { Room, RoomStateEvent, MatrixEvent } from "matrix-js-sdk/src/matrix"; -import { throttle } from "lodash"; +import { Room } from "matrix-js-sdk/src/matrix"; -import { MatrixClientPeg } from "../../../MatrixClientPeg"; import AppsDrawer from "./AppsDrawer"; import SettingsStore from "../../../settings/SettingsStore"; import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; @@ -37,93 +35,17 @@ interface IProps { children?: ReactNode; } -interface Counter { - title: string; - value: number; - link: string; - severity: string; - stateKey: string; -} - -interface IState { - counters: Counter[]; -} +interface IState {} export default class AuxPanel extends React.Component { public static defaultProps = { showApps: true, }; - public constructor(props: IProps) { - super(props); - - this.state = { - counters: this.computeCounters(), - }; - } - - public componentDidMount(): void { - const cli = MatrixClientPeg.safeGet(); - if (SettingsStore.getValue("feature_state_counters")) { - cli.on(RoomStateEvent.Events, this.onRoomStateEvents); - } - } - - public componentWillUnmount(): void { - if (SettingsStore.getValue("feature_state_counters")) { - MatrixClientPeg.get()?.removeListener(RoomStateEvent.Events, this.onRoomStateEvents); - } - } - public shouldComponentUpdate(nextProps: IProps, nextState: IState): boolean { return objectHasDiff(this.props, nextProps) || objectHasDiff(this.state, nextState); } - private onRoomStateEvents = (ev: MatrixEvent): void => { - if (ev.getType() === "re.jki.counter") { - this.updateCounters(); - } - }; - - private updateCounters = throttle( - () => { - this.setState({ counters: this.computeCounters() }); - }, - 500, - { leading: true, trailing: true }, - ); - - private computeCounters(): Counter[] { - const counters: Counter[] = []; - - if (this.props.room && SettingsStore.getValue("feature_state_counters")) { - const stateEvs = this.props.room.currentState.getStateEvents("re.jki.counter"); - stateEvs.sort((a, b) => lexicographicCompare(a.getStateKey()!, b.getStateKey()!)); - - for (const ev of stateEvs) { - 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 falsy values (e.g. - // zero) - if (title && value !== undefined) { - counters.push({ - title, - value, - link, - severity, - stateKey, - }); - } - } - } - - return counters; - } - public render(): React.ReactNode { const callView = ( { ); } - let stateViews: JSX.Element | null = null; - if (this.state.counters && SettingsStore.getValue("feature_state_counters")) { - const counters: JSX.Element[] = []; - - 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; - - let span = ( - - {title}: {value} - - ); - - if (link) { - span = ( - - {span} - - ); - } - - span = ( - - {span} - - ); - - counters.push(span); - counters.push( - - {" "} - ─{" "} - , - ); - }); - - if (counters.length > 0) { - counters.pop(); // remove last deliminator - stateViews =
{counters}
; - } - } - return ( - {stateViews} {this.props.children} {appsDrawer} {callView} diff --git a/src/settings/Settings.tsx b/src/settings/Settings.tsx index 4f000f300c59..324a03ed1bbd 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -286,13 +286,6 @@ export const SETTINGS: { [setting: string]: ISetting } = { supportedLevels: LEVELS_FEATURE, default: false, }, - "feature_state_counters": { - isFeature: true, - labsGroup: LabGroup.Rooms, - displayName: _td("labs|state_counters"), - supportedLevels: LEVELS_FEATURE, - default: false, - }, "feature_mjolnir": { isFeature: true, labsGroup: LabGroup.Moderation,