2020-10-30 20:34:04 +00:00
|
|
|
// Copyright 2015-2020 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
/* global textsecure, window */
|
2015-03-24 22:48:59 +00:00
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
// eslint-disable-next-line func-names
|
2020-11-18 15:15:42 +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 || {};
|
2015-03-24 22:48:59 +00:00
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
2015-03-24 22:48:59 +00:00
|
|
|
|
2020-03-05 21:14:58 +00:00
|
|
|
setUuidAndDeviceId(uuid, deviceId) {
|
|
|
|
textsecure.storage.put('uuid_id', `${uuid}.${deviceId}`);
|
|
|
|
},
|
|
|
|
|
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
|
|
|
},
|
2015-03-24 22:48:59 +00:00
|
|
|
|
2020-03-05 21:14:58 +00:00
|
|
|
getUuid() {
|
|
|
|
const uuid = textsecure.storage.get('uuid_id');
|
|
|
|
if (uuid === undefined) return undefined;
|
2021-01-15 16:57:09 +00:00
|
|
|
return textsecure.utils.unencodeNumber(uuid.toLowerCase())[0];
|
2020-03-05 21:14:58 +00:00
|
|
|
},
|
|
|
|
|
2018-07-21 21:51:20 +00:00
|
|
|
getDeviceId() {
|
2020-03-05 21:14:58 +00: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 21:51:20 +00:00
|
|
|
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');
|
|
|
|
},
|
2018-12-13 19:12:33 +00:00
|
|
|
|
|
|
|
setDeviceNameEncrypted() {
|
|
|
|
return textsecure.storage.put('deviceNameEncrypted', true);
|
|
|
|
},
|
|
|
|
|
|
|
|
getDeviceNameEncrypted() {
|
|
|
|
return textsecure.storage.get('deviceNameEncrypted');
|
|
|
|
},
|
2019-01-11 16:53:35 +00:00
|
|
|
|
|
|
|
getSignalingKey() {
|
|
|
|
return textsecure.storage.get('signaling_key');
|
|
|
|
},
|
2018-05-02 16:51:22 +00:00
|
|
|
};
|
2015-03-24 22:48:59 +00:00
|
|
|
})();
|