2020-10-30 15:34:04 -05:00
|
|
|
// Copyright 2015-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-07-21 14:51:20 -07:00
|
|
|
/* global textsecure, window */
|
2015-03-24 15:48:59 -07:00
|
|
|
|
2018-07-21 14:51:20 -07:00
|
|
|
// eslint-disable-next-line func-names
|
2020-11-18 07:15:42 -08:00
|
|
|
(function () {
|
2018-07-21 14:51:20 -07:00
|
|
|
/** *******************************************
|
2018-05-02 09:51:22 -07:00
|
|
|
*** Utilities to store data about the user ***
|
2018-07-21 14:51:20 -07:00
|
|
|
********************************************* */
|
2018-05-02 09:51:22 -07:00
|
|
|
window.textsecure = window.textsecure || {};
|
|
|
|
window.textsecure.storage = window.textsecure.storage || {};
|
2015-03-24 15:48:59 -07:00
|
|
|
|
2018-05-02 09:51:22 -07:00
|
|
|
window.textsecure.storage.user = {
|
2018-07-21 14:51:20 -07:00
|
|
|
setNumberAndDeviceId(number, deviceId, deviceName) {
|
|
|
|
textsecure.storage.put('number_id', `${number}.${deviceId}`);
|
2018-05-02 09:51:22 -07:00
|
|
|
if (deviceName) {
|
|
|
|
textsecure.storage.put('device_name', deviceName);
|
|
|
|
}
|
|
|
|
},
|
2015-03-24 15:48:59 -07:00
|
|
|
|
2020-03-05 13:14:58 -08:00
|
|
|
setUuidAndDeviceId(uuid, deviceId) {
|
|
|
|
textsecure.storage.put('uuid_id', `${uuid}.${deviceId}`);
|
|
|
|
},
|
|
|
|
|
2018-07-21 14:51:20 -07:00
|
|
|
getNumber() {
|
|
|
|
const numberId = textsecure.storage.get('number_id');
|
|
|
|
if (numberId === undefined) return undefined;
|
|
|
|
return textsecure.utils.unencodeNumber(numberId)[0];
|
2018-05-02 09:51:22 -07:00
|
|
|
},
|
2015-03-24 15:48:59 -07:00
|
|
|
|
2020-03-05 13:14:58 -08:00
|
|
|
getUuid() {
|
|
|
|
const uuid = textsecure.storage.get('uuid_id');
|
|
|
|
if (uuid === undefined) return undefined;
|
|
|
|
return textsecure.utils.unencodeNumber(uuid)[0];
|
|
|
|
},
|
|
|
|
|
2018-07-21 14:51:20 -07:00
|
|
|
getDeviceId() {
|
2020-03-05 13:14:58 -08:00
|
|
|
return this._getDeviceIdFromUuid() || this._getDeviceIdFromNumber();
|
|
|
|
},
|
|
|
|
|
|
|
|
_getDeviceIdFromUuid() {
|
|
|
|
const uuid = textsecure.storage.get('uuid_id');
|
|
|
|
if (uuid === undefined) return undefined;
|
|
|
|
return textsecure.utils.unencodeNumber(uuid)[1];
|
|
|
|
},
|
|
|
|
|
|
|
|
_getDeviceIdFromNumber() {
|
2018-07-21 14:51:20 -07:00
|
|
|
const numberId = textsecure.storage.get('number_id');
|
|
|
|
if (numberId === undefined) return undefined;
|
|
|
|
return textsecure.utils.unencodeNumber(numberId)[1];
|
2018-05-02 09:51:22 -07:00
|
|
|
},
|
2015-06-18 11:00:58 -07:00
|
|
|
|
2018-07-21 14:51:20 -07:00
|
|
|
getDeviceName() {
|
2018-05-02 09:51:22 -07:00
|
|
|
return textsecure.storage.get('device_name');
|
|
|
|
},
|
2018-12-13 11:12:33 -08:00
|
|
|
|
|
|
|
setDeviceNameEncrypted() {
|
|
|
|
return textsecure.storage.put('deviceNameEncrypted', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDeviceNameEncrypted() {
|
|
|
|
return textsecure.storage.get('deviceNameEncrypted');
|
|
|
|
},
|
2019-01-11 08:53:35 -08:00
|
|
|
|
|
|
|
getSignalingKey() {
|
|
|
|
return textsecure.storage.get('signaling_key');
|
|
|
|
},
|
2018-05-02 09:51:22 -07:00
|
|
|
};
|
2015-03-24 15:48:59 -07:00
|
|
|
})();
|