Warn on disconnecting from IS
...if the user has bound threepids Fixes https://github.com/vector-im/riot-web/issues/10550
This commit is contained in:
parent
088dc7953b
commit
75770f7a4a
4 changed files with 53 additions and 64 deletions
|
@ -22,6 +22,7 @@ import MatrixClientPeg from "../../../MatrixClientPeg";
|
||||||
import SdkConfig from "../../../SdkConfig";
|
import SdkConfig from "../../../SdkConfig";
|
||||||
import Modal from '../../../Modal';
|
import Modal from '../../../Modal';
|
||||||
import dis from "../../../dispatcher";
|
import dis from "../../../dispatcher";
|
||||||
|
import { getThreepidBindStatus } from '../../../boundThreepids';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If a url has no path component, etc. abbreviate it to just the hostname
|
* If a url has no path component, etc. abbreviate it to just the hostname
|
||||||
|
@ -98,6 +99,7 @@ export default class SetIdServer extends React.Component {
|
||||||
idServer: defaultIdServer,
|
idServer: defaultIdServer,
|
||||||
error: null,
|
error: null,
|
||||||
busy: false,
|
busy: false,
|
||||||
|
disconnectBusy: false,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,24 +152,45 @@ export default class SetIdServer extends React.Component {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
_onDisconnectClicked = () => {
|
_onDisconnectClicked = async () => {
|
||||||
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
this.setState({disconnectBusy: true});
|
||||||
Modal.createTrackedDialog('Identity Server Disconnect Warning', '', QuestionDialog, {
|
try {
|
||||||
title: _t("Disconnect Identity Server"),
|
const threepids = await getThreepidBindStatus(MatrixClientPeg.get());
|
||||||
description:
|
|
||||||
<div>
|
const boundThreepids = threepids.filter(tp => tp.bound);
|
||||||
{_t(
|
let message;
|
||||||
"Disconnect from the identity server <idserver />?", {},
|
if (boundThreepids.length) {
|
||||||
{idserver: sub => <b>{abbreviateUrl(this.state.currentClientIdServer)}</b>},
|
message = _t(
|
||||||
)},
|
"You are currently sharing email addresses or phone numbers on the identity " +
|
||||||
</div>,
|
"server <idserver />. You will need to reconnect to <idserver2 /> to stop " +
|
||||||
button: _t("Disconnect"),
|
"sharing them.", {},
|
||||||
onFinished: (confirmed) => {
|
{
|
||||||
if (confirmed) {
|
idserver: sub => <b>{abbreviateUrl(this.state.currentClientIdServer)}</b>,
|
||||||
this._disconnectIdServer();
|
// XXX: https://github.com/vector-im/riot-web/issues/10564
|
||||||
}
|
idserver2: sub => <b>{abbreviateUrl(this.state.currentClientIdServer)}</b>,
|
||||||
},
|
}
|
||||||
});
|
);
|
||||||
|
} else {
|
||||||
|
message = _t(
|
||||||
|
"Disconnect from the identity server <idserver />?", {},
|
||||||
|
{idserver: sub => <b>{abbreviateUrl(this.state.currentClientIdServer)}</b>},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const QuestionDialog = sdk.getComponent("dialogs.QuestionDialog");
|
||||||
|
Modal.createTrackedDialog('Identity Server Disconnect Warning', '', QuestionDialog, {
|
||||||
|
title: _t("Disconnect Identity Server"),
|
||||||
|
description: message,
|
||||||
|
button: _t("Disconnect"),
|
||||||
|
onFinished: (confirmed) => {
|
||||||
|
if (confirmed) {
|
||||||
|
this._disconnectIdServer();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
this.setState({disconnectBusy: false});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_disconnectIdServer = () => {
|
_disconnectIdServer = () => {
|
||||||
|
@ -215,6 +238,11 @@ export default class SetIdServer extends React.Component {
|
||||||
|
|
||||||
let discoSection;
|
let discoSection;
|
||||||
if (idServerUrl) {
|
if (idServerUrl) {
|
||||||
|
let discoButtonContent = _t("Disconnect");
|
||||||
|
if (this.state.disconnectBusy) {
|
||||||
|
const InlineSpinner = sdk.getComponent('views.elements.InlineSpinner');
|
||||||
|
discoButtonContent = <InlineSpinner />;
|
||||||
|
}
|
||||||
discoSection = <div>
|
discoSection = <div>
|
||||||
<span className="mx_SettingsTab_subsectionText">{_t(
|
<span className="mx_SettingsTab_subsectionText">{_t(
|
||||||
"Disconnecting from your identity server will mean you " +
|
"Disconnecting from your identity server will mean you " +
|
||||||
|
@ -222,7 +250,7 @@ export default class SetIdServer extends React.Component {
|
||||||
"able to invite others by email or phone.",
|
"able to invite others by email or phone.",
|
||||||
)}</span>
|
)}</span>
|
||||||
<AccessibleButton onClick={this._onDisconnectClicked} kind="danger">
|
<AccessibleButton onClick={this._onDisconnectClicked} kind="danger">
|
||||||
{_t("Disconnect")}
|
{discoButtonContent}
|
||||||
</AccessibleButton>
|
</AccessibleButton>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import sdk from '../../../../index';
|
||||||
import Modal from '../../../../Modal';
|
import Modal from '../../../../Modal';
|
||||||
import IdentityAuthClient from '../../../../IdentityAuthClient';
|
import IdentityAuthClient from '../../../../IdentityAuthClient';
|
||||||
import AddThreepid from '../../../../AddThreepid';
|
import AddThreepid from '../../../../AddThreepid';
|
||||||
|
import { getThreepidBindStatus } from '../../../../boundThreepids';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: Improve the UX for everything in here.
|
TODO: Improve the UX for everything in here.
|
||||||
|
@ -201,28 +202,7 @@ export default class EmailAddresses extends React.Component {
|
||||||
const userId = client.getUserId();
|
const userId = client.getUserId();
|
||||||
|
|
||||||
const { threepids } = await client.getThreePids();
|
const { threepids } = await client.getThreePids();
|
||||||
const emails = threepids.filter((a) => a.medium === 'email');
|
const emails = await getThreepidBindStatus(client, 'email');
|
||||||
|
|
||||||
if (emails.length > 0) {
|
|
||||||
// TODO: Handle terms agreement
|
|
||||||
// See https://github.com/vector-im/riot-web/issues/10522
|
|
||||||
const authClient = new IdentityAuthClient();
|
|
||||||
const identityAccessToken = await authClient.getAccessToken();
|
|
||||||
|
|
||||||
// Restructure for lookup query
|
|
||||||
const query = emails.map(({ medium, address }) => [medium, address]);
|
|
||||||
const lookupResults = await client.bulkLookupThreePids(query, identityAccessToken);
|
|
||||||
|
|
||||||
// Record which are already bound
|
|
||||||
for (const [medium, address, mxid] of lookupResults.threepids) {
|
|
||||||
if (medium !== "email" || mxid !== userId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const email = emails.find(e => e.address === address);
|
|
||||||
if (!email) continue;
|
|
||||||
email.bound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({ emails });
|
this.setState({ emails });
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import sdk from '../../../../index';
|
||||||
import Modal from '../../../../Modal';
|
import Modal from '../../../../Modal';
|
||||||
import IdentityAuthClient from '../../../../IdentityAuthClient';
|
import IdentityAuthClient from '../../../../IdentityAuthClient';
|
||||||
import AddThreepid from '../../../../AddThreepid';
|
import AddThreepid from '../../../../AddThreepid';
|
||||||
|
import { getThreepidBindStatus } from '../../../../boundThreepids';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
TODO: Improve the UX for everything in here.
|
TODO: Improve the UX for everything in here.
|
||||||
|
@ -220,28 +221,7 @@ export default class PhoneNumbers extends React.Component {
|
||||||
const userId = client.getUserId();
|
const userId = client.getUserId();
|
||||||
|
|
||||||
const { threepids } = await client.getThreePids();
|
const { threepids } = await client.getThreePids();
|
||||||
const msisdns = threepids.filter((a) => a.medium === 'msisdn');
|
const msisdns = await getThreepidBindStatus(client, 'msisdn');
|
||||||
|
|
||||||
if (msisdns.length > 0) {
|
|
||||||
// TODO: Handle terms agreement
|
|
||||||
// See https://github.com/vector-im/riot-web/issues/10522
|
|
||||||
const authClient = new IdentityAuthClient();
|
|
||||||
const identityAccessToken = await authClient.getAccessToken();
|
|
||||||
|
|
||||||
// Restructure for lookup query
|
|
||||||
const query = msisdns.map(({ medium, address }) => [medium, address]);
|
|
||||||
const lookupResults = await client.bulkLookupThreePids(query, identityAccessToken);
|
|
||||||
|
|
||||||
// Record which are already bound
|
|
||||||
for (const [medium, address, mxid] of lookupResults.threepids) {
|
|
||||||
if (medium !== "msisdn" || mxid !== userId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const msisdn = msisdns.find(e => e.address === address);
|
|
||||||
if (!msisdn) continue;
|
|
||||||
msisdn.bound = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.setState({ msisdns });
|
this.setState({ msisdns });
|
||||||
}
|
}
|
||||||
|
|
|
@ -543,8 +543,9 @@
|
||||||
"Not a valid Identity Server (status code %(code)s)": "Not a valid Identity Server (status code %(code)s)",
|
"Not a valid Identity Server (status code %(code)s)": "Not a valid Identity Server (status code %(code)s)",
|
||||||
"Could not connect to Identity Server": "Could not connect to Identity Server",
|
"Could not connect to Identity Server": "Could not connect to Identity Server",
|
||||||
"Checking server": "Checking server",
|
"Checking server": "Checking server",
|
||||||
"Disconnect Identity Server": "Disconnect Identity Server",
|
"You are currently sharing email addresses or phone numbers on the identity server <idserver />. You will need to reconnect to <idserver2 /> to stop sharing them.": "You are currently sharing email addresses or phone numbers on the identity server <idserver />. You will need to reconnect to <idserver2 /> to stop sharing them.",
|
||||||
"Disconnect from the identity server <idserver />?": "Disconnect from the identity server <idserver />?",
|
"Disconnect from the identity server <idserver />?": "Disconnect from the identity server <idserver />?",
|
||||||
|
"Disconnect Identity Server": "Disconnect Identity Server",
|
||||||
"Disconnect": "Disconnect",
|
"Disconnect": "Disconnect",
|
||||||
"Identity Server (%(server)s)": "Identity Server (%(server)s)",
|
"Identity Server (%(server)s)": "Identity Server (%(server)s)",
|
||||||
"You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.",
|
"You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.": "You are currently using <server></server> to discover and be discoverable by existing contacts you know. You can change your identity server below.",
|
||||||
|
|
Loading…
Reference in a new issue