diff --git a/background.html b/background.html index a37e90fe1..e7463fcb5 100644 --- a/background.html +++ b/background.html @@ -608,6 +608,7 @@ + diff --git a/js/models/conversations.js b/js/models/conversations.js index 7af61f601..0338278a0 100644 --- a/js/models/conversations.js +++ b/js/models/conversations.js @@ -1736,7 +1736,21 @@ this.getProfiles(); } }, + // Update profile variables dynamically + async updateProfile() { + const profile = await storage.getProfile(this.id); + if (!profile) { + this.set({ profileName: null }); + } else { + this.set({ profileName: profile.name.displayName }); + } + if (this.hasChanged()) { + await window.Signal.Data.updateConversation(this.id, this.attributes, { + Conversation: Whisper.Conversation, + }); + } + }, getProfiles() { // request all conversation members' keys let ids = []; @@ -1866,6 +1880,7 @@ } } }, + // Signal profile name async setProfileName(encryptedName) { if (!encryptedName) { return; diff --git a/js/models/profile.js b/js/models/profile.js index be551ca73..94edd1352 100644 --- a/js/models/profile.js +++ b/js/models/profile.js @@ -1,4 +1,4 @@ -/* global storage */ +/* global storage, _ */ /* global storage: false */ /* eslint-disable more/no-then */ @@ -18,14 +18,17 @@ storage.saveProfile = async (number, profile) => { const profiles = storage.get(PROFILE_ID, {}); - if (profiles[number]) { + const storedProfile = profiles[number]; + + // 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, + [number]: profile, }); } diff --git a/js/modules/types/contact.js b/js/modules/types/contact.js index 56baa425d..a031c56eb 100644 --- a/js/modules/types/contact.js +++ b/js/modules/types/contact.js @@ -66,7 +66,7 @@ function idForLogging(message) { exports._validate = (contact, options = {}) => { const { messageId } = options; - const { name, number, email, address, organization } = contact; + const { name, organization } = contact; if ((!name || !name.displayName) && !organization) { return new Error( @@ -74,15 +74,16 @@ exports._validate = (contact, options = {}) => { ); } - if ( - (!number || !number.length) && - (!email || !email.length) && - (!address || !address.length) - ) { - return new Error( - `Message ${messageId}: Contact had no included numbers, email or addresses` - ); - } + // Disabled as we don't require the users to provide this + // if ( + // (!number || !number.length) && + // (!email || !email.length) && + // (!address || !address.length) + // ) { + // return new Error( + // `Message ${messageId}: Contact had no included numbers, email or addresses` + // ); + // } return null; }; diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index f92b65a54..29d5c86a7 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -25,6 +25,7 @@ function Message(options) { this.needsSync = options.needsSync; this.expireTimer = options.expireTimer; this.profileKey = options.profileKey; + this.profile = options.profile; if (!(this.recipients instanceof Array) || this.recipients.length < 1) { throw new Error('Invalid recipient list'); @@ -132,6 +133,12 @@ Message.prototype = { proto.profileKey = this.profileKey; } + if (this.profile) { + const contact = new textsecure.protobuf.DataMessage.Contact(); + contact.name = this.profile.name; + proto.contact.push(contact); + } + this.dataMessage = proto; return proto; }, @@ -656,6 +663,8 @@ MessageSender.prototype = { profileKey, options ) { + const myNumber = textsecure.storage.user.getNumber(); + const profile = textsecure.storage.impl.getProfile(myNumber); return this.sendMessage( { recipients: [number], @@ -666,6 +675,7 @@ MessageSender.prototype = { needsSync: true, expireTimer, profileKey, + profile, }, options );