From 497f42165a3e89676073f9cc838e4ac120eb1181 Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Wed, 6 Nov 2019 10:26:53 +1100 Subject: [PATCH 1/5] Allow unpairing device --- _locales/en/messages.json | 6 +++ background.html | 11 ++++- js/views/device_pairing_dialog_view.js | 63 ++++++++++++++++++++------ 3 files changed, 65 insertions(+), 15 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 58cc6bb23..6c389713a 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -961,6 +961,12 @@ "showPairingWordsTitle": { "message": "Pairing Secret Words" }, + "confirmUnpairingTitle": { + "message": "Please confirm you want to unpair the following device:" + }, + "unpairDevice": { + "message": "Unpair Device" + }, "clear": { "message": "Clear" }, diff --git a/background.html b/background.html index ecfe74afa..f83de2ac7 100644 --- a/background.html +++ b/background.html @@ -253,7 +253,6 @@

{{ defaultTitle }}

@@ -292,6 +291,16 @@
+ + + diff --git a/js/views/device_pairing_dialog_view.js b/js/views/device_pairing_dialog_view.js index b8fb7fba9..190824815 100644 --- a/js/views/device_pairing_dialog_view.js +++ b/js/views/device_pairing_dialog_view.js @@ -1,4 +1,4 @@ -/* global Whisper, i18n, libloki, textsecure, ConversationController */ +/* global Whisper, i18n, libloki, textsecure, ConversationController, $, lokiFileServerAPI */ // eslint-disable-next-line func-names (function() { @@ -19,6 +19,7 @@ this.pubKey = null; this.accepted = false; this.isListening = false; + this.pubKeyToUnpair = null; this.success = false; }, events: { @@ -28,6 +29,8 @@ 'click .requestReceivedView .skip': 'skipDevice', 'click #allowPairing': 'allowDevice', 'click .requestAcceptedView .ok': 'stopReceivingRequests', + 'click .confirmUnpairView .cancel': 'stopReceivingRequests', + 'click .confirmUnpairView .unpairDevice': 'confirmUnpairDevice', }, render_attributes() { return { @@ -37,10 +40,12 @@ requestAcceptedTitle: i18n('devicePairingAccepted'), startPairingText: i18n('pairNewDevice'), cancelText: i18n('cancel'), + UnpairDevice: i18n('unpairDevice'), closeText: i18n('close'), skipText: i18n('skip'), okText: i18n('ok'), allowPairingText: i18n('allowPairing'), + confirmUnpairViewTitle: i18n('confirmUnpairingTitle'), }; }, startReceivingRequests() { @@ -103,31 +108,61 @@ // FIFO: pop at the back of the array using pop() this.pubKey = this.pubKeyRequests.pop(); }, + async confirmUnpairDevice() { + await libloki.storage.removePairingAuthorisationForSecondaryPubKey( + this.pubKeyToUnpair + ); + await lokiFileServerAPI.updateOurDeviceMapping(); + this.reset(); + this.showView(); + }, + requestUnpairDevice(pubKey) { + this.pubKeyToUnpair = pubKey; + this.showView(); + }, + getPubkeyName(pubKey) { + const secretWords = window.mnemonic.pubkey_to_secret_words(pubKey); + const conv = ConversationController.get(pubKey); + const deviceAlias = conv ? conv.getNickname() : 'Unnamed Device'; + return `${deviceAlias} (pairing secret: ${secretWords})`; + }, async showView() { const defaultView = this.$('.defaultView'); const waitingForRequestView = this.$('.waitingForRequestView'); const requestReceivedView = this.$('.requestReceivedView'); const requestAcceptedView = this.$('.requestAcceptedView'); - if (!this.isListening) { - const ourPubKey = textsecure.storage.user.getNumber(); - defaultView.show(); + const confirmUnpairView = this.$('.confirmUnpairView'); + if (this.pubKeyToUnpair) { + defaultView.hide(); + requestReceivedView.hide(); + waitingForRequestView.hide(); + requestAcceptedView.hide(); + confirmUnpairView.show(); + const name = this.getPubkeyName(this.pubKeyToUnpair); + this.$('.confirmUnpairView #pubkey').text(name); + } else if (!this.isListening) { requestReceivedView.hide(); waitingForRequestView.hide(); requestAcceptedView.hide(); + confirmUnpairView.hide(); + + const ourPubKey = textsecure.storage.user.getNumber(); + defaultView.show(); const pubKeys = await libloki.storage.getSecondaryDevicesFor(ourPubKey); + this.$('#pairedPubKeys').empty(); if (pubKeys && pubKeys.length > 0) { - this.$('#pairedPubKeys').empty(); pubKeys.forEach(x => { - let deviceAlias = 'Paired Device'; - const secretWords = window.mnemonic.pubkey_to_secret_words(x); - const conv = ConversationController.get(x); - if (conv) { - deviceAlias = conv.getNickname(); - } - this.$('#pairedPubKeys').append( - `
  • ${deviceAlias} (${secretWords})
  • ` - ); + const name = this.getPubkeyName(x); + const li = $('
  • ').html(`${name} - `); + const link = $('') + .text('Unpair') + .attr('href', '#'); + link.on('click', () => this.requestUnpairDevice(x)); + li.append(link); + this.$('#pairedPubKeys').append(li); }); + } else { + this.$('#pairedPubKeys').append('
  • No paired devices
  • '); } } else if (this.accepted) { defaultView.hide(); From 9ab3626149f9f79323633438f22876709810d97f Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Wed, 6 Nov 2019 11:01:41 +1100 Subject: [PATCH 2/5] Fix italic tags showing up --- js/views/device_pairing_dialog_view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/views/device_pairing_dialog_view.js b/js/views/device_pairing_dialog_view.js index 190824815..483de0280 100644 --- a/js/views/device_pairing_dialog_view.js +++ b/js/views/device_pairing_dialog_view.js @@ -139,7 +139,7 @@ requestAcceptedView.hide(); confirmUnpairView.show(); const name = this.getPubkeyName(this.pubKeyToUnpair); - this.$('.confirmUnpairView #pubkey').text(name); + this.$('.confirmUnpairView #pubkey').html(name); } else if (!this.isListening) { requestReceivedView.hide(); waitingForRequestView.hide(); From cd2c4b993ae38c7c1f016fb41c18a0930a333474 Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Wed, 6 Nov 2019 11:39:52 +1100 Subject: [PATCH 3/5] lint --- _locales/en/messages.json | 2 +- js/views/device_pairing_dialog_view.js | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 6c389713a..89091c807 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -962,7 +962,7 @@ "message": "Pairing Secret Words" }, "confirmUnpairingTitle": { - "message": "Please confirm you want to unpair the following device:" + "message": "Please confirm you want to unpair the following device:" }, "unpairDevice": { "message": "Unpair Device" diff --git a/js/views/device_pairing_dialog_view.js b/js/views/device_pairing_dialog_view.js index 483de0280..fb7d4389e 100644 --- a/js/views/device_pairing_dialog_view.js +++ b/js/views/device_pairing_dialog_view.js @@ -1,4 +1,12 @@ -/* global Whisper, i18n, libloki, textsecure, ConversationController, $, lokiFileServerAPI */ +/* global + Whisper, + i18n, + libloki, + textsecure, + ConversationController, + $, + lokiFileServerAPI +*/ // eslint-disable-next-line func-names (function() { From 3f52b9df93aaae850503660972ecfea1ef31ec2e Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Wed, 6 Nov 2019 14:54:23 +1100 Subject: [PATCH 4/5] Make unpairing a toggle-able feature (enable with window.lokiFeatureFlags.multiDeviceUnpairing = true) --- js/views/device_pairing_dialog_view.js | 15 +++++++++------ preload.js | 4 ++++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/js/views/device_pairing_dialog_view.js b/js/views/device_pairing_dialog_view.js index fb7d4389e..7dda6c3c0 100644 --- a/js/views/device_pairing_dialog_view.js +++ b/js/views/device_pairing_dialog_view.js @@ -161,12 +161,15 @@ if (pubKeys && pubKeys.length > 0) { pubKeys.forEach(x => { const name = this.getPubkeyName(x); - const li = $('
  • ').html(`${name} - `); - const link = $('') - .text('Unpair') - .attr('href', '#'); - link.on('click', () => this.requestUnpairDevice(x)); - li.append(link); + const li = $('
  • ').html(name); + if (window.lokiFeatureFlags.multiDeviceUnpairing) { + const link = $('') + .text('Unpair') + .attr('href', '#'); + link.on('click', () => this.requestUnpairDevice(x)); + li.append(' - '); + li.append(link); + } this.$('#pairedPubKeys').append(li); }); } else { diff --git a/preload.js b/preload.js index 9df58dadd..da596015f 100644 --- a/preload.js +++ b/preload.js @@ -456,3 +456,7 @@ if (config.environment === 'test') { window.shortenPubkey = pubkey => `(...${pubkey.substring(pubkey.length - 6)})`; window.pubkeyPattern = /@[a-fA-F0-9]{64,66}\b/g; + +window.lokiFeatureFlags = { + multiDeviceUnpairing: false, +}; From 86168ef8708a3ee5608626f876a176ad8a6630aa Mon Sep 17 00:00:00 2001 From: sachaaaaa Date: Wed, 6 Nov 2019 15:41:39 +1100 Subject: [PATCH 5/5] lower case variable --- background.html | 2 +- js/views/device_pairing_dialog_view.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/background.html b/background.html index f83de2ac7..19d7e6b65 100644 --- a/background.html +++ b/background.html @@ -298,7 +298,7 @@

    - +
    diff --git a/js/views/device_pairing_dialog_view.js b/js/views/device_pairing_dialog_view.js index 7dda6c3c0..7dd49cbc1 100644 --- a/js/views/device_pairing_dialog_view.js +++ b/js/views/device_pairing_dialog_view.js @@ -48,7 +48,7 @@ requestAcceptedTitle: i18n('devicePairingAccepted'), startPairingText: i18n('pairNewDevice'), cancelText: i18n('cancel'), - UnpairDevice: i18n('unpairDevice'), + unpairDevice: i18n('unpairDevice'), closeText: i18n('close'), skipText: i18n('skip'), okText: i18n('ok'),