From 1100ff87eea3a54144fa0d773adc8c6571bc1ab6 Mon Sep 17 00:00:00 2001 From: Germain Date: Mon, 31 Jul 2023 11:52:02 +0100 Subject: [PATCH 1/3] Deprecate lab experiment 'feature_state_counters' --- res/css/views/rooms/_AuxPanel.pcss | 37 ------- src/components/views/rooms/AuxPanel.tsx | 138 +----------------------- src/settings/Settings.tsx | 7 -- 3 files changed, 4 insertions(+), 178 deletions(-) diff --git a/res/css/views/rooms/_AuxPanel.pcss b/res/css/views/rooms/_AuxPanel.pcss index 38b93e414f3..80abbb1385e 100644 --- a/res/css/views/rooms/_AuxPanel.pcss +++ b/res/css/views/rooms/_AuxPanel.pcss @@ -20,41 +20,4 @@ limitations under the License. margin: 0px auto; overflow: auto; - - .mx_AuxPanel_stateViews { - padding: 5px; - padding-left: 19px; - border-bottom: 1px solid $primary-hairline-color; - } - - .mx_AuxPanel_stateViews_span { - &[data-severity="warning"] { - font-weight: bold; - color: orange; - } - - &[data-severity="alert"] { - font-weight: bold; - color: red; - } - - &[data-severity="normal"] { - font-weight: normal; - } - - &[data-severity="notice"] { - font-weight: normal; - color: $settings-grey-fg-color; - } - - a { - text-decoration: none; - color: inherit; - } - } - - .mx_AuxPanel_stateViews_delim { - padding: 0 5px; - color: $settings-grey-fg-color; - } } diff --git a/src/components/views/rooms/AuxPanel.tsx b/src/components/views/rooms/AuxPanel.tsx index 73002f484b1..0e736dbdda9 100644 --- a/src/components/views/rooms/AuxPanel.tsx +++ b/src/components/views/rooms/AuxPanel.tsx @@ -1,5 +1,5 @@ /* -Copyright 2015, 2016, 2017, 2020 The Matrix.org Foundation C.I.C. +Copyright 2015 - 2023 The Matrix.org Foundation C.I.C. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,13 +15,8 @@ limitations under the License. */ import React, { ReactNode } from "react"; -import { lexicographicCompare } from "matrix-js-sdk/src/utils"; import { Room } from "matrix-js-sdk/src/models/room"; -import { throttle } from "lodash"; -import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state"; -import { MatrixEvent } from "matrix-js-sdk/src/models/event"; -import { MatrixClientPeg } from "../../../MatrixClientPeg"; import AppsDrawer from "./AppsDrawer"; import SettingsStore from "../../../settings/SettingsStore"; import AutoHideScrollbar from "../../structures/AutoHideScrollbar"; @@ -39,91 +34,13 @@ interface IProps { children?: ReactNode; } -interface Counter { - title: string; - value: number; - link: string; - severity: string; - stateKey: string; -} - -interface IState { - counters: Counter[]; -} - -export default class AuxPanel extends React.Component { +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 shouldComponentUpdate(nextProps: IProps): boolean { + return objectHasDiff(this.props, nextProps); } public render(): React.ReactNode { @@ -147,55 +64,8 @@ export default class AuxPanel extends React.Component { ); } - 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 3f32d27d777..466a9f5b774 100644 --- a/src/settings/Settings.tsx +++ b/src/settings/Settings.tsx @@ -307,13 +307,6 @@ export const SETTINGS: { [setting: string]: ISetting } = { supportedLevels: LEVELS_FEATURE, default: false, }, - "feature_state_counters": { - isFeature: true, - labsGroup: LabGroup.Rooms, - displayName: _td("Render simple counters in room header"), - supportedLevels: LEVELS_FEATURE, - default: false, - }, "feature_mjolnir": { isFeature: true, labsGroup: LabGroup.Moderation, From 293c53b8b9c44ce521b1ae706d51761c6c956810 Mon Sep 17 00:00:00 2001 From: Germain Date: Mon, 31 Jul 2023 12:21:22 +0100 Subject: [PATCH 2/3] i18n --- src/i18n/strings/en_EN.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index a909a69fab4..6aad057e755 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -973,7 +973,6 @@ "Message Pinning": "Message Pinning", "Rich text editor": "Rich text editor", "Use rich text instead of Markdown in the message composer.": "Use rich text instead of Markdown in the message composer.", - "Render simple counters in room header": "Render simple counters in room header", "New ways to ignore people": "New ways to ignore people", "Currently experimental.": "Currently experimental.", "Support adding custom themes": "Support adding custom themes", From c5c26bcdcf068aab688488b8e31d722a5c1e531f Mon Sep 17 00:00:00 2001 From: Johannes Marbach Date: Wed, 22 Nov 2023 15:44:22 +0100 Subject: [PATCH 3/3] Regenerate strings --- src/i18n/strings/en_EN.json | 1 - 1 file changed, 1 deletion(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d9f472c2320..f15b90c8dd0 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1450,7 +1450,6 @@ "sliding_sync_server_no_support": "Your server lacks native support", "sliding_sync_server_specify_proxy": "Your server lacks native support, you must specify a proxy", "sliding_sync_server_support": "Your server has native support", - "state_counters": "Render simple counters in room header", "under_active_development": "Under active development.", "unrealiable_e2e": "Unreliable in encrypted rooms", "video_rooms": "Video rooms",