|
|
|
@ -43,4 +43,41 @@
|
|
|
|
|
window.log.info('removing profile for ', number);
|
|
|
|
|
await storage.put(PROFILE_ID, profiles);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Names that user can set for users
|
|
|
|
|
|
|
|
|
|
const NICKNAME_ID = 'nickname';
|
|
|
|
|
|
|
|
|
|
storage.getNickname = number => {
|
|
|
|
|
const nicknames = storage.get(NICKNAME_ID, {});
|
|
|
|
|
return nicknames[number] || null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
storage.saveNickname = async (number, name) => {
|
|
|
|
|
const nicknames = storage.get(NICKNAME_ID, {});
|
|
|
|
|
const storedName = nicknames[number];
|
|
|
|
|
|
|
|
|
|
// Only store the name if we have a different name
|
|
|
|
|
if (storedName === name) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.log.info('adding nickname ', name, 'for ', number);
|
|
|
|
|
await storage.put(NICKNAME_ID, {
|
|
|
|
|
...nicknames,
|
|
|
|
|
[number]: name,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
storage.removeNickname = async number => {
|
|
|
|
|
const nicknames = storage.get(NICKNAME_ID, {});
|
|
|
|
|
if (!nicknames[number]) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
delete nicknames[number];
|
|
|
|
|
|
|
|
|
|
window.log.info('removing nickname for ', number);
|
|
|
|
|
await storage.put(NICKNAME_ID, nicknames);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|