From e0b8343088153642cd5a383666ce1ca57dac750d Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 19 Aug 2020 19:21:40 -0600 Subject: [PATCH 1/8] Run all room leaving behaviour through a single function Fixes https://github.com/vector-im/element-web/issues/14999 Fixes https://github.com/vector-im/element-web/issues/10380 We were failing to handle errors when `/part`ing a room, though the leave room button was fine. This runs both the button and command through the same function for handling, including the 'view next room' behaviour. --- src/SlashCommands.tsx | 8 +-- src/components/structures/MatrixChat.tsx | 42 ++------------- src/i18n/strings/en_EN.json | 9 ++-- src/utils/membership.ts | 68 ++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 49 deletions(-) diff --git a/src/SlashCommands.tsx b/src/SlashCommands.tsx index 50a49ccf1c..d674634109 100644 --- a/src/SlashCommands.tsx +++ b/src/SlashCommands.tsx @@ -43,7 +43,7 @@ import SdkConfig from "./SdkConfig"; import { ensureDMExists } from "./createRoom"; import { ViewUserPayload } from "./dispatcher/payloads/ViewUserPayload"; import { Action } from "./dispatcher/actions"; -import { EffectiveMembership, getEffectiveMembership } from "./utils/membership"; +import { EffectiveMembership, getEffectiveMembership, leaveRoomBehaviour } from "./utils/membership"; // XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816 interface HTMLInputEvent extends Event { @@ -601,11 +601,7 @@ export const Commands = [ } if (!targetRoomId) targetRoomId = roomId; - return success( - cli.leaveRoomChain(targetRoomId).then(function() { - dis.dispatch({action: 'view_next_room'}); - }), - ); + return success(leaveRoomBehaviour(targetRoomId)); }, category: CommandCategories.actions, }), diff --git a/src/components/structures/MatrixChat.tsx b/src/components/structures/MatrixChat.tsx index ce96847d28..460148045c 100644 --- a/src/components/structures/MatrixChat.tsx +++ b/src/components/structures/MatrixChat.tsx @@ -76,6 +76,7 @@ import { OpenToTabPayload } from "../../dispatcher/payloads/OpenToTabPayload"; import ErrorDialog from "../views/dialogs/ErrorDialog"; import { RoomNotificationStateStore } from "../../stores/notifications/RoomNotificationStateStore"; import { SettingLevel } from "../../settings/SettingLevel"; +import { leaveRoomBehaviour } from "../../utils/membership"; /** constants for MatrixChat.state.view */ export enum Views { @@ -1082,50 +1083,13 @@ export default class MatrixChat extends React.PureComponent { button: _t("Leave"), onFinished: (shouldLeave) => { if (shouldLeave) { - const d = MatrixClientPeg.get().leaveRoomChain(roomId); + const d = leaveRoomBehaviour(roomId); // FIXME: controller shouldn't be loading a view :( const Loader = sdk.getComponent("elements.Spinner"); const modal = Modal.createDialog(Loader, null, 'mx_Dialog_spinner'); - d.then((errors) => { - modal.close(); - - for (const leftRoomId of Object.keys(errors)) { - const err = errors[leftRoomId]; - if (!err) continue; - - console.error("Failed to leave room " + leftRoomId + " " + err); - let title = _t("Failed to leave room"); - let message = _t("Server may be unavailable, overloaded, or you hit a bug."); - if (err.errcode === 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { - title = _t("Can't leave Server Notices room"); - message = _t( - "This room is used for important messages from the Homeserver, " + - "so you cannot leave it.", - ); - } else if (err && err.message) { - message = err.message; - } - Modal.createTrackedDialog('Failed to leave room', '', ErrorDialog, { - title: title, - description: message, - }); - return; - } - - if (this.state.currentRoomId === roomId) { - dis.dispatch({action: 'view_next_room'}); - } - }, (err) => { - // This should only happen if something went seriously wrong with leaving the chain. - modal.close(); - console.error("Failed to leave room " + roomId + " " + err); - Modal.createTrackedDialog('Failed to leave room', '', ErrorDialog, { - title: _t("Failed to leave room"), - description: _t("Unknown error"), - }); - }); + d.finally(() => modal.close()); } }, }); diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 8bfc3ed703..4c0557ac70 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -347,6 +347,10 @@ "Your browser does not support the required cryptography extensions": "Your browser does not support the required cryptography extensions", "Not a valid %(brand)s keyfile": "Not a valid %(brand)s keyfile", "Authentication check failed: incorrect password?": "Authentication check failed: incorrect password?", + "Unexpected server error trying to leave the room": "Unexpected server error trying to leave the room", + "Can't leave Server Notices room": "Can't leave Server Notices room", + "This room is used for important messages from the Homeserver, so you cannot leave it.": "This room is used for important messages from the Homeserver, so you cannot leave it.", + "Error leaving room": "Error leaving room", "Unrecognised address": "Unrecognised address", "You do not have permission to invite people to this room.": "You do not have permission to invite people to this room.", "User %(userId)s is already in the room": "User %(userId)s is already in the room", @@ -2028,10 +2032,6 @@ "Failed to reject invitation": "Failed to reject invitation", "This room is not public. You will not be able to rejoin without an invite.": "This room is not public. You will not be able to rejoin without an invite.", "Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?", - "Failed to leave room": "Failed to leave room", - "Can't leave Server Notices room": "Can't leave Server Notices room", - "This room is used for important messages from the Homeserver, so you cannot leave it.": "This room is used for important messages from the Homeserver, so you cannot leave it.", - "Unknown error": "Unknown error", "Signed Out": "Signed Out", "For security, this session has been signed out. Please sign in again.": "For security, this session has been signed out. Please sign in again.", "Terms and Conditions": "Terms and Conditions", @@ -2203,6 +2203,7 @@ "User Autocomplete": "User Autocomplete", "Passphrases must match": "Passphrases must match", "Passphrase must not be empty": "Passphrase must not be empty", + "Unknown error": "Unknown error", "Export room keys": "Export room keys", "This process allows you to export the keys for messages you have received in encrypted rooms to a local file. You will then be able to import the file into another Matrix client in the future, so that client will also be able to decrypt these messages.": "This process allows you to export the keys for messages you have received in encrypted rooms to a local file. You will then be able to import the file into another Matrix client in the future, so that client will also be able to decrypt these messages.", "The exported file will allow anyone who can read it to decrypt any encrypted messages that you can see, so you should be careful to keep it secure. To help with this, you should enter a passphrase below, which will be used to encrypt the exported data. It will only be possible to import the data by using the same passphrase.": "The exported file will allow anyone who can read it to decrypt any encrypted messages that you can see, so you should be careful to keep it secure. To help with this, you should enter a passphrase below, which will be used to encrypt the exported data. It will only be possible to import the data by using the same passphrase.", diff --git a/src/utils/membership.ts b/src/utils/membership.ts index 9534623d62..a8abacbeaa 100644 --- a/src/utils/membership.ts +++ b/src/utils/membership.ts @@ -15,6 +15,13 @@ limitations under the License. */ import { Room } from "matrix-js-sdk/src/models/room"; +import { MatrixClientPeg } from "../MatrixClientPeg"; +import { _t } from "../languageHandler"; +import Modal from "../Modal"; +import ErrorDialog from "../components/views/dialogs/ErrorDialog"; +import React from "react"; +import dis from "../dispatcher/dispatcher"; +import RoomViewStore from "../stores/RoomViewStore"; /** * Approximation of a membership status for a given room. @@ -70,3 +77,64 @@ export function getEffectiveMembership(membership: string): EffectiveMembership return EffectiveMembership.Leave; } } + +export async function leaveRoomBehaviour(roomId: string): Promise { + let leavingAllVersions = true; + const history = await MatrixClientPeg.get().getRoomUpgradeHistory(roomId); + if (history && history.length > 0) { + const currentRoom = history[history.length - 1]; + if (currentRoom.roomId !== roomId) { + // The user is trying to leave an older version of the room. Let them through + // without making them leave the current version of the room. + leavingAllVersions = false; + } + } + + let results: { [roomId: string]: Error & { errcode: string, message: string } } = {}; + if (!leavingAllVersions || true) { + try { + await MatrixClientPeg.get().leave(roomId); + } catch (e) { + if (e && e.data && e.data.errcode) { + const message = e.data.error || _t("Unexpected server error trying to leave the room"); + results[roomId] = Object.assign(new Error(message), {errcode: e.data.errcode}); + } else { + results[roomId] = e || new Error("Failed to leave room for unknown causes"); + } + } + } else { + results = await MatrixClientPeg.get().leaveRoomChain(roomId); + } + + const errors = Object.entries(results).filter(r => !!r[1]); + if (errors.length > 0) { + let messages = []; + for (const err of errors) { + let message = _t("Unexpected server error trying to leave the room"); + if (results[roomId].errcode && results[roomId].message) { + if (results[roomId].errcode === 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { + Modal.createTrackedDialog('Error Leaving Room', '', ErrorDialog, { + title: _t("Can't leave Server Notices room"), + description: _t( + "This room is used for important messages from the Homeserver, " + + "so you cannot leave it.", + ), + }); + return false; + } + message = results[roomId].message; + } + messages.push(message, React.createElement('BR')); // createElement to avoid using a tsx file in utils + } + Modal.createTrackedDialog('Error Leaving Room', '', ErrorDialog, { + title: _t("Error leaving room"), + description: messages, + }); + return false; + } + + if (RoomViewStore.getRoomId() === roomId) { + dis.dispatch({action: 'view_next_room'}); + } + return true; +} From 309c32700b32e06ce8c282014b258fe5553a1c08 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 19 Aug 2020 19:23:27 -0600 Subject: [PATCH 2/8] Remove unused success state --- src/utils/membership.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/utils/membership.ts b/src/utils/membership.ts index a8abacbeaa..2693d816a5 100644 --- a/src/utils/membership.ts +++ b/src/utils/membership.ts @@ -78,7 +78,7 @@ export function getEffectiveMembership(membership: string): EffectiveMembership } } -export async function leaveRoomBehaviour(roomId: string): Promise { +export async function leaveRoomBehaviour(roomId: string) { let leavingAllVersions = true; const history = await MatrixClientPeg.get().getRoomUpgradeHistory(roomId); if (history && history.length > 0) { @@ -120,7 +120,7 @@ export async function leaveRoomBehaviour(roomId: string): Promise { "so you cannot leave it.", ), }); - return false; + return; } message = results[roomId].message; } @@ -130,11 +130,10 @@ export async function leaveRoomBehaviour(roomId: string): Promise { title: _t("Error leaving room"), description: messages, }); - return false; + return; } if (RoomViewStore.getRoomId() === roomId) { dis.dispatch({action: 'view_next_room'}); } - return true; } From 8fffce8a303c764ce61a968109e0c5ddb70024d7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 19 Aug 2020 19:42:36 -0600 Subject: [PATCH 3/8] Appease the linter --- src/utils/membership.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/membership.ts b/src/utils/membership.ts index 2693d816a5..14a3ced739 100644 --- a/src/utils/membership.ts +++ b/src/utils/membership.ts @@ -108,11 +108,12 @@ export async function leaveRoomBehaviour(roomId: string) { const errors = Object.entries(results).filter(r => !!r[1]); if (errors.length > 0) { - let messages = []; - for (const err of errors) { + const messages = []; + for (const roomErr of errors) { + const err = roomErr[1]; // [0] is the roomId let message = _t("Unexpected server error trying to leave the room"); - if (results[roomId].errcode && results[roomId].message) { - if (results[roomId].errcode === 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { + if (err.errcode && err.message) { + if (err.errcode === 'M_CANNOT_LEAVE_SERVER_NOTICE_ROOM') { Modal.createTrackedDialog('Error Leaving Room', '', ErrorDialog, { title: _t("Can't leave Server Notices room"), description: _t( From 42988d373bb030d44d707c07ff80ef17ffb8fc93 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 19 Aug 2020 19:42:58 -0600 Subject: [PATCH 4/8] Remove debugging --- src/utils/membership.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/membership.ts b/src/utils/membership.ts index 14a3ced739..68ac958490 100644 --- a/src/utils/membership.ts +++ b/src/utils/membership.ts @@ -91,7 +91,7 @@ export async function leaveRoomBehaviour(roomId: string) { } let results: { [roomId: string]: Error & { errcode: string, message: string } } = {}; - if (!leavingAllVersions || true) { + if (!leavingAllVersions) { try { await MatrixClientPeg.get().leave(roomId); } catch (e) { From c815a370e7cec593c57a3f4d03c80e0b023070de Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 20 Aug 2020 20:46:31 -0600 Subject: [PATCH 5/8] Remove some unused components We no longer have tinting support, so remove it. We still need the `Tinter` to exist though as it's used in quite a few places (though does nothing). Similarly, we have to keep the `roomColor` setting due to it being used in a few places - another PR can take away the tinter support properly. The room tile context menu and top left menu are artifacts of the old room list. The end to end tests weren't failing before as the code path is unused, however it seems worthwhile to keep it as we will eventually need it. --- res/css/_components.scss | 3 - .../context_menus/_RoomTileContextMenu.scss | 114 ----- res/css/views/context_menus/_TopLeftMenu.scss | 96 ----- .../views/room_settings/_ColorSettings.scss | 39 -- .../context_menus/RoomTileContextMenu.js | 404 ------------------ .../views/context_menus/TopLeftMenu.js | 155 ------- .../views/room_settings/ColorSettings.js | 154 ------- .../end-to-end-tests/src/usecases/settings.js | 4 +- 8 files changed, 2 insertions(+), 967 deletions(-) delete mode 100644 res/css/views/context_menus/_RoomTileContextMenu.scss delete mode 100644 res/css/views/context_menus/_TopLeftMenu.scss delete mode 100644 res/css/views/room_settings/_ColorSettings.scss delete mode 100644 src/components/views/context_menus/RoomTileContextMenu.js delete mode 100644 src/components/views/context_menus/TopLeftMenu.js delete mode 100644 src/components/views/room_settings/ColorSettings.js diff --git a/res/css/_components.scss b/res/css/_components.scss index aedb5c1334..5145133127 100644 --- a/res/css/_components.scss +++ b/res/css/_components.scss @@ -53,10 +53,8 @@ @import "./views/avatars/_PulsedAvatar.scss"; @import "./views/context_menus/_IconizedContextMenu.scss"; @import "./views/context_menus/_MessageContextMenu.scss"; -@import "./views/context_menus/_RoomTileContextMenu.scss"; @import "./views/context_menus/_StatusMessageContextMenu.scss"; @import "./views/context_menus/_TagTileContextMenu.scss"; -@import "./views/context_menus/_TopLeftMenu.scss"; @import "./views/context_menus/_WidgetContextMenu.scss"; @import "./views/dialogs/_AddressPickerDialog.scss"; @import "./views/dialogs/_Analytics.scss"; @@ -157,7 +155,6 @@ @import "./views/right_panel/_UserInfo.scss"; @import "./views/right_panel/_VerificationPanel.scss"; @import "./views/room_settings/_AliasSettings.scss"; -@import "./views/room_settings/_ColorSettings.scss"; @import "./views/rooms/_AppsDrawer.scss"; @import "./views/rooms/_Autocomplete.scss"; @import "./views/rooms/_AuxPanel.scss"; diff --git a/res/css/views/context_menus/_RoomTileContextMenu.scss b/res/css/views/context_menus/_RoomTileContextMenu.scss deleted file mode 100644 index 9697ac9bef..0000000000 --- a/res/css/views/context_menus/_RoomTileContextMenu.scss +++ /dev/null @@ -1,114 +0,0 @@ -/* -Copyright 2015, 2016 OpenMarket Ltd - -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. -*/ - -.mx_RoomTileContextMenu { - padding: 6px; -} - -.mx_RoomTileContextMenu_tag_icon { - padding-right: 8px; - padding-left: 4px; - display: inline-block; -} - -.mx_RoomTileContextMenu_tag_icon_set { - padding-right: 8px; - padding-left: 4px; - display: none; -} - -.mx_RoomTileContextMenu_tag_field, .mx_RoomTileContextMenu_leave { - padding-top: 8px; - padding-right: 20px; - padding-bottom: 8px; - cursor: pointer; - white-space: nowrap; - display: flex; - align-items: center; - line-height: $font-16px; -} - -.mx_RoomTileContextMenu_tag_field.mx_RoomTileContextMenu_tag_fieldSet { - font-weight: bold; -} - -.mx_RoomTileContextMenu_tag_field.mx_RoomTileContextMenu_tag_fieldSet .mx_RoomTileContextMenu_tag_icon { - display: none; -} - -.mx_RoomTileContextMenu_tag_field.mx_RoomTileContextMenu_tag_fieldSet .mx_RoomTileContextMenu_tag_icon_set { - display: inline-block; -} - -.mx_RoomTileContextMenu_tag_field.mx_RoomTileContextMenu_tag_fieldDisabled { - color: rgba(0, 0, 0, 0.2); -} - -.mx_RoomTileContextMenu_separator { - margin-top: 0; - margin-bottom: 0; - border-bottom-style: none; - border-left-style: none; - border-right-style: none; - border-top-style: solid; - border-top-width: 1px; - border-color: $menu-border-color; -} - -.mx_RoomTileContextMenu_leave { - color: $warning-color; -} - -.mx_RoomTileContextMenu_notif_picker { - position: absolute; - top: 16px; - left: 5px; -} - -.mx_RoomTileContextMenu_notif_field { - padding-top: 4px; - padding-right: 6px; - padding-bottom: 10px; - padding-left: 8px; /* 20px */ - cursor: pointer; - white-space: nowrap; - display: flex; - align-items: center; -} - -.mx_RoomTileContextMenu_notif_field.mx_RoomTileContextMenu_notif_fieldSet { - font-weight: bold; -} - -.mx_RoomTileContextMenu_notif_field.mx_RoomTileContextMenu_notif_fieldDisabled { - color: rgba(0, 0, 0, 0.2); -} - -.mx_RoomTileContextMenu_notif_icon { - padding-right: 4px; - padding-left: 4px; -} - -.mx_RoomTileContextMenu_notif_activeIcon { - display: inline-block; - opacity: 0; - position: relative; - left: -5px; -} - -.mx_RoomTileContextMenu_notif_fieldSet .mx_RoomTileContextMenu_notif_activeIcon { - opacity: 1; -} diff --git a/res/css/views/context_menus/_TopLeftMenu.scss b/res/css/views/context_menus/_TopLeftMenu.scss deleted file mode 100644 index e0f5dd47bd..0000000000 --- a/res/css/views/context_menus/_TopLeftMenu.scss +++ /dev/null @@ -1,96 +0,0 @@ -/* -Copyright 2018 New Vector Ltd - -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. -*/ - -.mx_TopLeftMenu { - min-width: 210px; - border-radius: 4px; - - .mx_TopLeftMenu_greyedText { - font-size: $font-12px; - opacity: 0.5; - } - - .mx_TopLeftMenu_upgradeLink { - font-size: $font-12px; - - img { - margin-left: 5px; - } - } - - .mx_TopLeftMenu_section:not(:last-child) { - border-bottom: 1px solid $menu-border-color; - } - - .mx_TopLeftMenu_section_noIcon { - margin: 5px 0; - padding: 5px 20px 5px 15px; - - div:not(:first-child) { - margin-top: 5px; - } - } - - .mx_TopLeftMenu_section_withIcon { - margin: 5px 0; - padding: 0; - list-style: none; - - .mx_TopLeftMenu_icon_home::after { - mask-image: url('$(res)/img/feather-customised/home.svg'); - } - - .mx_TopLeftMenu_icon_help::after { - mask-image: url('$(res)/img/feather-customised/life-buoy.svg'); - } - - .mx_TopLeftMenu_icon_settings::after { - mask-image: url('$(res)/img/feather-customised/settings.svg'); - } - - .mx_TopLeftMenu_icon_signin::after { - mask-image: url('$(res)/img/feather-customised/sign-in.svg'); - } - - .mx_TopLeftMenu_icon_signout::after { - mask-image: url('$(res)/img/feather-customised/sign-out.svg'); - } - - .mx_AccessibleButton::after { - mask-repeat: no-repeat; - mask-position: 0 center; - mask-size: $font-16px; - position: absolute; - width: $font-16px; - height: $font-16px; - content: ""; - top: 5px; - left: 14px; - background-color: $primary-fg-color; - } - - .mx_AccessibleButton { - position: relative; - cursor: pointer; - white-space: nowrap; - padding: 5px 20px 5px 43px; - } - - .mx_AccessibleButton:hover { - background-color: $menu-selected-color; - } - } -} diff --git a/res/css/views/room_settings/_ColorSettings.scss b/res/css/views/room_settings/_ColorSettings.scss deleted file mode 100644 index fc6a4443ad..0000000000 --- a/res/css/views/room_settings/_ColorSettings.scss +++ /dev/null @@ -1,39 +0,0 @@ -/* -Copyright 2019 New Vector Ltd. - -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. -*/ - -.mx_ColorSettings_roomColor { - display: inline-block; - position: relative; - width: 37px; - height: 37px; - border: 1px solid #979797; - margin-right: 13px; - cursor: pointer; -} - -.mx_ColorSettings_roomColor_selected { - position: absolute; - left: 10px; - top: 4px; - cursor: default !important; -} - -.mx_ColorSettings_roomColorPrimary { - height: 10px; - position: absolute; - bottom: 0px; - width: 100%; -} diff --git a/src/components/views/context_menus/RoomTileContextMenu.js b/src/components/views/context_menus/RoomTileContextMenu.js deleted file mode 100644 index b08cf3be60..0000000000 --- a/src/components/views/context_menus/RoomTileContextMenu.js +++ /dev/null @@ -1,404 +0,0 @@ -/* -Copyright 2015, 2016 OpenMarket Ltd -Copyright 2017 Vector Creations Ltd -Copyright 2019 Michael Telatynski <7t3chguy@gmail.com> -Copyright 2019 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 PropTypes from 'prop-types'; -import createReactClass from 'create-react-class'; -import classNames from 'classnames'; -import * as sdk from '../../../index'; -import { _t, _td } from '../../../languageHandler'; -import {MatrixClientPeg} from '../../../MatrixClientPeg'; -import dis from '../../../dispatcher/dispatcher'; -import DMRoomMap from '../../../utils/DMRoomMap'; -import * as Rooms from '../../../Rooms'; -import * as RoomNotifs from '../../../RoomNotifs'; -import Modal from '../../../Modal'; -import RoomListActions from '../../../actions/RoomListActions'; -import RoomViewStore from '../../../stores/RoomViewStore'; -import {sleep} from "../../../utils/promise"; -import {MenuItem, MenuItemCheckbox, MenuItemRadio} from "../../structures/ContextMenu"; - -const RoomTagOption = ({active, onClick, src, srcSet, label}) => { - const classes = classNames('mx_RoomTileContextMenu_tag_field', { - 'mx_RoomTileContextMenu_tag_fieldSet': active, - 'mx_RoomTileContextMenu_tag_fieldDisabled': false, - }); - - return ( - - - - { label } - - ); -}; - -const NotifOption = ({active, onClick, src, label}) => { - const classes = classNames('mx_RoomTileContextMenu_notif_field', { - 'mx_RoomTileContextMenu_notif_fieldSet': active, - }); - - return ( - - - - { label } - - ); -}; - -export default createReactClass({ - displayName: 'RoomTileContextMenu', - - propTypes: { - room: PropTypes.object.isRequired, - /* callback called when the menu is dismissed */ - onFinished: PropTypes.func, - }, - - getInitialState() { - const dmRoomMap = new DMRoomMap(MatrixClientPeg.get()); - return { - roomNotifState: RoomNotifs.getRoomNotifsState(this.props.room.roomId), - isFavourite: this.props.room.tags.hasOwnProperty("m.favourite"), - isLowPriority: this.props.room.tags.hasOwnProperty("m.lowpriority"), - isDirectMessage: Boolean(dmRoomMap.getUserIdForRoomId(this.props.room.roomId)), - }; - }, - - componentDidMount: function() { - this._unmounted = false; - }, - - componentWillUnmount: function() { - this._unmounted = true; - }, - - _toggleTag: function(tagNameOn, tagNameOff) { - if (!MatrixClientPeg.get().isGuest()) { - sleep(500).then(() => { - dis.dispatch(RoomListActions.tagRoom( - MatrixClientPeg.get(), - this.props.room, - tagNameOff, tagNameOn, - undefined, 0, - ), true); - - this.props.onFinished(); - }); - } - }, - - _onClickFavourite: function() { - // Tag room as 'Favourite' - if (!this.state.isFavourite && this.state.isLowPriority) { - this.setState({ - isFavourite: true, - isLowPriority: false, - }); - this._toggleTag("m.favourite", "m.lowpriority"); - } else if (this.state.isFavourite) { - this.setState({isFavourite: false}); - this._toggleTag(null, "m.favourite"); - } else if (!this.state.isFavourite) { - this.setState({isFavourite: true}); - this._toggleTag("m.favourite"); - } - }, - - _onClickLowPriority: function() { - // Tag room as 'Low Priority' - if (!this.state.isLowPriority && this.state.isFavourite) { - this.setState({ - isFavourite: false, - isLowPriority: true, - }); - this._toggleTag("m.lowpriority", "m.favourite"); - } else if (this.state.isLowPriority) { - this.setState({isLowPriority: false}); - this._toggleTag(null, "m.lowpriority"); - } else if (!this.state.isLowPriority) { - this.setState({isLowPriority: true}); - this._toggleTag("m.lowpriority"); - } - }, - - _onClickDM: function() { - if (MatrixClientPeg.get().isGuest()) return; - - const newIsDirectMessage = !this.state.isDirectMessage; - this.setState({ - isDirectMessage: newIsDirectMessage, - }); - - Rooms.guessAndSetDMRoom( - this.props.room, newIsDirectMessage, - ).then(sleep(500)).finally(() => { - // Close the context menu - if (this.props.onFinished) { - this.props.onFinished(); - } - }, (err) => { - const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createTrackedDialog('Failed to set Direct Message status of room', '', ErrorDialog, { - title: _t('Failed to set Direct Message status of room'), - description: ((err && err.message) ? err.message : _t('Operation failed')), - }); - }); - }, - - _onClickLeave: function() { - // Leave room - dis.dispatch({ - action: 'leave_room', - room_id: this.props.room.roomId, - }); - - // Close the context menu - if (this.props.onFinished) { - this.props.onFinished(); - } - }, - - _onClickReject: function() { - dis.dispatch({ - action: 'reject_invite', - room_id: this.props.room.roomId, - }); - - // Close the context menu - if (this.props.onFinished) { - this.props.onFinished(); - } - }, - - _onClickForget: function() { - // FIXME: duplicated with RoomSettings (and dead code in RoomView) - MatrixClientPeg.get().forget(this.props.room.roomId).then(() => { - // Switch to another room view if we're currently viewing the - // historical room - if (RoomViewStore.getRoomId() === this.props.room.roomId) { - dis.dispatch({ action: 'view_next_room' }); - } - }, function(err) { - const errCode = err.errcode || _td("unknown error code"); - const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createTrackedDialog('Failed to forget room', '', ErrorDialog, { - title: _t('Failed to forget room %(errCode)s', {errCode: errCode}), - description: ((err && err.message) ? err.message : _t('Operation failed')), - }); - }); - - // Close the context menu - if (this.props.onFinished) { - this.props.onFinished(); - } - }, - - _saveNotifState: function(newState) { - if (MatrixClientPeg.get().isGuest()) return; - - const oldState = this.state.roomNotifState; - const roomId = this.props.room.roomId; - - this.setState({ - roomNotifState: newState, - }); - RoomNotifs.setRoomNotifsState(roomId, newState).then(() => { - // delay slightly so that the user can see their state change - // before closing the menu - return sleep(500).then(() => { - if (this._unmounted) return; - // Close the context menu - if (this.props.onFinished) { - this.props.onFinished(); - } - }); - }, (error) => { - // TODO: some form of error notification to the user - // to inform them that their state change failed. - // For now we at least set the state back - if (this._unmounted) return; - this.setState({ - roomNotifState: oldState, - }); - }); - }, - - _onClickAlertMe: function() { - this._saveNotifState(RoomNotifs.ALL_MESSAGES_LOUD); - }, - - _onClickAllNotifs: function() { - this._saveNotifState(RoomNotifs.ALL_MESSAGES); - }, - - _onClickMentions: function() { - this._saveNotifState(RoomNotifs.MENTIONS_ONLY); - }, - - _onClickMute: function() { - this._saveNotifState(RoomNotifs.MUTE); - }, - - _renderNotifMenu: function() { - return ( -
-
- -
- - - - - -
- ); - }, - - _onClickSettings: function() { - dis.dispatch({ - action: 'open_room_settings', - room_id: this.props.room.roomId, - }); - if (this.props.onFinished) { - this.props.onFinished(); - } - }, - - _renderSettingsMenu: function() { - return ( -
- - - { _t('Settings') } - -
- ); - }, - - _renderLeaveMenu: function(membership) { - if (!membership) { - return null; - } - - let leaveClickHandler = null; - let leaveText = null; - - switch (membership) { - case "join": - leaveClickHandler = this._onClickLeave; - leaveText = _t('Leave'); - break; - case "leave": - case "ban": - leaveClickHandler = this._onClickForget; - leaveText = _t('Forget'); - break; - case "invite": - leaveClickHandler = this._onClickReject; - leaveText = _t('Reject'); - break; - } - - return ( -
- - - { leaveText } - -
- ); - }, - - _renderRoomTagMenu: function() { - return ( -
- - - -
- ); - }, - - render: function() { - const myMembership = this.props.room.getMyMembership(); - - switch (myMembership) { - case 'join': - return
- { this._renderNotifMenu() } -
- { this._renderLeaveMenu(myMembership) } -
- { this._renderRoomTagMenu() } -
- { this._renderSettingsMenu() } -
; - case 'invite': - return
- { this._renderLeaveMenu(myMembership) } -
; - default: - return
- { this._renderLeaveMenu(myMembership) } -
- { this._renderSettingsMenu() } -
; - } - }, -}); diff --git a/src/components/views/context_menus/TopLeftMenu.js b/src/components/views/context_menus/TopLeftMenu.js deleted file mode 100644 index ec99c63724..0000000000 --- a/src/components/views/context_menus/TopLeftMenu.js +++ /dev/null @@ -1,155 +0,0 @@ -/* -Copyright 2018, 2019 New Vector Ltd -Copyright 2019 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 PropTypes from 'prop-types'; -import dis from '../../../dispatcher/dispatcher'; -import { _t } from '../../../languageHandler'; -import LogoutDialog from "../dialogs/LogoutDialog"; -import Modal from "../../../Modal"; -import SdkConfig from '../../../SdkConfig'; -import { getHostingLink } from '../../../utils/HostingLink'; -import {MatrixClientPeg} from '../../../MatrixClientPeg'; -import {MenuItem} from "../../structures/ContextMenu"; -import * as sdk from "../../../index"; -import {getHomePageUrl} from "../../../utils/pages"; -import {Action} from "../../../dispatcher/actions"; - -export default class TopLeftMenu extends React.Component { - static propTypes = { - displayName: PropTypes.string.isRequired, - userId: PropTypes.string.isRequired, - onFinished: PropTypes.func, - - // Optional function to collect a reference to the container - // of this component directly. - containerRef: PropTypes.func, - }; - - constructor() { - super(); - this.viewHomePage = this.viewHomePage.bind(this); - this.openSettings = this.openSettings.bind(this); - this.signIn = this.signIn.bind(this); - this.signOut = this.signOut.bind(this); - } - - hasHomePage() { - return !!getHomePageUrl(SdkConfig.get()); - } - - render() { - const isGuest = MatrixClientPeg.get().isGuest(); - - const hostingSignupLink = getHostingLink('user-context-menu'); - let hostingSignup = null; - if (hostingSignupLink) { - hostingSignup =
- {_t( - "Upgrade to your own domain", {}, - { - a: sub => - {sub}, - }, - )} - - - -
; - } - - let homePageItem = null; - if (this.hasHomePage()) { - homePageItem = ( - - {_t("Home")} - - ); - } - - let signInOutItem; - if (isGuest) { - signInOutItem = ( - - {_t("Sign in")} - - ); - } else { - signInOutItem = ( - - {_t("Sign out")} - - ); - } - - const helpItem = ( - - {_t("Help")} - - ); - - const settingsItem = ( - - {_t("Settings")} - - ); - - return
-
-
{this.props.displayName}
-
{this.props.userId}
- {hostingSignup} -
-
    - {homePageItem} - {settingsItem} - {helpItem} - {signInOutItem} -
-
; - } - - openHelp = () => { - this.closeMenu(); - const RedesignFeedbackDialog = sdk.getComponent("views.dialogs.RedesignFeedbackDialog"); - Modal.createTrackedDialog('Report bugs & give feedback', '', RedesignFeedbackDialog); - }; - - viewHomePage() { - dis.dispatch({action: 'view_home_page'}); - this.closeMenu(); - } - - openSettings() { - dis.fire(Action.ViewUserSettings); - this.closeMenu(); - } - - signIn() { - dis.dispatch({action: 'start_login'}); - this.closeMenu(); - } - - signOut() { - Modal.createTrackedDialog('Logout E2E Export', '', LogoutDialog); - this.closeMenu(); - } - - closeMenu() { - if (this.props.onFinished) this.props.onFinished(); - } -} diff --git a/src/components/views/room_settings/ColorSettings.js b/src/components/views/room_settings/ColorSettings.js deleted file mode 100644 index 2179bd905e..0000000000 --- a/src/components/views/room_settings/ColorSettings.js +++ /dev/null @@ -1,154 +0,0 @@ -/* -Copyright 2016 OpenMarket Ltd - -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 PropTypes from 'prop-types'; -import createReactClass from 'create-react-class'; - -import Tinter from '../../../Tinter'; -import dis from '../../../dispatcher/dispatcher'; -import SettingsStore from "../../../settings/SettingsStore"; -import {SettingLevel} from "../../../settings/SettingLevel"; - -const ROOM_COLORS = [ - // magic room default values courtesy of Ribot - [Tinter.getKeyRgb()[0], Tinter.getKeyRgb()[1]], - ["#81bddb", "#eaf1f4"], - ["#bd79cb", "#f3eaf5"], - ["#c65d94", "#f5eaef"], - ["#e55e5e", "#f5eaea"], - ["#eca46f", "#f5eeea"], - ["#dad658", "#f5f4ea"], - ["#80c553", "#eef5ea"], - ["#bb814e", "#eee8e3"], - //["#595959", "#ececec"], // Grey makes everything appear disabled, so remove it for now -]; - -// Dev note: this component is not attached anywhere, but is left here as it -// has a high possibility of being used in the nearish future. -// Ref: https://github.com/vector-im/element-web/issues/8421 - -export default createReactClass({ - displayName: 'ColorSettings', - - propTypes: { - room: PropTypes.object.isRequired, - }, - - getInitialState: function() { - const data = { - index: 0, - primary_color: ROOM_COLORS[0][0], - secondary_color: ROOM_COLORS[0][1], - hasChanged: false, - }; - const scheme = SettingsStore.getValueAt(SettingLevel.ROOM_ACCOUNT, "roomColor", this.props.room.roomId); - - if (scheme.primary_color && scheme.secondary_color) { - // We only use the user's scheme if the scheme is valid. - data.primary_color = scheme.primary_color; - data.secondary_color = scheme.secondary_color; - } - data.index = this._getColorIndex(data); - - if (data.index === -1) { - // append the unrecognised colours to our palette - data.index = ROOM_COLORS.length; - ROOM_COLORS.push([ - scheme.primary_color, scheme.secondary_color, - ]); - } - return data; - }, - - saveSettings: function() { // : Promise - if (!this.state.hasChanged) { - return Promise.resolve(); // They didn't explicitly give a color to save. - } - const originalState = this.getInitialState(); - if (originalState.primary_color !== this.state.primary_color || - originalState.secondary_color !== this.state.secondary_color) { - console.log("ColorSettings: Saving new color"); - // We would like guests to be able to set room colour but currently - // they can't, so we still send the request but display a sensible - // error if it fails. - // TODO: Support guests for room color. Technically this is possible via granular settings - // Granular settings would mean the guest is forced to use the DEVICE level though. - SettingsStore.setValue("roomColor", this.props.room.roomId, SettingLevel.ROOM_ACCOUNT, { - primary_color: this.state.primary_color, - secondary_color: this.state.secondary_color, - }).catch(function(err) { - if (err.errcode === 'M_GUEST_ACCESS_FORBIDDEN') { - dis.dispatch({action: 'require_registration'}); - } - }); - } - return Promise.resolve(); // no color diff - }, - - _getColorIndex: function(scheme) { - if (!scheme || !scheme.primary_color || !scheme.secondary_color) { - return -1; - } - // XXX: we should validate these values - for (let i = 0; i < ROOM_COLORS.length; i++) { - const room_color = ROOM_COLORS[i]; - if (room_color[0] === String(scheme.primary_color).toLowerCase() && - room_color[1] === String(scheme.secondary_color).toLowerCase()) { - return i; - } - } - return -1; - }, - - _onColorSchemeChanged: function(index) { - // preview what the user just changed the scheme to. - Tinter.tint(ROOM_COLORS[index][0], ROOM_COLORS[index][1]); - this.setState({ - index: index, - primary_color: ROOM_COLORS[index][0], - secondary_color: ROOM_COLORS[index][1], - hasChanged: true, - }); - }, - - render: function() { - return ( -
- { ROOM_COLORS.map((room_color, i) => { - let selected; - if (i === this.state.index) { - selected = ( -
- ./ -
- ); - } - const boundClick = this._onColorSchemeChanged.bind(this, i); - return ( -
- { selected } -
-
- ); - }) } -
- ); - }, -}); diff --git a/test/end-to-end-tests/src/usecases/settings.js b/test/end-to-end-tests/src/usecases/settings.js index a405fde9fb..52e4bb7e0a 100644 --- a/test/end-to-end-tests/src/usecases/settings.js +++ b/test/end-to-end-tests/src/usecases/settings.js @@ -18,9 +18,9 @@ limitations under the License. const assert = require('assert'); async function openSettings(session, section) { - const menuButton = await session.query(".mx_TopLeftMenuButton_name"); + const menuButton = await session.query(".mx_UserMenu"); await menuButton.click(); - const settingsItem = await session.query(".mx_TopLeftMenu_icon_settings"); + const settingsItem = await session.query(".mx_UserMenu_iconSettings"); await settingsItem.click(); if (section) { const sectionButton = await session.query( From fd062720623c65a0896a7efeb7fd02ccbc0d547f Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 20 Aug 2020 20:50:28 -0600 Subject: [PATCH 6/8] Update i18n --- src/i18n/strings/en_EN.json | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 4c0557ac70..85c587426a 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -1883,23 +1883,12 @@ "Source URL": "Source URL", "Collapse Reply Thread": "Collapse Reply Thread", "Report Content": "Report Content", - "Failed to set Direct Message status of room": "Failed to set Direct Message status of room", - "Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s", - "Notification settings": "Notification settings", - "All messages (noisy)": "All messages (noisy)", - "Mentions only": "Mentions only", - "Leave": "Leave", - "Forget": "Forget", - "Direct Chat": "Direct Chat", "Clear status": "Clear status", "Update status": "Update status", "Set status": "Set status", "Set a new status...": "Set a new status...", "View Community": "View Community", "Hide": "Hide", - "Home": "Home", - "Sign in": "Sign in", - "Help": "Help", "Reload": "Reload", "Take picture": "Take picture", "Remove for everyone": "Remove for everyone", @@ -1940,6 +1929,7 @@ "Phone": "Phone", "Not sure of your password? Set a new one": "Not sure of your password? Set a new one", "Sign in with": "Sign in with", + "Sign in": "Sign in", "No identity server is configured so you cannot add an email address in order to reset your password in the future.": "No identity server is configured so you cannot add an email address in order to reset your password in the future.", "If you don't specify an email address, you won't be able to reset your password. Are you sure?": "If you don't specify an email address, you won't be able to reset your password. Are you sure?", "Use an email address to recover your account": "Use an email address to recover your account", @@ -2002,6 +1992,7 @@ "You are an administrator of this community. You will not be able to rejoin without an invite from another administrator.": "You are an administrator of this community. You will not be able to rejoin without an invite from another administrator.", "Leave Community": "Leave Community", "Leave %(groupName)s?": "Leave %(groupName)s?", + "Leave": "Leave", "Unable to leave community": "Unable to leave community", "Community Settings": "Community Settings", "Want more than a community? Get your own server": "Want more than a community? Get your own server", @@ -2032,6 +2023,7 @@ "Failed to reject invitation": "Failed to reject invitation", "This room is not public. You will not be able to rejoin without an invite.": "This room is not public. You will not be able to rejoin without an invite.", "Are you sure you want to leave the room '%(roomName)s'?": "Are you sure you want to leave the room '%(roomName)s'?", + "Failed to forget room %(errCode)s": "Failed to forget room %(errCode)s", "Signed Out": "Signed Out", "For security, this session has been signed out. Please sign in again.": "For security, this session has been signed out. Please sign in again.", "Terms and Conditions": "Terms and Conditions", @@ -2103,9 +2095,11 @@ "Uploading %(filename)s and %(count)s others|other": "Uploading %(filename)s and %(count)s others", "Uploading %(filename)s and %(count)s others|zero": "Uploading %(filename)s", "Uploading %(filename)s and %(count)s others|one": "Uploading %(filename)s and %(count)s other", + "Home": "Home", "Switch to light mode": "Switch to light mode", "Switch to dark mode": "Switch to dark mode", "Switch theme": "Switch theme", + "Notification settings": "Notification settings", "Security & privacy": "Security & privacy", "All settings": "All settings", "Feedback": "Feedback", From 6a03c0a3c00ae288cd3c73013a1698cc9eee690d Mon Sep 17 00:00:00 2001 From: David Baker Date: Fri, 21 Aug 2020 10:32:51 +0100 Subject: [PATCH 7/8] Send mx_local_settings in rageshake Perhaps ideally we should get a complete dump of the settings in effect out of the settings manager, but all I want for now is the webrtc audio inputs and outputs, so let's send the ones stored locally. --- src/rageshake/submit-rageshake.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/rageshake/submit-rageshake.ts b/src/rageshake/submit-rageshake.ts index 76b0444052..04a0ad934d 100644 --- a/src/rageshake/submit-rageshake.ts +++ b/src/rageshake/submit-rageshake.ts @@ -182,6 +182,8 @@ export default async function sendBugReport(bugReportEndpoint: string, opts: IOp } } + body.append("mx_local_settings", localStorage.getItem('mx_local_settings')); + if (opts.sendLogs) { progressCallback(_t("Collecting logs")); const logs = await rageshake.getLogsForReport(); From 9193c81008056dac32272aa9ce04bda411566bb1 Mon Sep 17 00:00:00 2001 From: Heiko Carrasco Date: Fri, 21 Aug 2020 11:36:57 +0200 Subject: [PATCH 8/8] Fix image avatar view for 1:1 rooms Signed-off-by: Heiko Carrasco --- src/components/views/avatars/RoomAvatar.tsx | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/components/views/avatars/RoomAvatar.tsx b/src/components/views/avatars/RoomAvatar.tsx index 3317ed3a60..e37dff4bfe 100644 --- a/src/components/views/avatars/RoomAvatar.tsx +++ b/src/components/views/avatars/RoomAvatar.tsx @@ -114,9 +114,12 @@ export default class RoomAvatar extends React.Component { } private onRoomAvatarClick = () => { - const avatarUrl = this.props.room.getAvatarUrl( - MatrixClientPeg.get().getHomeserverUrl(), - null, null, null, false); + const avatarUrl = Avatar.avatarUrlForRoom( + this.props.room, + null, + null, + null, + ); const params = { src: avatarUrl, name: this.props.room.name,