From 2cae2be90964f2779f0259335d8e0596be2e0ee5 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 9 Aug 2022 17:11:26 +0100 Subject: [PATCH 01/11] Upgrade matrix-js-sdk to 19.3.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 933ccfd7ad..1bf41275ee 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.3.0-rc.1", "matrix-widget-api": "^0.1.0-beta.18", "minimist": "^1.2.5", "opus-recorder": "^8.0.3", diff --git a/yarn.lock b/yarn.lock index f2f623b7ed..37037a0148 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6776,9 +6776,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.2.0" - resolved "https://codeload.github.com/matrix-org/matrix-js-sdk/tar.gz/cf33569a2187628dd7954ac771995cce3e804af4" +matrix-js-sdk@19.3.0-rc.1: + version "19.3.0-rc.1" + resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.3.0-rc.1.tgz#dda9f140dca076a77c5c00315b53bf2d417e5946" + integrity sha512-sK5bdn0AClJD+Cgned/rHcqMNRy1HEDuU/4SiRFoO+ROhBnNTsN3L7nOosS318WTCCpTwu2OdJCcMSJ9BBridw== dependencies: "@babel/runtime" "^7.12.5" another-json "^0.2.0" From 8cf9b357f8d1eb69242c9290df465cd8c2d494c1 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 9 Aug 2022 17:14:58 +0100 Subject: [PATCH 02/11] Prepare changelog for v3.52.0-rc.1 --- CHANGELOG.md | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c27429be7f..cec9cf24eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ +Changes in [3.52.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0-rc.1) (2022-08-09) +=============================================================================================================== + +## ✨ Features + * Device manager generic settings subsection component ([\#9147](https://github.com/matrix-org/matrix-react-sdk/pull/9147)). + * Migrate the hidden read receipts flag to new "send read receipts" option ([\#9141](https://github.com/matrix-org/matrix-react-sdk/pull/9141)). + * Live location sharing - share location at most every 5 seconds ([\#9148](https://github.com/matrix-org/matrix-react-sdk/pull/9148)). + * Increase max length of voice messages to 15m ([\#9133](https://github.com/matrix-org/matrix-react-sdk/pull/9133)). Fixes vector-im/element-web#18620. + * Move pin drop out of labs ([\#9135](https://github.com/matrix-org/matrix-react-sdk/pull/9135)). + * Device manager - New device tile info design ([\#9122](https://github.com/matrix-org/matrix-react-sdk/pull/9122)). + * Start DM on first message ([\#8612](https://github.com/matrix-org/matrix-react-sdk/pull/8612)). Fixes vector-im/element-web#14736. + * Remove "Add Space" button from RoomListHeader when user cannot create spaces ([\#9129](https://github.com/matrix-org/matrix-react-sdk/pull/9129)). + * The Welcome Home Screen: Dedicated Download Apps Dialog ([\#9120](https://github.com/matrix-org/matrix-react-sdk/pull/9120)). Fixes vector-im/element-web#22921. + * The Welcome Home Screen: "Submit Feedback" pane ([\#9090](https://github.com/matrix-org/matrix-react-sdk/pull/9090)). Fixes vector-im/element-web#22918. + * New User Onboarding Task List ([\#9083](https://github.com/matrix-org/matrix-react-sdk/pull/9083)). Fixes vector-im/element-web#22919. + * Add support for disabling spell checking ([\#8604](https://github.com/matrix-org/matrix-react-sdk/pull/8604)). Fixes vector-im/element-web#21901. + * Live location share - leave maximised map open when beacons expire ([\#9098](https://github.com/matrix-org/matrix-react-sdk/pull/9098)). + +## 🐛 Bug Fixes + * Fix pillification sometimes doubling up ([\#9152](https://github.com/matrix-org/matrix-react-sdk/pull/9152)). Fixes vector-im/element-web#23036. + * Use stable reference for active tab in tabbedView ([\#9145](https://github.com/matrix-org/matrix-react-sdk/pull/9145)). + * Fix composer padding ([\#9137](https://github.com/matrix-org/matrix-react-sdk/pull/9137)). Fixes vector-im/element-web#22992. + * Fix highlights not being applied to plaintext messages ([\#9126](https://github.com/matrix-org/matrix-react-sdk/pull/9126)). Fixes vector-im/element-web#22787. + * Fix dismissing edit composer when change was undone ([\#9109](https://github.com/matrix-org/matrix-react-sdk/pull/9109)). Fixes vector-im/element-web#22932. + * 1-to-1 DM rooms with bots now act like DM rooms instead of multi-user-rooms before ([\#9124](https://github.com/matrix-org/matrix-react-sdk/pull/9124)). Fixes vector-im/element-web#22894. + * Apply inline start padding to selected lines on modern layout only ([\#9006](https://github.com/matrix-org/matrix-react-sdk/pull/9006)). Fixes vector-im/element-web#22768. Contributed by @luixxiul. + * Peek into world-readable rooms from spotlight ([\#9115](https://github.com/matrix-org/matrix-react-sdk/pull/9115)). Fixes vector-im/element-web#22862. + * Use default styling on nested numbered lists due to MD being sensitive ([\#9110](https://github.com/matrix-org/matrix-react-sdk/pull/9110)). Fixes vector-im/element-web#22935. + * Fix replying using chat effect commands ([\#9101](https://github.com/matrix-org/matrix-react-sdk/pull/9101)). Fixes vector-im/element-web#22824. + Changes in [3.51.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.51.0) (2022-08-02) ===================================================================================================== From dcc12a142dff6796597fffea33496e4b130bcc09 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 9 Aug 2022 17:14:59 +0100 Subject: [PATCH 03/11] v3.52.0-rc.1 --- package.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 1bf41275ee..cf88aa102c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.51.0", + "version": "3.52.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 cc3ace2397c42d44e5327ed8ffa827897fd6b090 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Fri, 12 Aug 2022 12:33:16 +0200 Subject: [PATCH 04/11] Hide sticker picker for local rooms (#9174) (#9180) * Disable stickers for local rooms * Use prop --- .../views/rooms/MessageComposer.tsx | 7 +- .../views/rooms/MessageComposer-test.tsx | 74 ++++++++++++------- 2 files changed, 52 insertions(+), 29 deletions(-) diff --git a/src/components/views/rooms/MessageComposer.tsx b/src/components/views/rooms/MessageComposer.tsx index d3dfd06d90..4e33fd3022 100644 --- a/src/components/views/rooms/MessageComposer.tsx +++ b/src/components/views/rooms/MessageComposer.tsx @@ -51,6 +51,7 @@ import { SettingUpdatedPayload } from "../../../dispatcher/payloads/SettingUpdat import MessageComposerButtons from './MessageComposerButtons'; import { ButtonEvent } from '../elements/AccessibleButton'; import { ViewRoomPayload } from "../../../dispatcher/payloads/ViewRoomPayload"; +import { isLocalRoom } from '../../../utils/localRoom/isLocalRoom'; let instanceCount = 0; @@ -350,6 +351,10 @@ export default class MessageComposer extends React.Component { }); }; + private get showStickersButton(): boolean { + return this.state.showStickersButton && !isLocalRoom(this.props.room); + } + public render() { const controls = [ this.props.e2eStatus ? @@ -475,7 +480,7 @@ export default class MessageComposer extends React.Component { setStickerPickerOpen={this.setStickerPickerOpen} showLocationButton={!window.electron} showPollsButton={this.state.showPollsButton} - showStickersButton={this.state.showStickersButton} + showStickersButton={this.showStickersButton} toggleButtonMenu={this.toggleButtonMenu} /> } { showSendButton && ( diff --git a/test/components/views/rooms/MessageComposer-test.tsx b/test/components/views/rooms/MessageComposer-test.tsx index 6bbb3cc2af..2aa07fbeef 100644 --- a/test/components/views/rooms/MessageComposer-test.tsx +++ b/test/components/views/rooms/MessageComposer-test.tsx @@ -28,48 +28,66 @@ import RoomContext from "../../../../src/contexts/RoomContext"; import { IRoomState } from "../../../../src/components/structures/RoomView"; import ResizeNotifier from "../../../../src/utils/ResizeNotifier"; import { RoomPermalinkCreator } from "../../../../src/utils/permalinks/Permalinks"; +import { LocalRoom } from "../../../../src/models/LocalRoom"; +import MessageComposerButtons from "../../../../src/components/views/rooms/MessageComposerButtons"; describe("MessageComposer", () => { stubClient(); const cli = createTestClient(); - const room = mkStubRoom("!roomId:server", "Room 1", cli); - it("Renders a SendMessageComposer and MessageComposerButtons by default", () => { - const wrapper = wrapAndRender({ room }); + describe("for a Room", () => { + const room = mkStubRoom("!roomId:server", "Room 1", cli); - expect(wrapper.find("SendMessageComposer")).toHaveLength(1); - expect(wrapper.find("MessageComposerButtons")).toHaveLength(1); + it("Renders a SendMessageComposer and MessageComposerButtons by default", () => { + const wrapper = wrapAndRender({ room }); + + expect(wrapper.find("SendMessageComposer")).toHaveLength(1); + expect(wrapper.find("MessageComposerButtons")).toHaveLength(1); + }); + + it("Does not render a SendMessageComposer or MessageComposerButtons when user has no permission", () => { + const wrapper = wrapAndRender({ room }, false); + + expect(wrapper.find("SendMessageComposer")).toHaveLength(0); + expect(wrapper.find("MessageComposerButtons")).toHaveLength(0); + expect(wrapper.find(".mx_MessageComposer_noperm_error")).toHaveLength(1); + }); + + it("Does not render a SendMessageComposer or MessageComposerButtons when room is tombstoned", () => { + const wrapper = wrapAndRender({ room }, true, mkEvent({ + event: true, + type: "m.room.tombstone", + room: room.roomId, + user: "@user1:server", + skey: "", + content: {}, + ts: Date.now(), + })); + + expect(wrapper.find("SendMessageComposer")).toHaveLength(0); + expect(wrapper.find("MessageComposerButtons")).toHaveLength(0); + expect(wrapper.find(".mx_MessageComposer_roomReplaced_header")).toHaveLength(1); + }); }); - it("Does not render a SendMessageComposer or MessageComposerButtons when user has no permission", () => { - const wrapper = wrapAndRender({ room }, false); + describe("for a LocalRoom", () => { + const localRoom = new LocalRoom("!room:example.com", cli, cli.getUserId()); - expect(wrapper.find("SendMessageComposer")).toHaveLength(0); - expect(wrapper.find("MessageComposerButtons")).toHaveLength(0); - expect(wrapper.find(".mx_MessageComposer_noperm_error")).toHaveLength(1); - }); - - it("Does not render a SendMessageComposer or MessageComposerButtons when room is tombstoned", () => { - const wrapper = wrapAndRender({ room }, true, mkEvent({ - event: true, - type: "m.room.tombstone", - room: room.roomId, - user: "@user1:server", - skey: "", - content: {}, - ts: Date.now(), - })); - - expect(wrapper.find("SendMessageComposer")).toHaveLength(0); - expect(wrapper.find("MessageComposerButtons")).toHaveLength(0); - expect(wrapper.find(".mx_MessageComposer_roomReplaced_header")).toHaveLength(1); + it("should pass the sticker picker disabled prop", () => { + const wrapper = wrapAndRender({ room: localRoom }); + expect(wrapper.find(MessageComposerButtons).props().showStickersButton).toBe(false); + }); }); }); -function wrapAndRender(props = {}, canSendMessages = true, tombstone?: MatrixEvent): ReactWrapper { +function wrapAndRender( + props: Partial> = {}, + canSendMessages = true, + tombstone?: MatrixEvent, +): ReactWrapper { const mockClient = MatrixClientPeg.get(); const roomId = "myroomid"; - const room: any = { + const room: any = props.room || { currentState: undefined, roomId, client: mockClient, From 5ccd473744c6e3a1ef1d32bb4af3fd8183db2e45 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Fri, 12 Aug 2022 13:34:03 +0100 Subject: [PATCH 05/11] Upgrade matrix-js-sdk to 19.3.0-rc.2 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index cf88aa102c..d04e104478 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.3.0-rc.1", + "matrix-js-sdk": "19.3.0-rc.2", "matrix-widget-api": "^0.1.0-beta.18", "minimist": "^1.2.5", "opus-recorder": "^8.0.3", diff --git a/yarn.lock b/yarn.lock index 37037a0148..0667bad91b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6776,10 +6776,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.3.0-rc.1: - version "19.3.0-rc.1" - resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.3.0-rc.1.tgz#dda9f140dca076a77c5c00315b53bf2d417e5946" - integrity sha512-sK5bdn0AClJD+Cgned/rHcqMNRy1HEDuU/4SiRFoO+ROhBnNTsN3L7nOosS318WTCCpTwu2OdJCcMSJ9BBridw== +matrix-js-sdk@19.3.0-rc.2: + version "19.3.0-rc.2" + resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.3.0-rc.2.tgz#ede132ee6f0b97b1444bbd515c12b27678b49da0" + integrity sha512-UixvWZ+rfBiDw3jf35XHYkEXHSQ6wHPM9fs58HAe3124PU3JeEeQl2f+0OKJzd0jnXah3WWPAylpvmpNeNGjXg== dependencies: "@babel/runtime" "^7.12.5" another-json "^0.2.0" From 1d6d012e93dcdd5a927be0b990d925a9f67b6f84 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Fri, 12 Aug 2022 13:38:12 +0100 Subject: [PATCH 06/11] Prepare changelog for v3.52.0-rc.2 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec9cf24eb..3c93934deb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Changes in [3.52.0-rc.2](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0-rc.2) (2022-08-12) +=============================================================================================================== + +## ✨ Features + * The first message in a DM can no longer be a sticker. This has been changed to avoid issues with the integration manager. ([\#9180](https://github.com/matrix-org/matrix-react-sdk/pull/9180)). + Changes in [3.52.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0-rc.1) (2022-08-09) =============================================================================================================== From 1371949a3aa1f260d8ea86dac507d9ba963867fc Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Fri, 12 Aug 2022 13:38:13 +0100 Subject: [PATCH 07/11] v3.52.0-rc.2 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d04e104478..c225abc265 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.52.0-rc.1", + "version": "3.52.0-rc.2", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": { From 65b1bb9bfdb9b78974277e911f1e0659773ebce0 Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Tue, 16 Aug 2022 16:17:47 +0200 Subject: [PATCH 08/11] Disable some slash commands in LocalRoom (#9193) --- src/SlashCommands.tsx | 39 +++++++-- test/SlashCommands-test.tsx | 162 +++++++++++++++++++++++++++++++++++- 2 files changed, 193 insertions(+), 8 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 9d3047a275..5a5f59498f 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -69,6 +69,7 @@ import { ViewRoomPayload } from "./dispatcher/payloads/ViewRoomPayload"; import VoipUserMapper from './VoipUserMapper'; import { htmlSerializeFromMdIfNeeded } from './editor/serialize'; import { leaveRoomBehaviour } from "./utils/leave-behaviour"; +import { isLocalRoom } from './utils/localRoom/isLocalRoom'; // XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816 interface HTMLInputEvent extends Event { @@ -206,6 +207,12 @@ function successSync(value: any) { return success(Promise.resolve(value)); } +const isCurrentLocalRoom = (): boolean => { + const cli = MatrixClientPeg.get(); + const room = cli.getRoom(RoomViewStore.instance.getRoomId()); + return isLocalRoom(room); +}; + /* Disable the "unexpected this" error for these commands - all of the run * functions are called with `this` bound to the Command instance. */ @@ -297,6 +304,7 @@ export const Commands = [ command: 'upgraderoom', args: '', description: _td('Upgrades a room to a new version'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { if (args) { const cli = MatrixClientPeg.get(); @@ -380,6 +388,7 @@ export const Commands = [ aliases: ['roomnick'], args: '', description: _td('Changes your display nickname in the current room only'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { if (args) { const cli = MatrixClientPeg.get(); @@ -399,6 +408,7 @@ export const Commands = [ command: 'roomavatar', args: '[]', description: _td('Changes the avatar of the current room'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { let promise = Promise.resolve(args); if (!args) { @@ -417,6 +427,7 @@ export const Commands = [ command: 'myroomavatar', args: '[]', description: _td('Changes your avatar in this current room only'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const cli = MatrixClientPeg.get(); const room = cli.getRoom(roomId); @@ -462,6 +473,7 @@ export const Commands = [ command: 'topic', args: '[]', description: _td('Gets or sets the room topic'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const cli = MatrixClientPeg.get(); if (args) { @@ -498,6 +510,7 @@ export const Commands = [ command: 'roomname', args: '', description: _td('Sets the room name'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { if (args) { return success(MatrixClientPeg.get().setRoomName(roomId, args)); @@ -512,7 +525,7 @@ export const Commands = [ args: ' []', description: _td('Invites user with given id to current room'), analyticsName: "Invite", - isEnabled: () => shouldShowComponent(UIComponent.InviteUsers), + isEnabled: () => !isCurrentLocalRoom() && shouldShowComponent(UIComponent.InviteUsers), runFn: function(roomId, args) { if (args) { const [address, reason] = args.split(/\s+(.+)/); @@ -694,6 +707,7 @@ export const Commands = [ args: '[]', description: _td('Leave room'), analyticsName: "Part", + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const cli = MatrixClientPeg.get(); @@ -746,6 +760,7 @@ export const Commands = [ aliases: ["kick"], args: ' [reason]', description: _td('Removes user with given id from this room'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { if (args) { const matches = args.match(/^(\S+?)( +(.*))?$/); @@ -762,6 +777,7 @@ export const Commands = [ command: 'ban', args: ' [reason]', description: _td('Bans user with given id'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { if (args) { const matches = args.match(/^(\S+?)( +(.*))?$/); @@ -778,6 +794,7 @@ export const Commands = [ command: 'unban', args: '', description: _td('Unbans user with given ID'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { if (args) { const matches = args.match(/^(\S+)$/); @@ -857,7 +874,8 @@ export const Commands = [ isEnabled(): boolean { const cli = MatrixClientPeg.get(); const room = cli.getRoom(RoomViewStore.instance.getRoomId()); - return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId()); + return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId()) + && !isLocalRoom(room); }, runFn: function(roomId, args) { if (args) { @@ -897,7 +915,8 @@ export const Commands = [ isEnabled(): boolean { const cli = MatrixClientPeg.get(); const room = cli.getRoom(RoomViewStore.instance.getRoomId()); - return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId()); + return room?.currentState.maySendStateEvent(EventType.RoomPowerLevels, cli.getUserId()) + && !isLocalRoom(room); }, runFn: function(roomId, args) { if (args) { @@ -936,7 +955,9 @@ export const Commands = [ command: 'addwidget', args: '', description: _td('Adds a custom widget by URL to the room'), - isEnabled: () => SettingsStore.getValue(UIFeature.Widgets) && shouldShowComponent(UIComponent.AddIntegrations), + isEnabled: () => SettingsStore.getValue(UIFeature.Widgets) + && shouldShowComponent(UIComponent.AddIntegrations) + && !isCurrentLocalRoom(), runFn: function(roomId, widgetUrl) { if (!widgetUrl) { return reject(newTranslatableError("Please supply a widget URL or embed code")); @@ -1059,6 +1080,7 @@ export const Commands = [ new Command({ command: 'discardsession', description: _td('Forces the current outbound group session in an encrypted room to be discarded'), + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId) { try { MatrixClientPeg.get().forceDiscardSession(roomId); @@ -1074,7 +1096,7 @@ export const Commands = [ command: 'remakeolm', description: _td('Developer command: Discards the current outbound group session and sets up new Olm sessions'), isEnabled: () => { - return SettingsStore.getValue("developerMode"); + return SettingsStore.getValue("developerMode") && !isCurrentLocalRoom(); }, runFn: (roomId) => { try { @@ -1125,6 +1147,7 @@ export const Commands = [ command: "whois", description: _td("Displays information about a user"), args: "", + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, userId) { if (!userId || !userId.startsWith("@") || !userId.includes(":")) { return reject(this.getUsage()); @@ -1160,7 +1183,7 @@ export const Commands = [ description: _td("Switches to this room's virtual room, if it has one"), category: CommandCategories.advanced, isEnabled(): boolean { - return CallHandler.instance.getSupportsVirtualRooms(); + return CallHandler.instance.getSupportsVirtualRooms() && !isCurrentLocalRoom(); }, runFn: (roomId) => { return success((async () => { @@ -1244,6 +1267,7 @@ export const Commands = [ command: "holdcall", description: _td("Places the call in the current room on hold"), category: CommandCategories.other, + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const call = CallHandler.instance.getCallForRoom(roomId); if (!call) { @@ -1258,6 +1282,7 @@ export const Commands = [ command: "unholdcall", description: _td("Takes the call in the current room off hold"), category: CommandCategories.other, + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const call = CallHandler.instance.getCallForRoom(roomId); if (!call) { @@ -1272,6 +1297,7 @@ export const Commands = [ command: "converttodm", description: _td("Converts the room to a DM"), category: CommandCategories.other, + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const room = MatrixClientPeg.get().getRoom(roomId); return success(guessAndSetDMRoom(room, true)); @@ -1282,6 +1308,7 @@ export const Commands = [ command: "converttoroom", description: _td("Converts the DM to a room"), category: CommandCategories.other, + isEnabled: () => !isCurrentLocalRoom(), runFn: function(roomId, args) { const room = MatrixClientPeg.get().getRoom(roomId); return success(guessAndSetDMRoom(room, false)); diff --git a/test/SlashCommands-test.tsx b/test/SlashCommands-test.tsx index f2b15fb729..09d8e3c587 100644 --- a/test/SlashCommands-test.tsx +++ b/test/SlashCommands-test.tsx @@ -14,18 +14,53 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { MatrixClient } from 'matrix-js-sdk/src/matrix'; +import { MatrixClient, Room } from 'matrix-js-sdk/src/matrix'; +import { mocked } from 'jest-mock'; -import { getCommand } from '../src/SlashCommands'; +import { Command, Commands, getCommand } from '../src/SlashCommands'; import { createTestClient } from './test-utils'; import { MatrixClientPeg } from '../src/MatrixClientPeg'; +import { LocalRoom, LOCAL_ROOM_ID_PREFIX } from '../src/models/LocalRoom'; +import { RoomViewStore } from '../src/stores/RoomViewStore'; +import SettingsStore from '../src/settings/SettingsStore'; +import CallHandler from '../src/CallHandler'; describe('SlashCommands', () => { let client: MatrixClient; + const roomId = "!room:example.com"; + let room: Room; + const localRoomId = LOCAL_ROOM_ID_PREFIX + "test"; + let localRoom: LocalRoom; + let command: Command; + + const findCommand = (cmd: string): Command => { + return Commands.find((command: Command) => command.command === cmd); + }; + + const setCurrentRoom = (): void => { + mocked(RoomViewStore.instance.getRoomId).mockReturnValue(roomId); + mocked(client.getRoom).mockImplementation((rId: string): Room => { + if (rId === roomId) return room; + }); + }; + + const setCurrentLocalRoon = (): void => { + mocked(RoomViewStore.instance.getRoomId).mockReturnValue(localRoomId); + mocked(client.getRoom).mockImplementation((rId: string): Room => { + if (rId === localRoomId) return localRoom; + }); + }; beforeEach(() => { + jest.clearAllMocks(); + client = createTestClient(); jest.spyOn(MatrixClientPeg, 'get').mockReturnValue(client); + + room = new Room(roomId, client, client.getUserId()); + localRoom = new LocalRoom(localRoomId, client, client.getUserId()); + + jest.spyOn(RoomViewStore.instance, "getRoomId"); }); describe('/topic', () => { @@ -37,4 +72,127 @@ describe('SlashCommands', () => { expect(client.setRoomTopic).toHaveBeenCalledWith("room-id", "pizza", undefined); }); }); + + describe.each([ + ["upgraderoom"], + ["myroomnick"], + ["roomavatar"], + ["myroomavatar"], + ["topic"], + ["roomname"], + ["invite"], + ["part"], + ["remove"], + ["ban"], + ["unban"], + ["op"], + ["deop"], + ["addwidget"], + ["discardsession"], + ["whois"], + ["holdcall"], + ["unholdcall"], + ["converttodm"], + ["converttoroom"], + ])("/%s", (commandName: string) => { + beforeEach(() => { + command = findCommand(commandName); + }); + + describe("isEnabled", () => { + it("should return true for Room", () => { + setCurrentRoom(); + expect(command.isEnabled()).toBe(true); + }); + + it("should return false for LocalRoom", () => { + setCurrentLocalRoon(); + expect(command.isEnabled()).toBe(false); + }); + }); + }); + + describe("/tovirtual", () => { + beforeEach(() => { + command = findCommand("tovirtual"); + }); + + describe("isEnabled", () => { + describe("when virtual rooms are supported", () => { + beforeEach(() => { + jest.spyOn(CallHandler.instance, "getSupportsVirtualRooms").mockReturnValue(true); + }); + + it("should return true for Room", () => { + setCurrentRoom(); + expect(command.isEnabled()).toBe(true); + }); + + it("should return false for LocalRoom", () => { + setCurrentLocalRoon(); + expect(command.isEnabled()).toBe(false); + }); + }); + + describe("when virtual rooms are not supported", () => { + beforeEach(() => { + jest.spyOn(CallHandler.instance, "getSupportsVirtualRooms").mockReturnValue(false); + }); + + it("should return false for Room", () => { + setCurrentRoom(); + expect(command.isEnabled()).toBe(false); + }); + + it("should return false for LocalRoom", () => { + setCurrentLocalRoon(); + expect(command.isEnabled()).toBe(false); + }); + }); + }); + }); + + describe("/remakeolm", () => { + beforeEach(() => { + command = findCommand("remakeolm"); + }); + + describe("isEnabled", () => { + describe("when developer mode is enabled", () => { + beforeEach(() => { + jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => { + if (settingName === "developerMode") return true; + }); + }); + + it("should return true for Room", () => { + setCurrentRoom(); + expect(command.isEnabled()).toBe(true); + }); + + it("should return false for LocalRoom", () => { + setCurrentLocalRoon(); + expect(command.isEnabled()).toBe(false); + }); + }); + + describe("when developer mode is not enabled", () => { + beforeEach(() => { + jest.spyOn(SettingsStore, "getValue").mockImplementation((settingName: string) => { + if (settingName === "developerMode") return false; + }); + }); + + it("should return false for Room", () => { + setCurrentRoom(); + expect(command.isEnabled()).toBe(false); + }); + + it("should return false for LocalRoom", () => { + setCurrentLocalRoon(); + expect(command.isEnabled()).toBe(false); + }); + }); + }); + }); }); From 4fce604771d3ee93028c5624da0923012328ea13 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 16 Aug 2022 15:35:10 +0100 Subject: [PATCH 09/11] Upgrade matrix-js-sdk to 19.3.0 --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index c225abc265..479abbaf43 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.3.0-rc.2", + "matrix-js-sdk": "19.3.0", "matrix-widget-api": "^0.1.0-beta.18", "minimist": "^1.2.5", "opus-recorder": "^8.0.3", diff --git a/yarn.lock b/yarn.lock index 0667bad91b..df04d3ac60 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6776,10 +6776,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.3.0-rc.2: - version "19.3.0-rc.2" - resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.3.0-rc.2.tgz#ede132ee6f0b97b1444bbd515c12b27678b49da0" - integrity sha512-UixvWZ+rfBiDw3jf35XHYkEXHSQ6wHPM9fs58HAe3124PU3JeEeQl2f+0OKJzd0jnXah3WWPAylpvmpNeNGjXg== +matrix-js-sdk@19.3.0: + version "19.3.0" + resolved "https://registry.yarnpkg.com/matrix-js-sdk/-/matrix-js-sdk-19.3.0.tgz#1a9ea66201ae349eb95039b3a63780c7d6607313" + integrity sha512-ZhYfDdnqujEFeZe+ek5SdxUgWXQBq2OaOgWnQwG4jD00ANdTmeBKlDsNCjOwefyD6UQ1G/oM2W/YVEghihAT1g== dependencies: "@babel/runtime" "^7.12.5" another-json "^0.2.0" From a2a67a735ff6a9200622403686de1cbb820017de Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 16 Aug 2022 15:38:46 +0100 Subject: [PATCH 10/11] Prepare changelog for v3.52.0 --- CHANGELOG.md | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c93934deb..c6b8e22f01 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,30 +1,25 @@ -Changes in [3.52.0-rc.2](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0-rc.2) (2022-08-12) -=============================================================================================================== +Changes in [3.52.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0) (2022-08-16) +===================================================================================================== ## ✨ Features - * The first message in a DM can no longer be a sticker. This has been changed to avoid issues with the integration manager. ([\#9180](https://github.com/matrix-org/matrix-react-sdk/pull/9180)). - -Changes in [3.52.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.52.0-rc.1) (2022-08-09) -=============================================================================================================== - -## ✨ Features - * Device manager generic settings subsection component ([\#9147](https://github.com/matrix-org/matrix-react-sdk/pull/9147)). + * Device manager - New device tile info design ([\#9122](https://github.com/matrix-org/matrix-react-sdk/pull/9122)). Contributed by @kerryarchibald. + * Device manager generic settings subsection component ([\#9147](https://github.com/matrix-org/matrix-react-sdk/pull/9147)). Contributed by @kerryarchibald. * Migrate the hidden read receipts flag to new "send read receipts" option ([\#9141](https://github.com/matrix-org/matrix-react-sdk/pull/9141)). - * Live location sharing - share location at most every 5 seconds ([\#9148](https://github.com/matrix-org/matrix-react-sdk/pull/9148)). + * Live location sharing - share location at most every 5 seconds ([\#9148](https://github.com/matrix-org/matrix-react-sdk/pull/9148)). Contributed by @kerryarchibald. * Increase max length of voice messages to 15m ([\#9133](https://github.com/matrix-org/matrix-react-sdk/pull/9133)). Fixes vector-im/element-web#18620. * Move pin drop out of labs ([\#9135](https://github.com/matrix-org/matrix-react-sdk/pull/9135)). - * Device manager - New device tile info design ([\#9122](https://github.com/matrix-org/matrix-react-sdk/pull/9122)). * Start DM on first message ([\#8612](https://github.com/matrix-org/matrix-react-sdk/pull/8612)). Fixes vector-im/element-web#14736. * Remove "Add Space" button from RoomListHeader when user cannot create spaces ([\#9129](https://github.com/matrix-org/matrix-react-sdk/pull/9129)). - * The Welcome Home Screen: Dedicated Download Apps Dialog ([\#9120](https://github.com/matrix-org/matrix-react-sdk/pull/9120)). Fixes vector-im/element-web#22921. - * The Welcome Home Screen: "Submit Feedback" pane ([\#9090](https://github.com/matrix-org/matrix-react-sdk/pull/9090)). Fixes vector-im/element-web#22918. - * New User Onboarding Task List ([\#9083](https://github.com/matrix-org/matrix-react-sdk/pull/9083)). Fixes vector-im/element-web#22919. + * The Welcome Home Screen: Dedicated Download Apps Dialog ([\#9120](https://github.com/matrix-org/matrix-react-sdk/pull/9120)). Fixes vector-im/element-web#22921. Contributed by @justjanne. + * The Welcome Home Screen: "Submit Feedback" pane ([\#9090](https://github.com/matrix-org/matrix-react-sdk/pull/9090)). Fixes vector-im/element-web#22918. Contributed by @justjanne. + * New User Onboarding Task List ([\#9083](https://github.com/matrix-org/matrix-react-sdk/pull/9083)). Fixes vector-im/element-web#22919. Contributed by @justjanne. * Add support for disabling spell checking ([\#8604](https://github.com/matrix-org/matrix-react-sdk/pull/8604)). Fixes vector-im/element-web#21901. - * Live location share - leave maximised map open when beacons expire ([\#9098](https://github.com/matrix-org/matrix-react-sdk/pull/9098)). + * Live location share - leave maximised map open when beacons expire ([\#9098](https://github.com/matrix-org/matrix-react-sdk/pull/9098)). Contributed by @kerryarchibald. ## 🐛 Bug Fixes + * Some slash-commands (`/myroomnick`) have temporarily been disabled before the first message in a DM is sent. ([\#9193](https://github.com/matrix-org/matrix-react-sdk/pull/9193)). + * Use stable reference for active tab in tabbedView ([\#9145](https://github.com/matrix-org/matrix-react-sdk/pull/9145)). Contributed by @kerryarchibald. * Fix pillification sometimes doubling up ([\#9152](https://github.com/matrix-org/matrix-react-sdk/pull/9152)). Fixes vector-im/element-web#23036. - * Use stable reference for active tab in tabbedView ([\#9145](https://github.com/matrix-org/matrix-react-sdk/pull/9145)). * Fix composer padding ([\#9137](https://github.com/matrix-org/matrix-react-sdk/pull/9137)). Fixes vector-im/element-web#22992. * Fix highlights not being applied to plaintext messages ([\#9126](https://github.com/matrix-org/matrix-react-sdk/pull/9126)). Fixes vector-im/element-web#22787. * Fix dismissing edit composer when change was undone ([\#9109](https://github.com/matrix-org/matrix-react-sdk/pull/9109)). Fixes vector-im/element-web#22932. @@ -33,6 +28,7 @@ Changes in [3.52.0-rc.1](https://github.com/matrix-org/matrix-react-sdk/releases * Peek into world-readable rooms from spotlight ([\#9115](https://github.com/matrix-org/matrix-react-sdk/pull/9115)). Fixes vector-im/element-web#22862. * Use default styling on nested numbered lists due to MD being sensitive ([\#9110](https://github.com/matrix-org/matrix-react-sdk/pull/9110)). Fixes vector-im/element-web#22935. * Fix replying using chat effect commands ([\#9101](https://github.com/matrix-org/matrix-react-sdk/pull/9101)). Fixes vector-im/element-web#22824. + * The first message in a DM can no longer be a sticker. This has been changed to avoid issues with the integration manager. ([\#9180](https://github.com/matrix-org/matrix-react-sdk/pull/9180)). Changes in [3.51.0](https://github.com/matrix-org/matrix-react-sdk/releases/tag/v3.51.0) (2022-08-02) ===================================================================================================== From afb39d8d921ed537705c5a46ba27fb514ac522d4 Mon Sep 17 00:00:00 2001 From: RiotRobot Date: Tue, 16 Aug 2022 15:38:47 +0100 Subject: [PATCH 11/11] v3.52.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 479abbaf43..72580e7e42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "matrix-react-sdk", - "version": "3.52.0-rc.2", + "version": "3.52.0", "description": "SDK for matrix.org using React", "author": "matrix.org", "repository": {