signal-desktop/libtextsecure/storage/user.js

36 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-07-21 21:51:20 +00:00
/* global textsecure, window */
2018-07-21 21:51:20 +00:00
// eslint-disable-next-line func-names
2018-05-02 16:51:22 +00:00
(function() {
2018-07-21 21:51:20 +00:00
/** *******************************************
2018-05-02 16:51:22 +00:00
*** Utilities to store data about the user ***
2018-07-21 21:51:20 +00:00
********************************************* */
2018-05-02 16:51:22 +00:00
window.textsecure = window.textsecure || {};
window.textsecure.storage = window.textsecure.storage || {};
2018-05-02 16:51:22 +00:00
window.textsecure.storage.user = {
2018-07-21 21:51:20 +00:00
setNumberAndDeviceId(number, deviceId, deviceName) {
textsecure.storage.put('number_id', `${number}.${deviceId}`);
2018-05-02 16:51:22 +00:00
if (deviceName) {
textsecure.storage.put('device_name', deviceName);
}
},
2018-07-21 21:51:20 +00:00
getNumber() {
const numberId = textsecure.storage.get('number_id');
if (numberId === undefined) return undefined;
return textsecure.utils.unencodeNumber(numberId)[0];
2018-05-02 16:51:22 +00:00
},
2018-07-21 21:51:20 +00:00
getDeviceId() {
const numberId = textsecure.storage.get('number_id');
if (numberId === undefined) return undefined;
return textsecure.utils.unencodeNumber(numberId)[1];
2018-05-02 16:51:22 +00:00
},
2015-06-18 18:00:58 +00:00
2018-07-21 21:51:20 +00:00
getDeviceName() {
2018-05-02 16:51:22 +00:00
return textsecure.storage.get('device_name');
},
};
})();