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).
This commit is contained in:
Travis Ralston 2019-08-07 12:13:59 -06:00
parent 3144b9f1a2
commit 24705d02b7
2 changed files with 19 additions and 32 deletions

View file

@ -343,7 +343,6 @@ const FeaturedUser = React.createClass({
dis.dispatch({ dis.dispatch({
action: 'view_start_chat_or_reuse', action: 'view_start_chat_or_reuse',
user_id: this.props.summaryInfo.user_id, user_id: this.props.summaryInfo.user_id,
go_home_on_cancel: false,
}); });
}, },

View file

@ -584,7 +584,7 @@ export default React.createClass({
this._setMxId(payload); this._setMxId(payload);
break; break;
case 'view_start_chat_or_reuse': case 'view_start_chat_or_reuse':
this._chatCreateOrReuse(payload.user_id, payload.go_home_on_cancel); this._chatCreateOrReuse(payload.user_id);
break; break;
case 'view_create_chat': case 'view_create_chat':
showStartChatInviteDialog(); showStartChatInviteDialog();
@ -945,12 +945,7 @@ export default React.createClass({
}); });
}, },
_chatCreateOrReuse: function(userId, goHomeOnCancel) { _chatCreateOrReuse: function(userId) {
if (goHomeOnCancel === undefined) goHomeOnCancel = true;
const ChatCreateOrReuseDialog = sdk.getComponent(
'views.dialogs.ChatCreateOrReuseDialog',
);
// Use a deferred action to reshow the dialog once the user has registered // Use a deferred action to reshow the dialog once the user has registered
if (MatrixClientPeg.get().isGuest()) { if (MatrixClientPeg.get().isGuest()) {
// No point in making 2 DMs with welcome bot. This assumes view_set_mxid will // No point in making 2 DMs with welcome bot. This assumes view_set_mxid will
@ -975,30 +970,23 @@ export default React.createClass({
return; return;
} }
const close = Modal.createTrackedDialog('Chat create or reuse', '', ChatCreateOrReuseDialog, { // TODO: Immutable DMs replaces this
userId: userId,
onFinished: (success) => { const client = MatrixClientPeg.get();
if (!success && goHomeOnCancel) { const dmRoomMap = new DMRoomMap(client);
// Dialog cancelled, default to home const dmRooms = dmRoomMap.getDMRoomsForUserId(userId);
dis.dispatch({ action: 'view_home_page' });
} if (dmRooms.length > 0) {
}, dis.dispatch({
onNewDMClick: () => { action: 'view_room',
room_id: dmRooms[0],
});
} else {
dis.dispatch({ dis.dispatch({
action: 'start_chat', action: 'start_chat',
user_id: userId, 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;
}, },
_leaveRoomWarnings: function(roomId) { _leaveRoomWarnings: function(roomId) {