Signal-Desktop/libtextsecure/storage/user.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

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 */
2018-07-21 21:51:20 +00:00
// eslint-disable-next-line func-names
(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);
}
},
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
},
getUuid() {
const uuid = textsecure.storage.get('uuid_id');
if (uuid === undefined) return undefined;
return textsecure.utils.unencodeNumber(uuid)[0];
},
2018-07-21 21:51:20 +00:00
getDeviceId() {
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');
},
setDeviceNameEncrypted() {
return textsecure.storage.put('deviceNameEncrypted', true);
},
getDeviceNameEncrypted() {
return textsecure.storage.get('deviceNameEncrypted');
},
getSignalingKey() {
return textsecure.storage.get('signaling_key');
},
2018-05-02 16:51:22 +00:00
};
})();