|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* global Whisper, i18n */
|
|
|
|
|
/* global Whisper, i18n, libloki, textsecure */
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
|
|
|
|
(function() {
|
|
|
|
@ -13,27 +13,43 @@
|
|
|
|
|
this.pubKeyRequests = [];
|
|
|
|
|
this.pubKey = null;
|
|
|
|
|
this.accepted = false;
|
|
|
|
|
this.isListening = false;
|
|
|
|
|
this.view = '';
|
|
|
|
|
this.render();
|
|
|
|
|
this.showView();
|
|
|
|
|
},
|
|
|
|
|
events: {
|
|
|
|
|
'click .waitingForRequestView .cancel': 'close',
|
|
|
|
|
'click #startPairing': 'startReceivingRequests',
|
|
|
|
|
'click #close': 'close',
|
|
|
|
|
'click .waitingForRequestView .cancel': 'stopReceivingRequests',
|
|
|
|
|
'click .requestReceivedView .skip': 'skipDevice',
|
|
|
|
|
'click #allowPairing': 'allowDevice',
|
|
|
|
|
'click .requestAcceptedView .ok': 'close',
|
|
|
|
|
'click .requestAcceptedView .ok': 'stopReceivingRequests',
|
|
|
|
|
},
|
|
|
|
|
render_attributes() {
|
|
|
|
|
return {
|
|
|
|
|
waitingForRequestTitle: 'Waiting for device to register...',
|
|
|
|
|
requestReceivedTitle: 'Device Pairing Received',
|
|
|
|
|
requestAcceptedTitle: 'Device Pairing Accepted',
|
|
|
|
|
defaultTitle: i18n('pairedDevices'),
|
|
|
|
|
waitingForRequestTitle: i18n('waitingForDeviceToRegister'),
|
|
|
|
|
requestReceivedTitle: i18n('devicePairingReceived'),
|
|
|
|
|
requestAcceptedTitle: i18n('devicePairingAccepted'),
|
|
|
|
|
startPairingText: i18n('pairNewDevice'),
|
|
|
|
|
cancelText: i18n('cancel'),
|
|
|
|
|
skipText: 'Skip',
|
|
|
|
|
closeText: i18n('close'),
|
|
|
|
|
skipText: i18n('skip'),
|
|
|
|
|
okText: i18n('ok'),
|
|
|
|
|
allowPairingText: 'Allow Pairing',
|
|
|
|
|
allowPairingText: i18n('allowPairing'),
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
startReceivingRequests() {
|
|
|
|
|
this.trigger('startReceivingRequests');
|
|
|
|
|
this.isListening = true;
|
|
|
|
|
this.showView();
|
|
|
|
|
},
|
|
|
|
|
stopReceivingRequests() {
|
|
|
|
|
this.trigger('stopReceivingRequests');
|
|
|
|
|
this.isListening = false;
|
|
|
|
|
this.showView();
|
|
|
|
|
},
|
|
|
|
|
requestReceived(secondaryDevicePubKey) {
|
|
|
|
|
// FIFO: push at the front of the array with unshift()
|
|
|
|
|
this.pubKeyRequests.unshift(secondaryDevicePubKey);
|
|
|
|
@ -51,7 +67,7 @@
|
|
|
|
|
},
|
|
|
|
|
transmisssionCB(errors) {
|
|
|
|
|
if (!errors) {
|
|
|
|
|
this.$('.transmissionStatus').text('Sent successfully');
|
|
|
|
|
this.$('.transmissionStatus').text(i18n('sent'));
|
|
|
|
|
} else {
|
|
|
|
|
this.$('.transmissionStatus').text(errors);
|
|
|
|
|
}
|
|
|
|
@ -66,11 +82,26 @@
|
|
|
|
|
// FIFO: pop at the back of the array using pop()
|
|
|
|
|
this.pubKey = this.pubKeyRequests.pop();
|
|
|
|
|
},
|
|
|
|
|
showView() {
|
|
|
|
|
async showView() {
|
|
|
|
|
const defaultView = this.$('.defaultView');
|
|
|
|
|
const waitingForRequestView = this.$('.waitingForRequestView');
|
|
|
|
|
const requestReceivedView = this.$('.requestReceivedView');
|
|
|
|
|
const requestAcceptedView = this.$('.requestAcceptedView');
|
|
|
|
|
if (this.accepted) {
|
|
|
|
|
if (!this.isListening) {
|
|
|
|
|
const ourPubKey = textsecure.storage.user.getNumber();
|
|
|
|
|
defaultView.show();
|
|
|
|
|
requestReceivedView.hide();
|
|
|
|
|
waitingForRequestView.hide();
|
|
|
|
|
requestAcceptedView.hide();
|
|
|
|
|
const pubKeys = await libloki.storage.getSecondaryDevicesFor(ourPubKey);
|
|
|
|
|
if (pubKeys && pubKeys.length > 0) {
|
|
|
|
|
this.$('#pairedPubKeys').empty();
|
|
|
|
|
pubKeys.forEach(x => {
|
|
|
|
|
this.$('#pairedPubKeys').append(`<li>${x}</li>`);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else if (this.accepted) {
|
|
|
|
|
defaultView.hide();
|
|
|
|
|
requestReceivedView.hide();
|
|
|
|
|
waitingForRequestView.hide();
|
|
|
|
|
requestAcceptedView.show();
|
|
|
|
@ -84,10 +115,12 @@
|
|
|
|
|
requestReceivedView.show();
|
|
|
|
|
waitingForRequestView.hide();
|
|
|
|
|
requestAcceptedView.hide();
|
|
|
|
|
defaultView.hide();
|
|
|
|
|
} else {
|
|
|
|
|
waitingForRequestView.show();
|
|
|
|
|
requestReceivedView.hide();
|
|
|
|
|
requestAcceptedView.hide();
|
|
|
|
|
defaultView.hide();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
close() {
|
|
|
|
|