Merge pull request #290 from Mikunj/loki-profile

Convert profile field in DataMessage to use LokiProfile
pull/299/head
Beaudan Campbell-Brown 6 years ago committed by GitHub
commit fd6f6c6a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -620,7 +620,7 @@
Whisper.events.on('onEditProfile', () => { Whisper.events.on('onEditProfile', () => {
const ourNumber = textsecure.storage.user.getNumber(); const ourNumber = textsecure.storage.user.getNumber();
const profile = storage.getLocalProfile(); const profile = storage.getLocalProfile();
const displayName = profile && profile.name && profile.name.displayName; const displayName = profile && profile.displayName;
if (appView) { if (appView) {
appView.showNicknameDialog({ appView.showNicknameDialog({
title: window.i18n('editProfileTitle'), title: window.i18n('editProfileTitle'),

@ -1978,7 +1978,7 @@
// Prioritise nickname over the profile display name // Prioritise nickname over the profile display name
const nickname = this.getNickname(); const nickname = this.getNickname();
const profile = this.getLocalProfile(); const profile = this.getLocalProfile();
const displayName = profile && profile.name && profile.name.displayName; const displayName = profile && profile.displayName;
const profileName = nickname || displayName || null; const profileName = nickname || displayName || null;
await this.setProfileName(profileName); await this.setProfileName(profileName);

@ -29,11 +29,9 @@
const profile = storage.getLocalProfile(); const profile = storage.getLocalProfile();
const newProfile = profile || {}; const newProfile = profile || {};
if (_.isEmpty(trimmed)) { if (_.isEmpty(trimmed)) {
delete newProfile.name; delete newProfile.displayName;
} else { } else {
newProfile.name = { newProfile.displayName = trimmed;
displayName: trimmed,
};
} }
await storage.saveLocalProfile(newProfile); await storage.saveLocalProfile(newProfile);

@ -143,10 +143,12 @@ Message.prototype = {
proto.profileKey = this.profileKey; proto.profileKey = this.profileKey;
} }
if (this.profile && this.profile.name) { // Only send the display name for now.
const contact = new textsecure.protobuf.DataMessage.Contact(); // In the future we might want to extend this to send other things.
contact.name = this.profile.name; if (this.profile && this.profile.displayName) {
proto.profile = contact; const profile = new textsecure.protobuf.DataMessage.LokiProfile();
profile.displayName = this.profile.displayName;
proto.profile = profile;
} }
this.dataMessage = proto; this.dataMessage = proto;

@ -180,6 +180,11 @@ message DataMessage {
optional AttachmentPointer image = 3; optional AttachmentPointer image = 3;
} }
// Loki: A custom message for our profile
message LokiProfile {
optional string displayName = 1;
}
optional string body = 1; optional string body = 1;
repeated AttachmentPointer attachments = 2; repeated AttachmentPointer attachments = 2;
optional GroupContext group = 3; optional GroupContext group = 3;
@ -190,7 +195,7 @@ message DataMessage {
optional Quote quote = 8; optional Quote quote = 8;
repeated Contact contact = 9; repeated Contact contact = 9;
repeated Preview preview = 10; repeated Preview preview = 10;
optional Contact profile = 101; // Loki: The profile of the current user optional LokiProfile profile = 101; // Loki: The profile of the current user
} }
message NullMessage { message NullMessage {

@ -72,13 +72,8 @@ describe('Profile', () => {
it('saves the display name', async () => { it('saves the display name', async () => {
await storage.setProfileName('hi there!'); await storage.setProfileName('hi there!');
const expected = {
displayName: 'hi there!',
};
const profile = storage.getLocalProfile(); const profile = storage.getLocalProfile();
assert.exists(profile.name); assert.deepEqual(profile.displayName, 'hi there!');
assert.deepEqual(expected, profile.name);
}); });
it('saves the display name without overwriting the other profile properties', async () => { it('saves the display name without overwriting the other profile properties', async () => {
@ -88,9 +83,7 @@ describe('Profile', () => {
const expected = { const expected = {
...profile, ...profile,
name: { displayName: 'hi there!',
displayName: 'hi there!',
},
}; };
assert.deepEqual(expected, storage.getLocalProfile()); assert.deepEqual(expected, storage.getLocalProfile());
}); });
@ -98,23 +91,18 @@ describe('Profile', () => {
it('trims the display name', async () => { it('trims the display name', async () => {
await storage.setProfileName(' in middle '); await storage.setProfileName(' in middle ');
const profile = storage.getLocalProfile(); const profile = storage.getLocalProfile();
const name = { assert.deepEqual('in middle', profile.displayName);
displayName: 'in middle',
};
assert.deepEqual(name, profile.name);
}); });
it('unsets the name property if it is empty', async () => { it('unsets the display name property if it is empty', async () => {
const profile = { const profile = {
name: { displayName: 'HI THERE!',
displayName: 'HI THERE!',
},
}; };
await storage.put(PROFILE_ID, profile); await storage.put(PROFILE_ID, profile);
assert.exists(storage.getLocalProfile().name); assert.exists(storage.getLocalProfile().displayName);
await storage.setProfileName(''); await storage.setProfileName('');
assert.notExists(storage.getLocalProfile().name); assert.notExists(storage.getLocalProfile().displayName);
}); });
}); });
}); });

Loading…
Cancel
Save