From 139b5663fe4015934d3833bdfe0cdf9b4e756ada Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 22 Jan 2020 21:14:53 -0700 Subject: [PATCH 1/3] Remove user lists feature flag, making it the default Fixes https://github.com/vector-im/riot-web/issues/11201 --- src/RoomInvite.js | 156 +++------------------------------------ src/settings/Settings.js | 6 -- 2 files changed, 12 insertions(+), 150 deletions(-) diff --git a/src/RoomInvite.js b/src/RoomInvite.js index 2eccf69b0f..839d677069 100644 --- a/src/RoomInvite.js +++ b/src/RoomInvite.js @@ -20,13 +20,8 @@ import React from 'react'; import {MatrixClientPeg} from './MatrixClientPeg'; import MultiInviter from './utils/MultiInviter'; import Modal from './Modal'; -import { getAddressType } from './UserAddress'; -import createRoom from './createRoom'; import * as sdk from './'; -import dis from './dispatcher'; -import DMRoomMap from './utils/DMRoomMap'; import { _t } from './languageHandler'; -import SettingsStore from "./settings/SettingsStore"; import {KIND_DM, KIND_INVITE} from "./components/views/dialogs/InviteDialog"; /** @@ -44,64 +39,21 @@ export function inviteMultipleToRoom(roomId, addrs) { } export function showStartChatInviteDialog() { - if (SettingsStore.isFeatureEnabled("feature_ftue_dms")) { - // This new dialog handles the room creation internally - we don't need to worry about it. - const InviteDialog = sdk.getComponent("dialogs.InviteDialog"); - Modal.createTrackedDialog( - 'Start DM', '', InviteDialog, {kind: KIND_DM}, - /*className=*/null, /*isPriority=*/false, /*isStatic=*/true, - ); - return; - } - - const AddressPickerDialog = sdk.getComponent("dialogs.AddressPickerDialog"); - - Modal.createTrackedDialog('Start a chat', '', AddressPickerDialog, { - title: _t('Start a chat'), - description: _t("Who would you like to communicate with?"), - placeholder: (validAddressTypes) => { - // The set of valid address type can be mutated inside the dialog - // when you first have no IS but agree to use one in the dialog. - if (validAddressTypes.includes('email')) { - return _t("Email, name or Matrix ID"); - } - return _t("Name or Matrix ID"); - }, - validAddressTypes: ['mx-user-id', 'email'], - button: _t("Start Chat"), - onFinished: _onStartDmFinished, - }, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); + // This dialog handles the room creation internally - we don't need to worry about it. + const InviteDialog = sdk.getComponent("dialogs.InviteDialog"); + Modal.createTrackedDialog( + 'Start DM', '', InviteDialog, {kind: KIND_DM}, + /*className=*/null, /*isPriority=*/false, /*isStatic=*/true, + ); } export function showRoomInviteDialog(roomId) { - if (SettingsStore.isFeatureEnabled("feature_ftue_dms")) { - // This new dialog handles the room creation internally - we don't need to worry about it. - const InviteDialog = sdk.getComponent("dialogs.InviteDialog"); - Modal.createTrackedDialog( - 'Invite Users', '', InviteDialog, {kind: KIND_INVITE, roomId}, - /*className=*/null, /*isPriority=*/false, /*isStatic=*/true, - ); - return; - } - - const AddressPickerDialog = sdk.getComponent("dialogs.AddressPickerDialog"); - - Modal.createTrackedDialog('Chat Invite', '', AddressPickerDialog, { - title: _t('Invite new room members'), - button: _t('Send Invites'), - placeholder: (validAddressTypes) => { - // The set of valid address type can be mutated inside the dialog - // when you first have no IS but agree to use one in the dialog. - if (validAddressTypes.includes('email')) { - return _t("Email, name or Matrix ID"); - } - return _t("Name or Matrix ID"); - }, - validAddressTypes: ['mx-user-id', 'email'], - onFinished: (shouldInvite, addrs) => { - _onRoomInviteFinished(roomId, shouldInvite, addrs); - }, - }, /*className=*/null, /*isPriority=*/false, /*isStatic=*/true); + // This dialog handles the room creation internally - we don't need to worry about it. + const InviteDialog = sdk.getComponent("dialogs.InviteDialog"); + Modal.createTrackedDialog( + 'Invite Users', '', InviteDialog, {kind: KIND_INVITE, roomId}, + /*className=*/null, /*isPriority=*/false, /*isStatic=*/true, + ); } /** @@ -122,60 +74,6 @@ export function isValid3pidInvite(event) { return true; } -// TODO: Canonical DMs replaces this -function _onStartDmFinished(shouldInvite, addrs) { - if (!shouldInvite) return; - - const addrTexts = addrs.map((addr) => addr.address); - - if (_isDmChat(addrTexts)) { - const rooms = _getDirectMessageRooms(addrTexts[0]); - if (rooms.length > 0) { - // A Direct Message room already exists for this user, so reuse it - dis.dispatch({ - action: 'view_room', - room_id: rooms[0], - should_peek: false, - joining: false, - }); - } else { - // Start a new DM chat - createRoom({dmUserId: addrTexts[0]}).catch((err) => { - const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createTrackedDialog('Failed to start chat', '', ErrorDialog, { - title: _t("Failed to start chat"), - description: ((err && err.message) ? err.message : _t("Operation failed")), - }); - }); - } - } else if (addrTexts.length === 1) { - // Start a new DM chat - createRoom({dmUserId: addrTexts[0]}).catch((err) => { - const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createTrackedDialog('Failed to start chat', '', ErrorDialog, { - title: _t("Failed to start chat"), - description: ((err && err.message) ? err.message : _t("Operation failed")), - }); - }); - } else { - // Start multi user chat - let room; - createRoom().then((roomId) => { - room = MatrixClientPeg.get().getRoom(roomId); - return inviteMultipleToRoom(roomId, addrTexts); - }).then((result) => { - return _showAnyInviteErrors(result.states, room, result.inviter); - }).catch((err) => { - console.error(err.stack); - const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); - Modal.createTrackedDialog('Failed to invite', '', ErrorDialog, { - title: _t("Failed to invite"), - description: ((err && err.message) ? err.message : _t("Operation failed")), - }); - }); - } -} - export function inviteUsersToRoom(roomId, userIds) { return inviteMultipleToRoom(roomId, userIds).then((result) => { const room = MatrixClientPeg.get().getRoom(roomId); @@ -190,24 +88,6 @@ export function inviteUsersToRoom(roomId, userIds) { }); } -function _onRoomInviteFinished(roomId, shouldInvite, addrs) { - if (!shouldInvite) return; - - const addrTexts = addrs.map((addr) => addr.address); - - // Invite new users to a room - inviteUsersToRoom(roomId, addrTexts); -} - -// TODO: Immutable DMs replaces this -function _isDmChat(addrTexts) { - if (addrTexts.length === 1 && getAddressType(addrTexts[0]) === 'mx-user-id') { - return true; - } else { - return false; - } -} - function _showAnyInviteErrors(addrs, room, inviter) { // Show user any errors const failedUsers = Object.keys(addrs).filter(a => addrs[a] === 'error'); @@ -243,15 +123,3 @@ function _showAnyInviteErrors(addrs, room, inviter) { return addrs; } - -function _getDirectMessageRooms(addr) { - const dmRoomMap = new DMRoomMap(MatrixClientPeg.get()); - const dmRooms = dmRoomMap.getDMRoomsForUserId(addr); - const rooms = dmRooms.filter((dmRoom) => { - const room = MatrixClientPeg.get().getRoom(dmRoom); - if (room) { - return room.getMyMembership() === 'join'; - } - }); - return rooms; -} diff --git a/src/settings/Settings.js b/src/settings/Settings.js index eacf63e55d..e908861821 100644 --- a/src/settings/Settings.js +++ b/src/settings/Settings.js @@ -128,12 +128,6 @@ export const SETTINGS = { supportedLevels: LEVELS_FEATURE, default: false, }, - "feature_ftue_dms": { - isFeature: true, - displayName: _td("New invite dialog"), - supportedLevels: LEVELS_FEATURE, - default: false, - }, "feature_presence_in_room_list": { isFeature: true, displayName: _td("Show a presence dot next to DMs in the room list"), From a196ecc8911fc951ac18ab6ed28c2a7426f7bc99 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 22 Jan 2020 21:17:40 -0700 Subject: [PATCH 2/3] Fix i18n --- src/i18n/strings/en_EN.json | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index d19cbb9bfd..6a68c70d56 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -121,15 +121,8 @@ "Moderator": "Moderator", "Admin": "Admin", "Custom (%(level)s)": "Custom (%(level)s)", - "Start a chat": "Start a chat", - "Who would you like to communicate with?": "Who would you like to communicate with?", - "Email, name or Matrix ID": "Email, name or Matrix ID", - "Start Chat": "Start Chat", - "Invite new room members": "Invite new room members", - "Send Invites": "Send Invites", - "Failed to start chat": "Failed to start chat", - "Operation failed": "Operation failed", "Failed to invite": "Failed to invite", + "Operation failed": "Operation failed", "Failed to invite users to the room:": "Failed to invite users to the room:", "Failed to invite the following users to the %(roomName)s room:": "Failed to invite the following users to the %(roomName)s room:", "You need to be logged in.": "You need to be logged in.", @@ -372,7 +365,6 @@ "Render simple counters in room header": "Render simple counters in room header", "Multiple integration managers": "Multiple integration managers", "Try out new ways to ignore people (experimental)": "Try out new ways to ignore people (experimental)", - "New invite dialog": "New invite dialog", "Show a presence dot next to DMs in the room list": "Show a presence dot next to DMs in the room list", "Enable cross-signing to verify per-user instead of per-device (in development)": "Enable cross-signing to verify per-user instead of per-device (in development)", "Enable local event indexing and E2EE search (requires restart)": "Enable local event indexing and E2EE search (requires restart)", @@ -943,6 +935,7 @@ "Invite": "Invite", "Share Link to User": "Share Link to User", "User Options": "User Options", + "Start a chat": "Start a chat", "Direct chats": "Direct chats", "Remove recent messages": "Remove recent messages", "Unmute": "Unmute", From 65450e893c9862ef2ef7cdaeb22267bd19f3d731 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 22 Jan 2020 22:40:02 -0700 Subject: [PATCH 3/3] Try and fix e2e tests for new invite dialog --- test/end-to-end-tests/src/usecases/invite.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/end-to-end-tests/src/usecases/invite.js b/test/end-to-end-tests/src/usecases/invite.js index 6bee5dfd6f..75ebc61a88 100644 --- a/test/end-to-end-tests/src/usecases/invite.js +++ b/test/end-to-end-tests/src/usecases/invite.js @@ -31,10 +31,11 @@ module.exports = async function invite(session, userId) { } const inviteButton = await session.query(".mx_MemberList_invite"); await inviteButton.click(); - const inviteTextArea = await session.query(".mx_AddressPickerDialog textarea"); + const inviteTextArea = await session.query(".mx_InviteDialog_editor textarea"); await inviteTextArea.type(userId); - await inviteTextArea.press("Enter"); - const confirmButton = await session.query(".mx_Dialog_primary"); + const selectUserItem = await session.query(".mx_InviteDialog_roomTile"); + await selectUserItem.click(); + const confirmButton = await session.query(".mx_InviteDialog_goButton"); await confirmButton.click(); session.log.done(); };