Use separate MSISDN add and bind flow for supporting HSes
This changes the paths used for binding MSISDNs for discovery to use the new separate bind / unbind APIs on supporting servers. Fixes https://github.com/vector-im/riot-web/issues/10839
This commit is contained in:
parent
ff69ad02b9
commit
f9a09d271b
2 changed files with 88 additions and 14 deletions
|
@ -56,6 +56,48 @@ export class PhoneNumber extends React.Component {
|
|||
}
|
||||
|
||||
async changeBinding({ bind, label, errorTitle }) {
|
||||
if (!await MatrixClientPeg.get().doesServerSupportSeparateAddAndBind()) {
|
||||
return this.changeBindingTangledAddBind({ bind, label, errorTitle });
|
||||
}
|
||||
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
const { medium, address } = this.props.msisdn;
|
||||
|
||||
try {
|
||||
if (bind) {
|
||||
const task = new AddThreepid();
|
||||
this.setState({
|
||||
verifying: true,
|
||||
continueDisabled: true,
|
||||
addTask: task,
|
||||
});
|
||||
// XXX: Sydent will accept a number without country code if you add
|
||||
// a leading plus sign to a number in E.164 format (which the 3PID
|
||||
// address is), but this goes against the spec.
|
||||
// See https://github.com/matrix-org/matrix-doc/issues/2222
|
||||
await task.bindMsisdn(null, `+${address}`);
|
||||
this.setState({
|
||||
continueDisabled: false,
|
||||
});
|
||||
} else {
|
||||
await MatrixClientPeg.get().unbindThreePid(medium, address);
|
||||
}
|
||||
this.setState({ bound: bind });
|
||||
} catch (err) {
|
||||
console.error(`Unable to ${label} phone number ${address} ${err}`);
|
||||
this.setState({
|
||||
verifying: false,
|
||||
continueDisabled: false,
|
||||
addTask: null,
|
||||
});
|
||||
Modal.createTrackedDialog(`Unable to ${label} phone number`, '', ErrorDialog, {
|
||||
title: errorTitle,
|
||||
description: ((err && err.message) ? err.message : _t("Operation failed")),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async changeBindingTangledAddBind({ bind, label, errorTitle }) {
|
||||
const ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");
|
||||
const { medium, address } = this.props.msisdn;
|
||||
|
||||
|
@ -67,12 +109,6 @@ export class PhoneNumber extends React.Component {
|
|||
});
|
||||
|
||||
try {
|
||||
// XXX: Unfortunately, at the moment we can't just bind via the HS
|
||||
// in a single operation, at it will error saying the 3PID is in use
|
||||
// even though it's in use by the current user. For the moment, we
|
||||
// work around this by removing the 3PID from the HS and re-adding
|
||||
// it with IS binding enabled.
|
||||
// See https://github.com/matrix-org/matrix-doc/pull/2140/files#r311462052
|
||||
await MatrixClientPeg.get().deleteThreePid(medium, address);
|
||||
// XXX: Sydent will accept a number without country code if you add
|
||||
// a leading plus sign to a number in E.164 format (which the 3PID
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue