From 24705d02b77d14cbee3bc12fadcc633c15854c5e Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Wed, 7 Aug 2019 12:13:59 -0600 Subject: [PATCH] Replace DM logic in `view_start_chat_or_reuse` Part of https://github.com/vector-im/riot-web/issues/10416 This code is used by the welcome bot logic and the groups/communities section of the app. goHomeOnCancel can be removed because no matter what happens we'll end up in a room with the user (and we aren't showing a dialog anymore). --- src/components/structures/GroupView.js | 1 - src/components/structures/MatrixChat.js | 50 ++++++++++--------------- 2 files changed, 19 insertions(+), 32 deletions(-) diff --git a/src/components/structures/GroupView.js b/src/components/structures/GroupView.js index 7bf5400942..d5fa8fa5ae 100644 --- a/src/components/structures/GroupView.js +++ b/src/components/structures/GroupView.js @@ -343,7 +343,6 @@ const FeaturedUser = React.createClass({ dis.dispatch({ action: 'view_start_chat_or_reuse', user_id: this.props.summaryInfo.user_id, - go_home_on_cancel: false, }); }, diff --git a/src/components/structures/MatrixChat.js b/src/components/structures/MatrixChat.js index db5b7d034b..bcc0923f14 100644 --- a/src/components/structures/MatrixChat.js +++ b/src/components/structures/MatrixChat.js @@ -584,7 +584,7 @@ export default React.createClass({ this._setMxId(payload); break; case 'view_start_chat_or_reuse': - this._chatCreateOrReuse(payload.user_id, payload.go_home_on_cancel); + this._chatCreateOrReuse(payload.user_id); break; case 'view_create_chat': showStartChatInviteDialog(); @@ -945,12 +945,7 @@ export default React.createClass({ }); }, - _chatCreateOrReuse: function(userId, goHomeOnCancel) { - if (goHomeOnCancel === undefined) goHomeOnCancel = true; - - const ChatCreateOrReuseDialog = sdk.getComponent( - 'views.dialogs.ChatCreateOrReuseDialog', - ); + _chatCreateOrReuse: function(userId) { // Use a deferred action to reshow the dialog once the user has registered if (MatrixClientPeg.get().isGuest()) { // No point in making 2 DMs with welcome bot. This assumes view_set_mxid will @@ -975,30 +970,23 @@ export default React.createClass({ return; } - const close = Modal.createTrackedDialog('Chat create or reuse', '', ChatCreateOrReuseDialog, { - userId: userId, - onFinished: (success) => { - if (!success && goHomeOnCancel) { - // Dialog cancelled, default to home - dis.dispatch({ action: 'view_home_page' }); - } - }, - onNewDMClick: () => { - dis.dispatch({ - action: 'start_chat', - user_id: userId, - }); - // Close the dialog, indicate success (calls onFinished(true)) - close(true); - }, - onExistingRoomSelected: (roomId) => { - dis.dispatch({ - action: 'view_room', - room_id: roomId, - }); - close(true); - }, - }).close; + // TODO: Immutable DMs replaces this + + const client = MatrixClientPeg.get(); + const dmRoomMap = new DMRoomMap(client); + const dmRooms = dmRoomMap.getDMRoomsForUserId(userId); + + if (dmRooms.length > 0) { + dis.dispatch({ + action: 'view_room', + room_id: dmRooms[0], + }); + } else { + dis.dispatch({ + action: 'start_chat', + user_id: userId, + }); + } }, _leaveRoomWarnings: function(roomId) {