Improve terms handling for 3PID state gathering

This changes the 3PID state gathering (used in Settings) to ignore terms errors
(no modals will be shown) on the assumption that other UX handles this case.
pull/21833/head
J. Ryan Stinnett 2019-09-11 13:36:10 +01:00
parent f04c347df7
commit 0b7995dc11
3 changed files with 23 additions and 18 deletions

View File

@ -65,7 +65,7 @@ export default class IdentityAuthClient {
} }
// Returns a promise that resolves to the access_token string from the IS // Returns a promise that resolves to the access_token string from the IS
async getAccessToken(check=true) { async getAccessToken({ check = true } = {}) {
if (!this.authEnabled) { if (!this.authEnabled) {
// The current IS doesn't support authentication // The current IS doesn't support authentication
return null; return null;

View File

@ -26,26 +26,31 @@ export async function getThreepidsWithBindStatus(client, filterMedium) {
// Check bind status assuming we have an IS and terms are agreed // Check bind status assuming we have an IS and terms are agreed
if (threepids.length > 0 && client.getIdentityServerUrl()) { if (threepids.length > 0 && client.getIdentityServerUrl()) {
// TODO: Handle terms agreement try {
// See https://github.com/vector-im/riot-web/issues/10522 const authClient = new IdentityAuthClient();
const authClient = new IdentityAuthClient(); const identityAccessToken = await authClient.getAccessToken({ check: false });
const identityAccessToken = await authClient.getAccessToken();
// Restructure for lookup query // Restructure for lookup query
const query = threepids.map(({ medium, address }) => [medium, address]); const query = threepids.map(({ medium, address }) => [medium, address]);
const lookupResults = await client.bulkLookupThreePids(query, identityAccessToken); const lookupResults = await client.bulkLookupThreePids(query, identityAccessToken);
// Record which are already bound // Record which are already bound
for (const [medium, address, mxid] of lookupResults.threepids) { for (const [medium, address, mxid] of lookupResults.threepids) {
if (mxid !== userId) { if (mxid !== userId) {
continue; continue;
}
if (filterMedium && medium !== filterMedium) {
continue;
}
const threepid = threepids.find(e => e.medium === medium && e.address === address);
if (!threepid) continue;
threepid.bound = true;
} }
if (filterMedium && medium !== filterMedium) { } catch (e) {
continue; // Ignore terms errors here and assume other flows handle this
if (!(e.errcode === "M_TERMS_NOT_SIGNED")) {
throw e;
} }
const threepid = threepids.find(e => e.medium === medium && e.address === address);
if (!threepid) continue;
threepid.bound = true;
} }
} }

View File

@ -110,7 +110,7 @@ export default class GeneralUserSettingsTab extends React.Component {
// By starting the terms flow we get the logic for checking which terms the user has signed // By starting the terms flow we get the logic for checking which terms the user has signed
// for free. So we might as well use that for our own purposes. // for free. So we might as well use that for our own purposes.
const authClient = new IdentityAuthClient(); const authClient = new IdentityAuthClient();
const idAccessToken = await authClient.getAccessToken(/*check=*/false); const idAccessToken = await authClient.getAccessToken({ check: false });
startTermsFlow([new Service( startTermsFlow([new Service(
SERVICE_TYPES.IS, SERVICE_TYPES.IS,
MatrixClientPeg.get().getIdentityServerUrl(), MatrixClientPeg.get().getIdentityServerUrl(),