diff --git a/js/background.js b/js/background.js index 5b8a01848..a107388b2 100644 --- a/js/background.js +++ b/js/background.js @@ -580,19 +580,19 @@ onOk: async (newName) => { // Update our profiles accordingly' const trimmed = newName && newName.trim(); - let newProfile = null; + + // If we get an empty name then unset the name property + // Otherwise update it + const newProfile = profile || {}; if (_.isEmpty(trimmed)) { - await storage.removeLocalProfile(); + delete newProfile.name; } else { - newProfile = { - ...(profile || {}), - name: { - displayName: trimmed, - }, - }; - await storage.saveLocalProfile(newProfile); + newProfile.name = { + displayName: trimmed, + } } + await storage.saveLocalProfile(newProfile); appView.inboxView.trigger('updateProfile'); // Update the conversation if we have it diff --git a/libtextsecure/message_receiver.js b/libtextsecure/message_receiver.js index ddd6d4029..a3072b104 100644 --- a/libtextsecure/message_receiver.js +++ b/libtextsecure/message_receiver.js @@ -918,7 +918,7 @@ MessageReceiver.prototype.extend({ p = this.handleEndSession(envelope.source); } return p.then(() => - this.processDecrypted(envelope, msg, envelope.source).then(async message => { + this.processDecrypted(envelope, msg, envelope.source).then(message => { const groupId = message.group && message.group.id; const isBlocked = this.isGroupBlocked(groupId); const isMe = envelope.source === textsecure.storage.user.getNumber(); @@ -932,8 +932,7 @@ MessageReceiver.prototype.extend({ if (!isMe && conversation) { let profile = null; if (message.profile) { - const name = JSON.parse(message.profile.name.encodeJSON()); - profile = { name }; + profile = JSON.parse(message.profile.encodeJSON()); } // Update the conversation diff --git a/libtextsecure/sendmessage.js b/libtextsecure/sendmessage.js index e3ab2dbcd..2bf30970d 100644 --- a/libtextsecure/sendmessage.js +++ b/libtextsecure/sendmessage.js @@ -135,7 +135,8 @@ Message.prototype = { if (this.profile) { const contact = new textsecure.protobuf.DataMessage.Contact(); - contact.name = this.profile.name; + if (this.profile.name) + contact.name = this.profile.name; proto.profile = contact; }