From 8b36c6f3a01a2ca68e04d8007719646319691ddd Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 23 Aug 2022 10:57:56 +0100 Subject: [PATCH 01/10] Upgrade matrix-js-sdk to 19.4.0-rc.1 --- package.json | 2 +- yarn.lock | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a34cc60ad8..ed2dba8797 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "maplibre-gl": "^1.15.2", "matrix-encrypt-attachment": "^1.0.3", "matrix-events-sdk": "^0.0.1-beta.7", - "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", + "matrix-js-sdk": "19.4.0-rc.1", "matrix-widget-api": "^1.0.0", "minimist": "^1.2.5", "opus-recorder": "^8.0.3", diff --git a/yarn.lock b/yarn.lock index 973a5c586d..1c68fc5436 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6786,9 +6786,10 @@ matrix-events-sdk@^0.0.1-beta.7: resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.7.tgz#5ffe45eba1f67cc8d7c2377736c728b322524934" integrity sha512-9jl4wtWanUFSy2sr2lCjErN/oC8KTAtaeaozJtrgot1JiQcEI4Rda9OLgQ7nLKaqb4Z/QUx/fR3XpDzm5Jy1JA== -"matrix-js-sdk@github:matrix-org/matrix-js-sdk#develop": - version "19.3.0" - resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/566b4ba56c587578fcf4f32af003528291c77365" +matrix-js-sdk@19.4.0-rc.1: + version "19.4.0-rc.1" + resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.4.0-rc.1.tgz#3116d6ad4d09d934aae5c40f968b44bfe472def8" + integrity sha512-Hl6MvaUgqD5SMhbAtUk/3c+1yEBby0HYv6ddmB7LYOK2cBm0dncRPsdJ2o/iXFNKH5KpJlSCKwZtoRHZqIHucQ== dependencies: "@babel/runtime" "^7.12.5" another-json "^0.2.0" From 70ee5caaf6e88e5fc0f6a81fcb16a346d7349680 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 23 Aug 2022 11:00:37 +0100 Subject: [PATCH 02/10] Prepare changelog for v3.53.0-rc.1 --- CHANGELOG.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6b8e22f01..ff45838ce5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,37 @@ +Changes in [3.53.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.53.0-rc.1) (2022-08-23) +=============================================================================================================== + +## ✨ Features + * Ignore unreads in low priority rooms in the space panel ([\#6518](https://github.com/matrix-org/matrix-react-sdk/pull/6518)). Fixes vector-im/element-web#16836. + * Release message right-click context menu out of labs ([\#8613](https://github.com/matrix-org/matrix-react-sdk/pull/8613)). + * Device manager - expandable session details in device list ([\#9188](https://github.com/matrix-org/matrix-react-sdk/pull/9188)). + * Device manager - device list filtering ([\#9181](https://github.com/matrix-org/matrix-react-sdk/pull/9181)). + * Device manager - add verification details to session details ([\#9187](https://github.com/matrix-org/matrix-react-sdk/pull/9187)). + * Device manager - current session expandable details ([\#9185](https://github.com/matrix-org/matrix-react-sdk/pull/9185)). + * Device manager - security recommendations section ([\#9179](https://github.com/matrix-org/matrix-react-sdk/pull/9179)). + * The Welcome Home Screen: Return Button ([\#9089](https://github.com/matrix-org/matrix-react-sdk/pull/9089)). Fixes vector-im/element-web#22917. + * Device manager - label devices as inactive ([\#9175](https://github.com/matrix-org/matrix-react-sdk/pull/9175)). + * Device manager - other sessions list ([\#9155](https://github.com/matrix-org/matrix-react-sdk/pull/9155)). + * Implement MSC3846: Allowing widgets to access TURN servers ([\#9061](https://github.com/matrix-org/matrix-react-sdk/pull/9061)). + * Allow widgets to send/receive to-device messages ([\#8885](https://github.com/matrix-org/matrix-react-sdk/pull/8885)). + +## πŸ› Bug Fixes + * Reduce amount of requests done by the onboarding task list ([\#9194](https://github.com/matrix-org/matrix-react-sdk/pull/9194)). Fixes vector-im/element-web#23085. + * Avoid hardcoding branding in user onboarding ([\#9206](https://github.com/matrix-org/matrix-react-sdk/pull/9206)). Fixes vector-im/element-web#23111. + * End jitsi call when member is banned ([\#8879](https://github.com/matrix-org/matrix-react-sdk/pull/8879)). Contributed by @maheichyk. + * Fix context menu being opened when clicking message action bar buttons ([\#9200](https://github.com/matrix-org/matrix-react-sdk/pull/9200)). Fixes vector-im/element-web#22279 and vector-im/element-web#23100. + * Add gap between checkbox and text in report dialog following the same pattern (8px) used in the gap between the two buttons. It fixes vector-im/element-web#23060 ([\#9195](https://github.com/matrix-org/matrix-react-sdk/pull/9195)). Contributed by @gefgu. + * Fix url preview AXE and layout issue & add percy test ([\#9189](https://github.com/matrix-org/matrix-react-sdk/pull/9189)). Fixes vector-im/element-web#23083. + * Wrap long space names ([\#9201](https://github.com/matrix-org/matrix-react-sdk/pull/9201)). Fixes vector-im/element-web#23095. + * Attempt to fix `Failed to execute 'removeChild' on 'Node'` ([\#9196](https://github.com/matrix-org/matrix-react-sdk/pull/9196)). + * Fix soft crash around space hierarchy changing between spaces ([\#9191](https://github.com/matrix-org/matrix-react-sdk/pull/9191)). Fixes matrix-org/element-web-rageshakes#14613. + * Fix soft crash around room view store metrics ([\#9190](https://github.com/matrix-org/matrix-react-sdk/pull/9190)). Fixes matrix-org/element-web-rageshakes#14361. + * Fix the same person appearing multiple times when searching for them. ([\#9177](https://github.com/matrix-org/matrix-react-sdk/pull/9177)). Fixes vector-im/element-web#22851. + * Fix space panel subspace indentation going missing ([\#9167](https://github.com/matrix-org/matrix-react-sdk/pull/9167)). Fixes vector-im/element-web#23049. + * Fix invisible power levels tile when showing hidden events ([\#9162](https://github.com/matrix-org/matrix-react-sdk/pull/9162)). Fixes vector-im/element-web#23013. + * Space panel accessibility improvements ([\#9157](https://github.com/matrix-org/matrix-react-sdk/pull/9157)). Fixes vector-im/element-web#22995. + * Fix inverted logic for showing UserWelcomeTop component ([\#9164](https://github.com/matrix-org/matrix-react-sdk/pull/9164)). Fixes vector-im/element-web#23037. + Changes in [3.52.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0) (2022-08-16) ===================================================================================================== From 0a0a46c1316f52312e0f1611eed4cfa7e48c1f40 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 23 Aug 2022 11:00:38 +0100 Subject: [PATCH 03/10] v3.53.0-rc.1 --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index ed2dba8797..de20deb03e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.52.0", + "version": "3.53.0-rc.1", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": { @@ -23,7 +23,7 @@ "package.json", ".stylelintrc.js" ], - "main": "./src/index.ts", + "main": "./lib/index.ts", "matrix_src_main": "./src/index.ts", "matrix_lib_main": "./lib/index.ts", "matrix_lib_typings": "./lib/index.d.ts", @@ -252,5 +252,6 @@ "jestSonar": { "reportPath": "coverage", "sonar56x": true - } + }, + "typings": "./lib/index.d.ts" } From 877fa9c5c4052df95c1dd9aefa2e1adad362c242 Mon Sep 17 00:00:00 2001 From: ElementRobot Date: Thu, 25 Aug 2022 16:47:48 +0100 Subject: [PATCH 04/10] Fix progress bar regression throughout the app (#9219) (#9221) * Fix useSmoothAnimation enablement not working properly by getting rid of it Passing duration=0 is more logical and less superfluous * Refactor UploadBar to handle state more correctly * Change ProgressBar to new useSmoothAnimation signature and default animated to true for consistency * Add type guard * Make types stricter * Write tests for the ProgressBar component * Make the new test conform to tsc --strict * Update UploadBar.tsx * Update UploadBar.tsx * Update UploadBar.tsx (cherry picked from commit 9b99c967f4d65e3446a18a677fa4010612958d90) Co-authored-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/structures/UploadBar.tsx | 75 ++++++++++++------- src/components/views/elements/ProgressBar.tsx | 4 +- src/dispatcher/payloads/UploadPayload.ts | 2 +- src/hooks/useSmoothAnimation.ts | 8 +- .../views/elements/ProgressBar-test.tsx | 53 +++++++++++++ 5 files changed, 105 insertions(+), 37 deletions(-) create mode 100644 test/components/views/elements/ProgressBar-test.tsx diff --git a/src/components/structures/UploadBar.tsx b/src/components/structures/UploadBar.tsx index e3dc77a466..b2c7544f1f 100644 --- a/src/components/structures/UploadBar.tsx +++ b/src/components/structures/UploadBar.tsx @@ -17,17 +17,19 @@ limitations under the License. import React from 'react'; import { Room } from "matrix-js-sdk/src/models/room"; import filesize from "filesize"; -import { IEventRelation } from 'matrix-js-sdk/src/matrix'; +import { IAbortablePromise, IEventRelation } from 'matrix-js-sdk/src/matrix'; +import { Optional } from "matrix-events-sdk"; import ContentMessages from '../../ContentMessages'; import dis from "../../dispatcher/dispatcher"; import { _t } from '../../languageHandler'; -import { ActionPayload } from "../../dispatcher/payloads"; import { Action } from "../../dispatcher/actions"; import ProgressBar from "../views/elements/ProgressBar"; -import AccessibleButton from "../views/elements/AccessibleButton"; +import AccessibleButton, { ButtonEvent } from "../views/elements/AccessibleButton"; import { IUpload } from "../../models/IUpload"; import MatrixClientContext from "../../contexts/MatrixClientContext"; +import { ActionPayload } from '../../dispatcher/payloads'; +import { UploadPayload } from "../../dispatcher/payloads/UploadPayload"; interface IProps { room: Room; @@ -35,23 +37,35 @@ interface IProps { } interface IState { - currentUpload?: IUpload; - uploadsHere: IUpload[]; + currentFile?: string; + currentPromise?: IAbortablePromise; + currentLoaded?: number; + currentTotal?: number; + countFiles: number; } -export default class UploadBar extends React.Component { +function isUploadPayload(payload: ActionPayload): payload is UploadPayload { + return [ + Action.UploadStarted, + Action.UploadProgress, + Action.UploadFailed, + Action.UploadFinished, + Action.UploadCanceled, + ].includes(payload.action as Action); +} + +export default class UploadBar extends React.PureComponent { static contextType = MatrixClientContext; - private dispatcherRef: string; - private mounted: boolean; + private dispatcherRef: Optional; + private mounted = false; constructor(props) { super(props); // Set initial state to any available upload in this room - we might be mounting // earlier than the first progress event, so should show something relevant. - const uploadsHere = this.getUploadsInRoom(); - this.state = { currentUpload: uploadsHere[0], uploadsHere }; + this.state = this.calculateState(); } componentDidMount() { @@ -61,7 +75,7 @@ export default class UploadBar extends React.Component { componentWillUnmount() { this.mounted = false; - dis.unregister(this.dispatcherRef); + dis.unregister(this.dispatcherRef!); } private getUploadsInRoom(): IUpload[] { @@ -69,45 +83,48 @@ export default class UploadBar extends React.Component { return uploads.filter(u => u.roomId === this.props.room.roomId); } + private calculateState(): IState { + const [currentUpload, ...otherUploads] = this.getUploadsInRoom(); + return { + currentFile: currentUpload?.fileName, + currentPromise: currentUpload?.promise, + currentLoaded: currentUpload?.loaded, + currentTotal: currentUpload?.total, + countFiles: otherUploads.length + 1, + }; + } + private onAction = (payload: ActionPayload) => { - switch (payload.action) { - case Action.UploadStarted: - case Action.UploadProgress: - case Action.UploadFinished: - case Action.UploadCanceled: - case Action.UploadFailed: { - if (!this.mounted) return; - const uploadsHere = this.getUploadsInRoom(); - this.setState({ currentUpload: uploadsHere[0], uploadsHere }); - break; - } + if (!this.mounted) return; + if (isUploadPayload(payload)) { + this.setState(this.calculateState()); } }; - private onCancelClick = (ev) => { + private onCancelClick = (ev: ButtonEvent) => { ev.preventDefault(); - ContentMessages.sharedInstance().cancelUpload(this.state.currentUpload.promise, this.context); + ContentMessages.sharedInstance().cancelUpload(this.state.currentPromise!, this.context); }; render() { - if (!this.state.currentUpload) { + if (!this.state.currentFile) { return null; } // MUST use var name 'count' for pluralization to kick in const uploadText = _t( "Uploading %(filename)s and %(count)s others", { - filename: this.state.currentUpload.fileName, - count: this.state.uploadsHere.length - 1, + filename: this.state.currentFile, + count: this.state.countFiles - 1, }, ); - const uploadSize = filesize(this.state.currentUpload.total); + const uploadSize = filesize(this.state.currentTotal!); return (
{ uploadText } ({ uploadSize })
- +
); } diff --git a/src/components/views/elements/ProgressBar.tsx b/src/components/views/elements/ProgressBar.tsx index af06f579ea..2759846ffe 100644 --- a/src/components/views/elements/ProgressBar.tsx +++ b/src/components/views/elements/ProgressBar.tsx @@ -25,10 +25,10 @@ interface IProps { } const PROGRESS_BAR_ANIMATION_DURATION = 300; -const ProgressBar: React.FC = ({ value, max, animated }) => { +const ProgressBar: React.FC = ({ value, max, animated = true }) => { // Animating progress bars via CSS transition isn’t possible in all of our supported browsers yet. // As workaround, we’re using animations through JS requestAnimationFrame - const currentValue = useSmoothAnimation(0, value, PROGRESS_BAR_ANIMATION_DURATION, animated); + const currentValue = useSmoothAnimation(0, value, animated ? PROGRESS_BAR_ANIMATION_DURATION : 0); return ; }; diff --git a/src/dispatcher/payloads/UploadPayload.ts b/src/dispatcher/payloads/UploadPayload.ts index 023bd5403c..7db4a4a4d7 100644 --- a/src/dispatcher/payloads/UploadPayload.ts +++ b/src/dispatcher/payloads/UploadPayload.ts @@ -18,7 +18,7 @@ import { ActionPayload } from "../payloads"; import { Action } from "../actions"; import { IUpload } from "../../models/IUpload"; -interface UploadPayload extends ActionPayload { +export interface UploadPayload extends ActionPayload { /** * The upload with fields representing the new upload state. */ diff --git a/src/hooks/useSmoothAnimation.ts b/src/hooks/useSmoothAnimation.ts index 8d652f3257..743018aba8 100644 --- a/src/hooks/useSmoothAnimation.ts +++ b/src/hooks/useSmoothAnimation.ts @@ -30,14 +30,12 @@ const debuglog = (...args: any[]) => { * Utility function to smoothly animate to a certain target value * @param initialValue Initial value to be used as initial starting point * @param targetValue Desired value to animate to (can be changed repeatedly to whatever is current at that time) - * @param duration Duration that each animation should take - * @param enabled Whether the animation should run or not + * @param duration Duration that each animation should take, specify 0 to skip animating */ export function useSmoothAnimation( initialValue: number, targetValue: number, duration: number, - enabled: boolean, ): number { const state = useRef<{ timestamp: DOMHighResTimeStamp | null, value: number }>({ timestamp: null, @@ -79,7 +77,7 @@ export function useSmoothAnimation( [currentStepSize, targetValue], ); - useAnimation(enabled, update); + useAnimation(duration > 0, update); - return currentValue; + return duration > 0 ? currentValue : targetValue; } diff --git a/test/components/views/elements/ProgressBar-test.tsx b/test/components/views/elements/ProgressBar-test.tsx new file mode 100644 index 0000000000..320304fb76 --- /dev/null +++ b/test/components/views/elements/ProgressBar-test.tsx @@ -0,0 +1,53 @@ +/* +Copyright 2022 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. +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 { act, render } from "@testing-library/react"; + +import ProgressBar from "../../../../src/components/views/elements/ProgressBar"; + +jest.useFakeTimers(); + +describe("", () => { + it("works when animated", () => { + const { container, rerender } = render(); + const progress = container.querySelector("progress")!; + + // The animation always starts from 0 + expect(progress.value).toBe(0); + + // Await the animation to conclude to our initial value of 50 + act(() => { jest.runAllTimers(); }); + expect(progress.position).toBe(0.5); + + // Move the needle to 80% + rerender(); + expect(progress.position).toBe(0.5); + + // Let the animaiton run a tiny bit, assert it has moved from where it was to where it needs to go + act(() => { jest.advanceTimersByTime(150); }); + expect(progress.position).toBeGreaterThan(0.5); + expect(progress.position).toBeLessThan(0.8); + }); + + it("works when not animated", () => { + const { container, rerender } = render(); + const progress = container.querySelector("progress")!; + + // Without animation all positional updates are immediate, not requiring timers to run + expect(progress.position).toBe(0.5); + rerender(); + expect(progress.position).toBe(0.8); + }); +}); From e55d65327ffc59ab90ce50801e46529d0d0c02cb Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Thu, 25 Aug 2022 16:50:13 +0100 Subject: [PATCH 05/10] Prepare changelog for v3.53.0-rc.2 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff45838ce5..0339384d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Changes in [3.53.0-rc.2](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.53.0-rc.2) (2022-08-25) +=============================================================================================================== + +## πŸ› Bug Fixes + * Fix progress bar regression throughout the app ([\#9219](https://github.com/matrix-org/matrix-react-sdk/pull/9219)). Fixes vector-im/element-web#23121. + Changes in [3.53.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.53.0-rc.1) (2022-08-23) =============================================================================================================== From aace3a8c28ee95935d9f56b08a4504d84c979d95 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Thu, 25 Aug 2022 16:50:13 +0100 Subject: [PATCH 06/10] v3.53.0-rc.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index de20deb03e..54d48fba2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.53.0-rc.1", + "version": "3.53.0-rc.2", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": { From 37a527c61f7d42cc1359f1b8a783f0c85e8cbe80 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 29 Aug 2022 17:02:24 -0600 Subject: [PATCH 07/10] Convert several internal maps to real maps --- .../views/messages/MessageEvent.tsx | 67 +++++++++++-------- src/events/EventTileFactory.tsx | 67 +++++++++---------- 2 files changed, 71 insertions(+), 63 deletions(-) diff --git a/src/components/views/messages/MessageEvent.tsx b/src/components/views/messages/MessageEvent.tsx index 840f2c79f1..d2d207eec3 100644 --- a/src/components/views/messages/MessageEvent.tsx +++ b/src/components/views/messages/MessageEvent.tsx @@ -59,11 +59,30 @@ export interface IOperableEventTile { getEventTileOps(): IEventTileOps; } +const baseBodyTypes = new Map([ + [MsgType.Text, TextualBody], + [MsgType.Notice, TextualBody], + [MsgType.Emote, TextualBody], + [MsgType.Image, MImageBody], + [MsgType.File, MFileBody], + [MsgType.Audio, MVoiceOrAudioBody], + [MsgType.Video, MVideoBody], +]); +const baseEvTypes = new Map>>([ + [EventType.Sticker, MStickerBody], + [M_POLL_START.name, MPollBody], + [M_POLL_START.altName, MPollBody], + [M_BEACON_INFO.name, MBeaconBody], + [M_BEACON_INFO.altName, MBeaconBody], +]); + export default class MessageEvent extends React.Component implements IMediaBody, IOperableEventTile { private body: React.RefObject = createRef(); private mediaHelper: MediaEventHelper; + private bodyTypes = new Map(baseBodyTypes.entries()); + private evTypes = new Map>>(baseEvTypes.entries()); - static contextType = MatrixClientContext; + public static contextType = MatrixClientContext; public context!: React.ContextType; public constructor(props: IProps, context: React.ContextType) { @@ -72,6 +91,8 @@ export default class MessageEvent extends React.Component implements IMe if (MediaEventHelper.isEligible(this.props.mxEvent)) { this.mediaHelper = new MediaEventHelper(this.props.mxEvent); } + + this.updateComponentMaps(); } public componentDidMount(): void { @@ -88,32 +109,20 @@ export default class MessageEvent extends React.Component implements IMe this.mediaHelper?.destroy(); this.mediaHelper = new MediaEventHelper(this.props.mxEvent); } + + this.updateComponentMaps(); } - private get bodyTypes(): Record { - return { - [MsgType.Text]: TextualBody, - [MsgType.Notice]: TextualBody, - [MsgType.Emote]: TextualBody, - [MsgType.Image]: MImageBody, - [MsgType.File]: MFileBody, - [MsgType.Audio]: MVoiceOrAudioBody, - [MsgType.Video]: MVideoBody, + private updateComponentMaps() { + this.bodyTypes = new Map(baseBodyTypes.entries()); + for (const [bodyType, bodyComponent] of Object.entries(this.props.overrideBodyTypes ?? {})) { + this.bodyTypes.set(bodyType, bodyComponent); + } - ...(this.props.overrideBodyTypes || {}), - }; - } - - private get evTypes(): Record>> { - return { - [EventType.Sticker]: MStickerBody, - [M_POLL_START.name]: MPollBody, - [M_POLL_START.altName]: MPollBody, - [M_BEACON_INFO.name]: MBeaconBody, - [M_BEACON_INFO.altName]: MBeaconBody, - - ...(this.props.overrideEventTypes || {}), - }; + this.evTypes = new Map>>(baseEvTypes.entries()); + for (const [evType, evComponent] of Object.entries(this.props.overrideEventTypes ?? {})) { + this.evTypes.set(evType, evComponent); + } } public getEventTileOps = () => { @@ -143,13 +152,13 @@ export default class MessageEvent extends React.Component implements IMe let BodyType: React.ComponentType> | ReactAnyComponent = RedactedBody; if (!this.props.mxEvent.isRedacted()) { // only resolve BodyType if event is not redacted - if (type && this.evTypes[type]) { - BodyType = this.evTypes[type]; - } else if (msgtype && this.bodyTypes[msgtype]) { - BodyType = this.bodyTypes[msgtype]; + if (type && this.evTypes.has(type)) { + BodyType = this.evTypes.get(type); + } else if (msgtype && this.bodyTypes.has(msgtype)) { + BodyType = this.bodyTypes.get(msgtype); } else if (content.url) { // Fallback to MFileBody if there's a content URL - BodyType = this.bodyTypes[MsgType.File]; + BodyType = this.bodyTypes.get(MsgType.File); } else { // Fallback to UnknownBody otherwise if not redacted BodyType = UnknownBody; diff --git a/src/events/EventTileFactory.tsx b/src/events/EventTileFactory.tsx index 88982b373f..a12807de47 100644 --- a/src/events/EventTileFactory.tsx +++ b/src/events/EventTileFactory.tsx @@ -67,7 +67,6 @@ export interface EventTileTypeProps { type FactoryProps = Omit; type Factory = (ref: Optional>, props: X) => JSX.Element; -type FactoryMap = Record; const MessageEventFactory: Factory = (ref, props) => ; const KeyVerificationConclFactory: Factory = (ref, props) => ; @@ -82,40 +81,40 @@ const HiddenEventFactory: Factory = (ref, props) => ; export const JSONEventFactory: Factory = (ref, props) => ; -const EVENT_TILE_TYPES: FactoryMap = { - [EventType.RoomMessage]: MessageEventFactory, // note that verification requests are handled in pickFactory() - [EventType.Sticker]: MessageEventFactory, - [M_POLL_START.name]: MessageEventFactory, - [M_POLL_START.altName]: MessageEventFactory, - [EventType.KeyVerificationCancel]: KeyVerificationConclFactory, - [EventType.KeyVerificationDone]: KeyVerificationConclFactory, - [EventType.CallInvite]: CallEventFactory, // note that this requires a special factory type -}; +const EVENT_TILE_TYPES = new Map([ + [EventType.RoomMessage, MessageEventFactory], // note that verification requests are handled in pickFactory() + [EventType.Sticker, MessageEventFactory], + [M_POLL_START.name, MessageEventFactory], + [M_POLL_START.altName, MessageEventFactory], + [EventType.KeyVerificationCancel, KeyVerificationConclFactory], + [EventType.KeyVerificationDone, KeyVerificationConclFactory], + [EventType.CallInvite, CallEventFactory], // note that this requires a special factory type +]); -const STATE_EVENT_TILE_TYPES: FactoryMap = { - [EventType.RoomEncryption]: (ref, props) => , - [EventType.RoomCanonicalAlias]: TextualEventFactory, - [EventType.RoomCreate]: (ref, props) => , - [EventType.RoomMember]: TextualEventFactory, - [EventType.RoomName]: TextualEventFactory, - [EventType.RoomAvatar]: (ref, props) => , - [EventType.RoomThirdPartyInvite]: TextualEventFactory, - [EventType.RoomHistoryVisibility]: TextualEventFactory, - [EventType.RoomTopic]: TextualEventFactory, - [EventType.RoomPowerLevels]: TextualEventFactory, - [EventType.RoomPinnedEvents]: TextualEventFactory, - [EventType.RoomServerAcl]: TextualEventFactory, +const STATE_EVENT_TILE_TYPES = new Map([ + [EventType.RoomEncryption, (ref, props) => ], + [EventType.RoomCanonicalAlias, TextualEventFactory], + [EventType.RoomCreate, (ref, props) => ], + [EventType.RoomMember, TextualEventFactory], + [EventType.RoomName, TextualEventFactory], + [EventType.RoomAvatar, (ref, props) => ], + [EventType.RoomThirdPartyInvite, TextualEventFactory], + [EventType.RoomHistoryVisibility, TextualEventFactory], + [EventType.RoomTopic, TextualEventFactory], + [EventType.RoomPowerLevels, TextualEventFactory], + [EventType.RoomPinnedEvents, TextualEventFactory], + [EventType.RoomServerAcl, TextualEventFactory], // TODO: Enable support for m.widget event type (https://github.com/vector-im/element-web/issues/13111) - 'im.vector.modular.widgets': TextualEventFactory, // note that Jitsi widgets are special in pickFactory() - [WIDGET_LAYOUT_EVENT_TYPE]: TextualEventFactory, - [EventType.RoomTombstone]: TextualEventFactory, - [EventType.RoomJoinRules]: TextualEventFactory, - [EventType.RoomGuestAccess]: TextualEventFactory, -}; + ['im.vector.modular.widgets', TextualEventFactory], // note that Jitsi widgets are special in pickFactory() + [WIDGET_LAYOUT_EVENT_TYPE, TextualEventFactory], + [EventType.RoomTombstone, TextualEventFactory], + [EventType.RoomJoinRules, TextualEventFactory], + [EventType.RoomGuestAccess, TextualEventFactory], +]); // Add all the Mjolnir stuff to the renderer too for (const evType of ALL_RULE_TYPES) { - STATE_EVENT_TILE_TYPES[evType] = TextualEventFactory; + STATE_EVENT_TILE_TYPES.set(evType, TextualEventFactory); } // These events should be recorded in the STATE_EVENT_TILE_TYPES @@ -225,11 +224,11 @@ export function pickFactory( return noEventFactoryFactory(); // improper event type to render } - if (STATE_EVENT_TILE_TYPES[evType] === TextualEventFactory && !hasText(mxEvent, showHiddenEvents)) { + if (STATE_EVENT_TILE_TYPES.get(evType) === TextualEventFactory && !hasText(mxEvent, showHiddenEvents)) { return noEventFactoryFactory(); } - return STATE_EVENT_TILE_TYPES[evType] ?? noEventFactoryFactory(); + return STATE_EVENT_TILE_TYPES.get(evType) ?? noEventFactoryFactory(); } // Blanket override for all events. The MessageEvent component handles redacted states for us. @@ -241,7 +240,7 @@ export function pickFactory( return noEventFactoryFactory(); } - return EVENT_TILE_TYPES[evType] ?? noEventFactoryFactory(); + return EVENT_TILE_TYPES.get(evType) ?? noEventFactoryFactory(); } /** @@ -391,7 +390,7 @@ export function haveRendererForEvent(mxEvent: MatrixEvent, showHiddenEvents: boo if (!handler) return false; if (handler === TextualEventFactory) { return hasText(mxEvent, showHiddenEvents); - } else if (handler === STATE_EVENT_TILE_TYPES[EventType.RoomCreate]) { + } else if (handler === STATE_EVENT_TILE_TYPES.get(EventType.RoomCreate)) { return Boolean(mxEvent.getContent()['predecessor']); } else if (handler === JSONEventFactory) { return false; From c88a4bfad9b02b220fef4e9a0d893f94feb3a6df Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 31 Aug 2022 16:28:09 +0100 Subject: [PATCH 08/10] Upgrade matrix-js-sdk to 19.4.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 54d48fba2d..eee8d32adc 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "maplibre-gl": "^1.15.2", "matrix-encrypt-attachment": "^1.0.3", "matrix-events-sdk": "^0.0.1-beta.7", - "matrix-js-sdk": "19.4.0-rc.1", + "matrix-js-sdk": "19.4.0", "matrix-widget-api": "^1.0.0", "minimist": "^1.2.5", "opus-recorder": "^8.0.3", diff --git a/yarn.lock b/yarn.lock index 1c68fc5436..7eba11e478 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6786,10 +6786,10 @@ matrix-events-sdk@^0.0.1-beta.7: resolved "https://registry.yarnpkg.com/matrix-events-sdk/-/matrix-events-sdk-0.0.1-beta.7.tgz#5ffe45eba1f67cc8d7c2377736c728b322524934" integrity sha512-9jl4wtWanUFSy2sr2lCjErN/oC8KTAtaeaozJtrgot1JiQcEI4Rda9OLgQ7nLKaqb4Z/QUx/fR3XpDzm5Jy1JA== -matrix-js-sdk@19.4.0-rc.1: - version "19.4.0-rc.1" - resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.4.0-rc.1.tgz#3116d6ad4d09d934aae5c40f968b44bfe472def8" - integrity sha512-Hl6MvaUgqD5SMhbAtUk/3c+1yEBby0HYv6ddmB7LYOK2cBm0dncRPsdJ2o/iXFNKH5KpJlSCKwZtoRHZqIHucQ== +matrix-js-sdk@19.4.0: + version "19.4.0" + resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.4.0.tgz#ea333ec3b7893ea953bd1ac00c0ce1108fffc0d0" + integrity sha512-B8Mm4jCsCHaMaChcdM3VhZDVKrn0nMSDtYvHmS15Iu8Pe0G4qmIpk2AoADBAL9U9yN3pCqvs3TDXaQhM8UxRRA== dependencies: "@babel/runtime" "^7.12.5" another-json "^0.2.0" From 9e44ad44c739a0a0daccf811093b00b587affcde Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 31 Aug 2022 16:29:38 +0100 Subject: [PATCH 09/10] Prepare changelog for v3.53.0 --- CHANGELOG.md | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0339384d28..b82d5bc48e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,29 +1,30 @@ -Changes in [3.53.0-rc.2](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.53.0-rc.2) (2022-08-25) -=============================================================================================================== - -## πŸ› Bug Fixes - * Fix progress bar regression throughout the app ([\#9219](https://github.com/matrix-org/matrix-react-sdk/pull/9219)). Fixes vector-im/element-web#23121. - -Changes in [3.53.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.53.0-rc.1) (2022-08-23) -=============================================================================================================== +Changes in [3.53.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.53.0) (2022-08-31) +===================================================================================================== ## ✨ Features + * Device manager - scroll to filtered list from security recommendations ([\#9227](https://github.com/matrix-org/matrix-react-sdk/pull/9227)). Contributed by @kerryarchibald. + * Device manager - updated dropdown style in filtered device list ([\#9226](https://github.com/matrix-org/matrix-react-sdk/pull/9226)). Contributed by @kerryarchibald. + * Device manager - device type and verification icons on device tile ([\#9197](https://github.com/matrix-org/matrix-react-sdk/pull/9197)). Contributed by @kerryarchibald. * Ignore unreads in low priority rooms in the space panel ([\#6518](https://github.com/matrix-org/matrix-react-sdk/pull/6518)). Fixes vector-im/element-web#16836. * Release message right-click context menu out of labs ([\#8613](https://github.com/matrix-org/matrix-react-sdk/pull/8613)). - * Device manager - expandable session details in device list ([\#9188](https://github.com/matrix-org/matrix-react-sdk/pull/9188)). - * Device manager - device list filtering ([\#9181](https://github.com/matrix-org/matrix-react-sdk/pull/9181)). - * Device manager - add verification details to session details ([\#9187](https://github.com/matrix-org/matrix-react-sdk/pull/9187)). - * Device manager - current session expandable details ([\#9185](https://github.com/matrix-org/matrix-react-sdk/pull/9185)). - * Device manager - security recommendations section ([\#9179](https://github.com/matrix-org/matrix-react-sdk/pull/9179)). - * The Welcome Home Screen: Return Button ([\#9089](https://github.com/matrix-org/matrix-react-sdk/pull/9089)). Fixes vector-im/element-web#22917. - * Device manager - label devices as inactive ([\#9175](https://github.com/matrix-org/matrix-react-sdk/pull/9175)). - * Device manager - other sessions list ([\#9155](https://github.com/matrix-org/matrix-react-sdk/pull/9155)). + * Device manager - expandable session details in device list ([\#9188](https://github.com/matrix-org/matrix-react-sdk/pull/9188)). Contributed by @kerryarchibald. + * Device manager - device list filtering ([\#9181](https://github.com/matrix-org/matrix-react-sdk/pull/9181)). Contributed by @kerryarchibald. + * Device manager - add verification details to session details ([\#9187](https://github.com/matrix-org/matrix-react-sdk/pull/9187)). Contributed by @kerryarchibald. + * Device manager - current session expandable details ([\#9185](https://github.com/matrix-org/matrix-react-sdk/pull/9185)). Contributed by @kerryarchibald. + * Device manager - security recommendations section ([\#9179](https://github.com/matrix-org/matrix-react-sdk/pull/9179)). Contributed by @kerryarchibald. + * The Welcome Home Screen: Return Button ([\#9089](https://github.com/matrix-org/matrix-react-sdk/pull/9089)). Fixes vector-im/element-web#22917. Contributed by @justjanne. + * Device manager - label devices as inactive ([\#9175](https://github.com/matrix-org/matrix-react-sdk/pull/9175)). Contributed by @kerryarchibald. + * Device manager - other sessions list ([\#9155](https://github.com/matrix-org/matrix-react-sdk/pull/9155)). Contributed by @kerryarchibald. * Implement MSC3846: Allowing widgets to access TURN servers ([\#9061](https://github.com/matrix-org/matrix-react-sdk/pull/9061)). * Allow widgets to send/receive to-device messages ([\#8885](https://github.com/matrix-org/matrix-react-sdk/pull/8885)). ## πŸ› Bug Fixes - * Reduce amount of requests done by the onboarding task list ([\#9194](https://github.com/matrix-org/matrix-react-sdk/pull/9194)). Fixes vector-im/element-web#23085. - * Avoid hardcoding branding in user onboarding ([\#9206](https://github.com/matrix-org/matrix-react-sdk/pull/9206)). Fixes vector-im/element-web#23111. + * Add super cool feature ([\#9222](https://github.com/matrix-org/matrix-react-sdk/pull/9222)). Contributed by @gefgu. + * Make use of js-sdk roomNameGenerator to handle i18n for generated room names ([\#9209](https://github.com/matrix-org/matrix-react-sdk/pull/9209)). Fixes vector-im/element-web#21369. + * Fix progress bar regression throughout the app ([\#9219](https://github.com/matrix-org/matrix-react-sdk/pull/9219)). Fixes vector-im/element-web#23121. + * Reuse empty string & space string logic for event types in devtools ([\#9218](https://github.com/matrix-org/matrix-react-sdk/pull/9218)). Fixes vector-im/element-web#23115. + * Reduce amount of requests done by the onboarding task list ([\#9194](https://github.com/matrix-org/matrix-react-sdk/pull/9194)). Fixes vector-im/element-web#23085. Contributed by @justjanne. + * Avoid hardcoding branding in user onboarding ([\#9206](https://github.com/matrix-org/matrix-react-sdk/pull/9206)). Fixes vector-im/element-web#23111. Contributed by @justjanne. * End jitsi call when member is banned ([\#8879](https://github.com/matrix-org/matrix-react-sdk/pull/8879)). Contributed by @maheichyk. * Fix context menu being opened when clicking message action bar buttons ([\#9200](https://github.com/matrix-org/matrix-react-sdk/pull/9200)). Fixes vector-im/element-web#22279 and vector-im/element-web#23100. * Add gap between checkbox and text in report dialog following the same pattern (8px) used in the gap between the two buttons. It fixes vector-im/element-web#23060 ([\#9195](https://github.com/matrix-org/matrix-react-sdk/pull/9195)). Contributed by @gefgu. From e064f05d88e88893558ff5aa50ab4560f166c6dd Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Wed, 31 Aug 2022 16:29:39 +0100 Subject: [PATCH 10/10] v3.53.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index eee8d32adc..7abfaa2140 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.53.0-rc.2", + "version": "3.53.0", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": {