Add support for device name

This commit is contained in:
lilia 2015-06-18 11:00:58 -07:00
parent 9f1af24b9c
commit f32ff58953
6 changed files with 71 additions and 31 deletions

View file

@ -38050,8 +38050,11 @@ axolotlInternal.RecipientRecord = function() {
window.textsecure.storage = window.textsecure.storage || {};
window.textsecure.storage.user = {
setNumberAndDeviceId: function(number, deviceId) {
setNumberAndDeviceId: function(number, deviceId, deviceName) {
textsecure.storage.put("number_id", number + "." + deviceId);
if (deviceName) {
textsecure.storage.put("device_name", deviceName);
}
},
getNumber: function(key, defaultValue) {
@ -38066,6 +38069,10 @@ axolotlInternal.RecipientRecord = function() {
if (number_id === undefined)
return undefined;
return textsecure.utils.unencodeNumber(number_id)[1];
},
getDeviceName: function(key) {
return textsecure.storage.get("device_name");
}
};
})();
@ -38968,7 +38975,7 @@ TextSecureServer = function () {
* error_callback: function(http status code = -1 or != 200) called on failure
* urlParameters: crap appended to the url (probably including a leading /)
* user: user name to be sent in a basic auth header
* password: password to be sent in a basic auth headerA
* password: password to be sent in a basic auth header
* do_auth: alternative to user/password where user/password are figured out automagically
* jsonData: JSON data sent in the request body
*/
@ -39094,20 +39101,26 @@ TextSecureServer = function () {
};
self.confirmCode = function(number, code, password,
signaling_key, registrationId, single_device) {
var call = single_device ? 'accounts' : 'devices';
var urlPrefix = single_device ? '/code/' : '/';
signaling_key, registrationId, deviceName) {
var call = deviceName ? 'devices' : 'accounts';
var urlPrefix = deviceName ? '/' : '/code/';
var jsonData = {
signalingKey : btoa(getString(signaling_key)),
supportsSms : false,
fetchesMessages : true,
registrationId : registrationId,
};
if (deviceName) {
jsonData.name = deviceName;
}
return doAjax({
call : call,
httpType : 'PUT',
urlParameters : urlPrefix + code,
user : number,
password : password,
jsonData : { signalingKey : btoa(getString(signaling_key)),
supportsSms : false,
fetchesMessages : true,
registrationId : registrationId}
jsonData : jsonData
});
};
@ -39337,12 +39350,15 @@ TextSecureServer = function () {
request.respond(200, 'OK');
socket.close();
resolve(cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(provisionMessage) {
return confirmNumber(provisionMessage.number).then(function() {
return confirmNumber(provisionMessage.number).then(function(deviceName) {
if (typeof deviceName !== 'string' || deviceName.length == 0) {
throw new Error('Invalid device name');
}
return createAccount(
provisionMessage.number,
provisionMessage.provisioningCode,
provisionMessage.identityKeyPair,
false
deviceName
);
});
}));
@ -39363,7 +39379,7 @@ TextSecureServer = function () {
});
}
};
function createAccount(number, verificationCode, identityKeyPair, single_device) {
function createAccount(number, verificationCode, identityKeyPair, deviceName) {
textsecure.storage.put('identityKey', identityKeyPair);
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
@ -39377,9 +39393,9 @@ TextSecureServer = function () {
textsecure.storage.put("registrationId", registrationId);
return TextSecureServer.confirmCode(
number, verificationCode, password, signalingKey, registrationId, single_device
number, verificationCode, password, signalingKey, registrationId, deviceName
).then(function(response) {
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1);
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName);
textsecure.storage.put("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
});
}

View file

@ -51,10 +51,14 @@
});
$('.confirmation-dialog .ok').click(function(e) {
e.stopPropagation();
var name = $('#device-name').val();
if (name.trim().length === 0) {
return;
}
$('.confirmation-dialog').hide();
$('.progress-dialog').show();
$('.progress-dialog .status').text('Generating Keys');
resolve();
resolve(name);
});
$('.modal-container').show();
});

View file

@ -55,12 +55,15 @@
request.respond(200, 'OK');
socket.close();
resolve(cryptoInfo.decryptAndHandleDeviceInit(envelope).then(function(provisionMessage) {
return confirmNumber(provisionMessage.number).then(function() {
return confirmNumber(provisionMessage.number).then(function(deviceName) {
if (typeof deviceName !== 'string' || deviceName.length == 0) {
throw new Error('Invalid device name');
}
return createAccount(
provisionMessage.number,
provisionMessage.provisioningCode,
provisionMessage.identityKeyPair,
false
deviceName
);
});
}));
@ -81,7 +84,7 @@
});
}
};
function createAccount(number, verificationCode, identityKeyPair, single_device) {
function createAccount(number, verificationCode, identityKeyPair, deviceName) {
textsecure.storage.put('identityKey', identityKeyPair);
var signalingKey = textsecure.crypto.getRandomBytes(32 + 20);
@ -95,9 +98,9 @@
textsecure.storage.put("registrationId", registrationId);
return TextSecureServer.confirmCode(
number, verificationCode, password, signalingKey, registrationId, single_device
number, verificationCode, password, signalingKey, registrationId, deviceName
).then(function(response) {
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1);
textsecure.storage.user.setNumberAndDeviceId(number, response.deviceId || 1, deviceName);
textsecure.storage.put("regionCode", libphonenumber.util.getRegionCodeForNumber(number));
});
}

View file

@ -48,7 +48,7 @@ TextSecureServer = function () {
* error_callback: function(http status code = -1 or != 200) called on failure
* urlParameters: crap appended to the url (probably including a leading /)
* user: user name to be sent in a basic auth header
* password: password to be sent in a basic auth headerA
* password: password to be sent in a basic auth header
* do_auth: alternative to user/password where user/password are figured out automagically
* jsonData: JSON data sent in the request body
*/
@ -174,20 +174,26 @@ TextSecureServer = function () {
};
self.confirmCode = function(number, code, password,
signaling_key, registrationId, single_device) {
var call = single_device ? 'accounts' : 'devices';
var urlPrefix = single_device ? '/code/' : '/';
signaling_key, registrationId, deviceName) {
var call = deviceName ? 'devices' : 'accounts';
var urlPrefix = deviceName ? '/' : '/code/';
var jsonData = {
signalingKey : btoa(getString(signaling_key)),
supportsSms : false,
fetchesMessages : true,
registrationId : registrationId,
};
if (deviceName) {
jsonData.name = deviceName;
}
return doAjax({
call : call,
httpType : 'PUT',
urlParameters : urlPrefix + code,
user : number,
password : password,
jsonData : { signalingKey : btoa(getString(signaling_key)),
supportsSms : false,
fetchesMessages : true,
registrationId : registrationId}
jsonData : jsonData
});
};

View file

@ -24,8 +24,11 @@
window.textsecure.storage = window.textsecure.storage || {};
window.textsecure.storage.user = {
setNumberAndDeviceId: function(number, deviceId) {
setNumberAndDeviceId: function(number, deviceId, deviceName) {
textsecure.storage.put("number_id", number + "." + deviceId);
if (deviceName) {
textsecure.storage.put("device_name", deviceName);
}
},
getNumber: function(key, defaultValue) {
@ -40,6 +43,10 @@
if (number_id === undefined)
return undefined;
return textsecure.utils.unencodeNumber(number_id)[1];
},
getDeviceName: function(key) {
return textsecure.storage.get("device_name");
}
};
})();

View file

@ -103,8 +103,12 @@
<div class='modal-main'>
<h4>Pairing</h4>
<div class='confirmation-dialog clearfix'>
Please confirm your phone number:
<h3 class='number'></h3>
<div class='panel'>
Name this device: <input type='text' id='device-name'></input>
</div>
<div class='panel'>
Your phone number: <span class='number'></span>
</div>
<button class='ok'>Continue</span>
<button class='cancel'>Cancel</span>
</div>