Merge pull request #1717 from matrix-org/t3chguy/fix_3pid_dm_rooms

Use invite_3pid prop of createRoom instead of manual invite after create
pull/21833/head
David Baker 2018-02-05 12:07:43 +00:00 committed by GitHub
commit 0d04c8dab5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 4 deletions

View File

@ -85,9 +85,7 @@ function _onStartChatFinished(shouldInvite, addrs) {
if (rooms.length > 0) {
// A Direct Message room already exists for this user, so select a
// room from a list that is similar to the one in MemberInfo panel
const ChatCreateOrReuseDialog = sdk.getComponent(
"views.dialogs.ChatCreateOrReuseDialog",
);
const ChatCreateOrReuseDialog = sdk.getComponent("views.dialogs.ChatCreateOrReuseDialog");
const close = Modal.createTrackedDialog('Create or Reuse', '', ChatCreateOrReuseDialog, {
userId: addrTexts[0],
onNewDMClick: () => {
@ -115,6 +113,15 @@ function _onStartChatFinished(shouldInvite, addrs) {
});
});
}
} 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 invite user', '', ErrorDialog, {
title: _t("Failed to invite user"),
description: ((err && err.message) ? err.message : _t("Operation failed")),
});
});
} else {
// Start multi user chat
let room;

View File

@ -22,6 +22,7 @@ import dis from "./dispatcher";
import * as Rooms from "./Rooms";
import Promise from 'bluebird';
import {getAddressType} from "./UserAddress";
/**
* Create a new room, and switch to it.
@ -52,7 +53,17 @@ function createRoom(opts) {
createOpts.preset = createOpts.preset || defaultPreset;
createOpts.visibility = createOpts.visibility || 'private';
if (opts.dmUserId && createOpts.invite === undefined) {
createOpts.invite = [opts.dmUserId];
switch (getAddressType(opts.dmUserId)) {
case 'mx-user-id':
createOpts.invite = [opts.dmUserId];
break;
case 'email':
createOpts.invite_3pid = [{
id_server: MatrixClientPeg.get().getIdentityServerUrl(true),
medium: 'email',
address: opts.dmUserId,
}];
}
}
if (opts.dmUserId && createOpts.is_direct === undefined) {
createOpts.is_direct = true;