You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
949 B
JavaScript
44 lines
949 B
JavaScript
7 years ago
|
/* global storage */
|
||
|
/* global storage: false */
|
||
|
|
||
|
/* eslint-disable more/no-then */
|
||
|
|
||
|
// eslint-disable-next-line func-names
|
||
|
(function() {
|
||
|
'use strict';
|
||
|
|
||
|
window.Whisper = window.Whisper || {};
|
||
|
|
||
|
const PROFILE_ID = 'profiles';
|
||
|
|
||
|
storage.getProfile = number => {
|
||
|
const profiles = storage.get(PROFILE_ID, {});
|
||
|
return profiles[number] || null;
|
||
|
}
|
||
|
|
||
|
storage.saveProfile = async (number, profile) => {
|
||
|
const profiles = storage.get(PROFILE_ID, {});
|
||
|
if (profiles[number]) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
window.log.info('adding profile ', profile, 'for ', number);
|
||
|
await storage.put(PROFILE_ID, {
|
||
|
...profiles,
|
||
|
number: profile,
|
||
|
});
|
||
|
}
|
||
|
|
||
|
storage.removeProfile = async number => {
|
||
|
const profiles = storage.get(PROFILE_ID, {});
|
||
|
if (!profiles[number]) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
delete profiles[number];
|
||
|
|
||
|
window.log.info('removing profile for ', number);
|
||
|
await storage.put(PROFILE_ID, profiles);
|
||
|
}
|
||
|
})();
|