From d13c3d3350b9c7a3d2c45687c7d6cfe618d9a19a Mon Sep 17 00:00:00 2001 From: Scott Nonnenberg Date: Tue, 5 May 2020 12:46:42 -0700 Subject: [PATCH] Link flow: Show 'you must upgrade' on 409 server response --- _locales/en/messages.json | 9 ++++ background.html | 3 ++ js/views/install_view.js | 28 +++++++++++- ts/textsecure/WebAPI.ts | 14 +++--- ts/util/lint/exceptions.json | 84 ++++++++++++++++++------------------ 5 files changed, 85 insertions(+), 53 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index a334b392a..7edc4abd4 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -1076,6 +1076,15 @@ "installTooManyDevices": { "message": "Sorry, you have too many devices linked already. Try removing some." }, + "installTooOld": { + "message": "Update Signal on this device to link your phone." + }, + "installErrorHeader": { + "message": "Something went wrong!" + }, + "installTryAgain": { + "message": "Try again" + }, "theme": { "message": "Theme", "description": "Header for theme settings" diff --git a/background.html b/background.html index b50458d8f..9a5a2f9d8 100644 --- a/background.html +++ b/background.html @@ -306,6 +306,9 @@ diff --git a/js/views/install_view.js b/js/views/install_view.js index 36441ba6a..69b828d67 100644 --- a/js/views/install_view.js +++ b/js/views/install_view.js @@ -20,12 +20,14 @@ const DEVICE_NAME_SELECTOR = 'input.device-name'; const CONNECTION_ERROR = -1; const TOO_MANY_DEVICES = 411; + const TOO_OLD = 409; Whisper.InstallView = Whisper.View.extend({ templateName: 'link-flow-template', className: 'main full-screen-flow', events: { 'click .try-again': 'connect', + 'click .second': 'shutdown', 'click .finish': 'finishLinking', // the actual next step happens in confirmNumber() on submit form #link-phone }, @@ -43,6 +45,8 @@ }, render_attributes() { let errorMessage; + let errorButton = i18n('installTryAgain'); + let errorSecondButton = null; if (this.error) { if ( @@ -50,6 +54,13 @@ this.error.code === TOO_MANY_DEVICES ) { errorMessage = i18n('installTooManyDevices'); + } else if ( + this.error.name === 'HTTPError' && + this.error.code === TOO_OLD + ) { + errorMessage = i18n('installTooOld'); + errorButton = i18n('upgrade'); + errorSecondButton = i18n('quit'); } else if ( this.error.name === 'HTTPError' && this.error.code === CONNECTION_ERROR @@ -63,9 +74,10 @@ return { isError: true, - errorHeader: 'Something went wrong!', + errorHeader: i18n('installErrorHeader'), errorMessage, - errorButton: 'Try again', + errorButton, + errorSecondButton, }; } @@ -89,7 +101,19 @@ this.step = step; this.render(); }, + shutdown() { + window.shutdown(); + }, connect() { + if ( + this.error && + this.error.name === 'HTTPError' && + this.error.code === TOO_OLD + ) { + window.location = 'https://signal.org/download'; + return; + } + this.error = null; this.selectStep(Steps.SCAN_QR_CODE); this.clearQR(); diff --git a/ts/textsecure/WebAPI.ts b/ts/textsecure/WebAPI.ts index 7e229a041..3ba46461f 100644 --- a/ts/textsecure/WebAPI.ts +++ b/ts/textsecure/WebAPI.ts @@ -917,9 +917,13 @@ export function initialize({ ) { const { accessKey } = options; const jsonData: any = { - supportsSms: false, + capabilities: { + uuid: true, + }, fetchesMessages: true, + name: deviceName ? deviceName : undefined, registrationId, + supportsSms: false, unidentifiedAccessKey: accessKey ? _btoa(_getString(accessKey)) : undefined, @@ -929,14 +933,6 @@ export function initialize({ const call = deviceName ? 'devices' : 'accounts'; const urlPrefix = deviceName ? '/' : '/code/'; - if (deviceName) { - jsonData.name = deviceName; - } else { - jsonData.capabilities = { - uuid: true, - }; - } - // We update our saved username and password, since we're creating a new account username = number; password = newPassword; diff --git a/ts/util/lint/exceptions.json b/ts/util/lint/exceptions.json index 1c0229c07..6adebec22 100644 --- a/ts/util/lint/exceptions.json +++ b/ts/util/lint/exceptions.json @@ -586,7 +586,7 @@ "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " this.$('#qr img').remove();", - "lineNumber": 136, + "lineNumber": 160, "reasonCategory": "usageTrusted", "updated": "2018-09-19T21:59:32.770Z", "reasonDetail": "Protected from arbitrary input" @@ -595,7 +595,7 @@ "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " this.$('#qr .container').show();", - "lineNumber": 138, + "lineNumber": 162, "reasonCategory": "usageTrusted", "updated": "2018-09-19T21:59:32.770Z", "reasonDetail": "Protected from arbitrary input" @@ -604,7 +604,7 @@ "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " if ($('#qr').length === 0) {", - "lineNumber": 142, + "lineNumber": 166, "reasonCategory": "usageTrusted", "updated": "2018-09-19T21:59:32.770Z", "reasonDetail": "Protected from arbitrary input" @@ -613,7 +613,7 @@ "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " this.$('#qr .container').hide();", - "lineNumber": 148, + "lineNumber": 172, "reasonCategory": "usageTrusted", "updated": "2020-03-24T19:03:04.861Z", "reasonDetail": "Protected from arbitrary input" @@ -622,7 +622,7 @@ "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " this.qr = new QRCode(this.$('#qr')[0]).makeCode(url);", - "lineNumber": 149, + "lineNumber": 173, "reasonCategory": "usageTrusted", "updated": "2020-03-24T19:03:04.861Z", "reasonDetail": "Protected from arbitrary input" @@ -631,52 +631,52 @@ "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " this.$('#qr').addClass('ready');", - "lineNumber": 151, - "reasonCategory": "usageTrusted", - "updated": "2020-03-24T19:03:04.861Z", - "reasonDetail": "Protected from arbitrary input" - }, - { - "rule": "jQuery-$(", - "path": "js/views/install_view.js", - "line": " this.$(DEVICE_NAME_SELECTOR).val(deviceName || window.getHostName());", - "lineNumber": 156, - "reasonCategory": "usageTrusted", - "updated": "2020-03-24T19:03:04.861Z", - "reasonDetail": "Protected from arbitrary input" - }, - { - "rule": "jQuery-$(", - "path": "js/views/install_view.js", - "line": " this.$('#link-phone').submit();", - "lineNumber": 161, - "reasonCategory": "usageTrusted", - "updated": "2020-03-24T19:03:04.861Z", - "reasonDetail": "Protected from arbitrary input" - }, - { - "rule": "jQuery-$(", - "path": "js/views/install_view.js", - "line": " this.$('#link-phone').submit(e => {", - "lineNumber": 171, - "reasonCategory": "usageTrusted", - "updated": "2020-03-24T19:03:04.861Z", - "reasonDetail": "Protected from arbitrary input" - }, - { - "rule": "jQuery-$(", - "path": "js/views/install_view.js", - "line": " let name = this.$(DEVICE_NAME_SELECTOR).val();", "lineNumber": 175, "reasonCategory": "usageTrusted", "updated": "2020-03-24T19:03:04.861Z", "reasonDetail": "Protected from arbitrary input" }, + { + "rule": "jQuery-$(", + "path": "js/views/install_view.js", + "line": " this.$(DEVICE_NAME_SELECTOR).val(deviceName || window.getHostName());", + "lineNumber": 180, + "reasonCategory": "usageTrusted", + "updated": "2020-03-24T19:03:04.861Z", + "reasonDetail": "Protected from arbitrary input" + }, + { + "rule": "jQuery-$(", + "path": "js/views/install_view.js", + "line": " this.$('#link-phone').submit();", + "lineNumber": 185, + "reasonCategory": "usageTrusted", + "updated": "2020-03-24T19:03:04.861Z", + "reasonDetail": "Protected from arbitrary input" + }, + { + "rule": "jQuery-$(", + "path": "js/views/install_view.js", + "line": " this.$('#link-phone').submit(e => {", + "lineNumber": 195, + "reasonCategory": "usageTrusted", + "updated": "2020-03-24T19:03:04.861Z", + "reasonDetail": "Protected from arbitrary input" + }, + { + "rule": "jQuery-$(", + "path": "js/views/install_view.js", + "line": " let name = this.$(DEVICE_NAME_SELECTOR).val();", + "lineNumber": 199, + "reasonCategory": "usageTrusted", + "updated": "2020-03-24T19:03:04.861Z", + "reasonDetail": "Protected from arbitrary input" + }, { "rule": "jQuery-$(", "path": "js/views/install_view.js", "line": " this.$(DEVICE_NAME_SELECTOR).focus();", - "lineNumber": 178, + "lineNumber": 202, "reasonCategory": "usageTrusted", "updated": "2020-03-24T19:03:04.861Z", "reasonDetail": "Protected from arbitrary input"