Moved and nicknames into conversations.

pull/61/head
Mikunj 7 years ago
parent 98c4b5d77b
commit 14ee7fec65

@ -570,33 +570,34 @@
Whisper.events.on('onEditProfile', () => {
const ourNumber = textsecure.storage.user.getNumber();
const profile = storage.getProfile(ourNumber);
const nickname = profile && profile.name && profile.name.displayName;
const profile = storage.getLocalProfile();
const displayName = profile && profile.name && profile.name.displayName;
if (appView) {
appView.showNicknameDialog({
title: 'Change your own nickname',
message: 'Note: Your nickname will be visible to your contacts.',
nickname,
nickname: displayName,
onOk: async (newNickname) => {
// Update our profiles accordingly
if (_.isEmpty(newNickname)) {
await storage.removeProfile(ourNumber);
// Update our profiles accordingly'
const trimmed = newNickname && newNickname.trim();
let newProfile = null;
if (_.isEmpty(trimmed)) {
await storage.removeLocalProfile();
} else {
await storage.saveProfile(ourNumber, {
newProfile = {
name: {
displayName: newNickname,
displayName: trimmed,
},
});
};
await storage.saveLocalProfile(newProfile);
}
appView.inboxView.trigger('updateProfile');
// Update the conversation if we have it
try {
const conversation = ConversationController.get(ourNumber);
conversation.updateProfile();
} catch (e) {}
const conversation = ConversationController.get(ourNumber);
if (conversation)
conversation.setProfile(newProfile);
},
})
}

@ -1731,26 +1731,35 @@
}
},
onChangeProfileKey() {
if (this.isPrivate()) {
this.getProfiles();
}
// LOKI PROFILES
async setNickname(nickname) {
const trimmed = nickname && nickname.trim();
if (this.get('nickname') === trimmed) return;
this.set({ nickname: trimmed });
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
await this.updateProfile();
},
/*
Update profile values from the profile in storage.
async setProfile(profile) {
if (_.isEqual(this.get('profile'), profile)) return;
Signal has methods of setting data from a profile it fetches.
It fetches this via a server and they aren't saved anywhere.
this.set({ profile });
await window.Signal.Data.updateConversation(this.id, this.attributes, {
Conversation: Whisper.Conversation,
});
We made our own profile storage system so thus to avoid
any future conflict with upstream, we just use this method to update the values.
*/
await this.updateProfile();
},
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 nickname = this.getNickname();
const profile = this.getLocalProfile();
const displayName = profile && profile.name && profile.name.displayName;
const newProfileName = nickname || displayName || null;
@ -1761,6 +1770,21 @@
});
}
},
getLocalProfile() {
return this.get('profile');
},
getNickname() {
return this.get('nickname');
},
// SIGNAL PROFILES
onChangeProfileKey() {
if (this.isPrivate()) {
this.getProfiles();
}
},
getProfiles() {
// request all conversation members' keys
let ids = [];

@ -9,75 +9,27 @@
window.Whisper = window.Whisper || {};
const PROFILE_ID = 'profiles';
const PROFILE_ID = 'local-profile';
storage.getProfile = number => {
const profiles = storage.get(PROFILE_ID, {});
return profiles[number] || null;
storage.getLocalProfile = () => {
const profile = storage.get(PROFILE_ID, null);
return profile;
}
storage.saveProfile = async (number, profile) => {
const profiles = storage.get(PROFILE_ID, {});
const storedProfile = profiles[number];
storage.saveLocalProfile = async (profile) => {
const storedProfile = storage.get(PROFILE_ID, null);
// Only store the profile if we have a different object
if (storedProfile && _.isEqual(storedProfile, profile)) {
return;
}
window.log.info('adding profile ', profile, 'for ', number);
await storage.put(PROFILE_ID, {
...profiles,
[number]: profile,
});
window.log.info('saving local profile ', profile);
await storage.put(PROFILE_ID, 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);
}
// 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);
storage.removeLocalProfile = async () => {
window.log.info('removing local profile');
await storage.remove(PROFILE_ID);
}
})();

@ -174,7 +174,7 @@
name: item.getName(),
value: item.get('seconds'),
})),
hasNickname: !!storage.getNickname(this.model.id),
hasNickname: !!this.model.getNickname(),
onSetDisappearingMessages: seconds =>
this.setDisappearingMessages(seconds),
@ -208,20 +208,12 @@
onChangeNickname: () => {
window.Whisper.events.trigger('showNicknameDialog', {
pubKey: this.model.id,
nickname: storage.getNickname(this.model.id),
onOk: async (newName) => {
if (_.isEmpty(newName)) {
await storage.removeNickname(this.model.id)
} else {
await storage.saveNickname(this.model.id, newName);
}
this.model.updateProfile();
},
nickname: this.model.getNickname(),
onOk: newName => this.model.setNickname(newName),
});
},
onClearNickname: async () => {
await storage.removeNickname(this.model.id);
this.model.updateProfile();
this.model.setNickname(null);
},
};
};

@ -198,7 +198,7 @@
_getIdentityKeyViewProps() {
const identityKey = textsecure.storage.get('identityKey').pubKey;
const pubKey = StringView.arrayBufferToHex(identityKey);
const profile = storage.getProfile(pubKey);
const profile = storage.getLocalProfile();
const name = profile && profile.name && profile.name.displayName;
return {
@ -210,18 +210,11 @@
}
},
render_attributes() {
const identityKey = textsecure.storage.get('identityKey').pubKey;
const pubKey = StringView.arrayBufferToHex(identityKey);
const profile = storage.getProfile(pubKey);
const name = profile && profile.name && profile.name.displayName;
return {
welcomeToSignal: i18n('welcomeToSignal'),
selectAContact: i18n('selectAContact'),
searchForPeopleOrGroups: i18n('searchForPeopleOrGroups'),
settings: i18n('settings'),
identityKey: pubKey,
name,
};
},
events: {

@ -929,18 +929,15 @@ MessageReceiver.prototype.extend({
);
// Check if we need to update any profile names
if (!isMe) {
if (!isMe && conversation) {
let profile = null;
if (message.profile) {
const name = JSON.parse(message.profile.name.encodeJSON());
await storage.saveProfile(envelope.source, { name });
} else {
await storage.removeProfile(envelope.source);
profile = { name };
}
// Update the conversation profle
if (conversation) {
conversation.updateProfile();
}
// Update the conversation
conversation.setProfile(profile);
}
if (type === 'friend-request' && isMe) {

@ -663,8 +663,7 @@ MessageSender.prototype = {
profileKey,
options
) {
const myNumber = textsecure.storage.user.getNumber();
const profile = textsecure.storage.impl.getProfile(myNumber);
const profile = textsecure.storage.impl.getLocalProfile();
return this.sendMessage(
{
recipients: [number],

Loading…
Cancel
Save