Added storing nicknames.

pull/61/head
Mikunj 7 years ago
parent f1d18219ed
commit cf24e42a0e

@ -1739,9 +1739,13 @@
// Update profile variables dynamically
async updateProfile() {
const profileName = this.get('profileName');
// Prioritise nickname over the profile display name
const nickname = await storage.getNickname(this.id);
const profile = await storage.getProfile(this.id);
const displayName = profile && profile.name && profile.name.displayName;
const newProfileName = (profile && profile.name && profile.name.displayName) || null
const newProfileName = nickname || displayName || null;
if (profileName !== newProfileName) {
this.set({ profileName: newProfileName });
await window.Signal.Data.updateConversation(this.id, this.attributes, {

@ -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);
}
})();

Loading…
Cancel
Save