From 29dfb092eb7e72f352ca05f7c6912e219976127d Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 8 Sep 2020 16:52:25 +1000 Subject: [PATCH 1/3] add Secondary Device only if it's not a primary device --- js/models/messages.js | 12 +++++++----- js/views/conversation_view.js | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index 67f2fe7fb..aa9132fa3 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -836,7 +836,7 @@ return Boolean(lookup[contactId]); }, - getPropsForMessageDetail() { + async getPropsForMessageDetail() { const newIdentity = i18n('newIdentity'); const OUTGOING_KEY_ERROR = 'OutgoingIdentityKeyError'; @@ -872,8 +872,7 @@ // that contact. Otherwise, it will be a standalone entry. const errors = _.reject(allErrors, error => Boolean(error.number)); const errorsGroupedById = _.groupBy(allErrors, 'number'); - const primaryDevicePubKey = this.get('conversationId'); - const finalContacts = (phoneNumbers || []).map(id => { + const finalContacts = await Promise.all((phoneNumbers || []).map(async id => { const errorsForContact = errorsGroupedById[id]; const isOutgoingKeyError = Boolean( _.find(errorsForContact, error => error.name === OUTGOING_KEY_ERROR) @@ -881,8 +880,11 @@ const isUnidentifiedDelivery = storage.get('unidentifiedDeliveryIndicators') && this.isUnidentifiedDelivery(id, unidentifiedLookup); + const primary = await window.libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice( + id + ); - const isPrimaryDevice = id === primaryDevicePubKey; + const isPrimaryDevice = id === primary.key; const contact = this.findAndFormatContact(id); const profileName = isPrimaryDevice @@ -904,7 +906,7 @@ onShowSafetyNumber: () => this.trigger('show-identity', this.findContact(id)), }; - }); + })); // The prefix created here ensures that contacts with errors are listed // first; otherwise it's alphabetical diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index dee2d56c5..59106847e 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -1496,14 +1496,14 @@ Signal.Backbone.Views.Lightbox.show(this.lightboxGalleryView.el); }, - showMessageDetail(message) { + async showMessageDetail(message) { const onClose = () => { this.stopListening(message, 'change', update); this.resetPanel(); this.updateHeader(); }; - const props = message.getPropsForMessageDetail(); + const props = await message.getPropsForMessageDetail(); const view = new Whisper.ReactWrapperView({ className: 'message-detail-wrapper', Component: Signal.Components.MessageDetail, @@ -1511,7 +1511,7 @@ onClose, }); - const update = () => view.update(message.getPropsForMessageDetail()); + const update = async () => view.update(await message.getPropsForMessageDetail()); this.listenTo(message, 'change', update); this.listenTo(message, 'expired', onClose); // We could listen to all involved contacts, but we'll call that overkill From f43ea3d940a5c500b41277b4c181dd41f01887f2 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Tue, 8 Sep 2020 16:56:56 +1000 Subject: [PATCH 2/3] fix size of sent badge on message detail view --- stylesheets/_modules.scss | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stylesheets/_modules.scss b/stylesheets/_modules.scss index e252c7f6f..58ef21818 100644 --- a/stylesheets/_modules.scss +++ b/stylesheets/_modules.scss @@ -1224,7 +1224,7 @@ } .module-message-detail__contact-container { - margin: 20px; + margin: 20px 0 20px 0; } .module-message-detail__contact { From 5bab1c665f91a86487627abb5b93d296f9ab355c Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Wed, 9 Sep 2020 10:42:52 +1000 Subject: [PATCH 3/3] lint --- js/models/messages.js | 70 ++++++++++++++++++----------------- js/views/conversation_view.js | 3 +- 2 files changed, 38 insertions(+), 35 deletions(-) diff --git a/js/models/messages.js b/js/models/messages.js index aa9132fa3..95f4b0dda 100644 --- a/js/models/messages.js +++ b/js/models/messages.js @@ -872,41 +872,43 @@ // that contact. Otherwise, it will be a standalone entry. const errors = _.reject(allErrors, error => Boolean(error.number)); const errorsGroupedById = _.groupBy(allErrors, 'number'); - const finalContacts = await Promise.all((phoneNumbers || []).map(async id => { - const errorsForContact = errorsGroupedById[id]; - const isOutgoingKeyError = Boolean( - _.find(errorsForContact, error => error.name === OUTGOING_KEY_ERROR) - ); - const isUnidentifiedDelivery = - storage.get('unidentifiedDeliveryIndicators') && - this.isUnidentifiedDelivery(id, unidentifiedLookup); - const primary = await window.libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice( - id - ); - - const isPrimaryDevice = id === primary.key; + const finalContacts = await Promise.all( + (phoneNumbers || []).map(async id => { + const errorsForContact = errorsGroupedById[id]; + const isOutgoingKeyError = Boolean( + _.find(errorsForContact, error => error.name === OUTGOING_KEY_ERROR) + ); + const isUnidentifiedDelivery = + storage.get('unidentifiedDeliveryIndicators') && + this.isUnidentifiedDelivery(id, unidentifiedLookup); + const primary = await window.libsession.Protocols.MultiDeviceProtocol.getPrimaryDevice( + id + ); - const contact = this.findAndFormatContact(id); - const profileName = isPrimaryDevice - ? contact.profileName - : `${contact.profileName} (Secondary Device)`; - return { - ...contact, - status: this.getStatus(id), - errors: errorsForContact, - isOutgoingKeyError, - isUnidentifiedDelivery, - isPrimaryDevice, - profileName, - onSendAnyway: () => - this.trigger('force-send', { - contact: this.findContact(id), - message: this, - }), - onShowSafetyNumber: () => - this.trigger('show-identity', this.findContact(id)), - }; - })); + const isPrimaryDevice = id === primary.key; + + const contact = this.findAndFormatContact(id); + const profileName = isPrimaryDevice + ? contact.profileName + : `${contact.profileName} (Secondary Device)`; + return { + ...contact, + status: this.getStatus(id), + errors: errorsForContact, + isOutgoingKeyError, + isUnidentifiedDelivery, + isPrimaryDevice, + profileName, + onSendAnyway: () => + this.trigger('force-send', { + contact: this.findContact(id), + message: this, + }), + onShowSafetyNumber: () => + this.trigger('show-identity', this.findContact(id)), + }; + }) + ); // The prefix created here ensures that contacts with errors are listed // first; otherwise it's alphabetical diff --git a/js/views/conversation_view.js b/js/views/conversation_view.js index 59106847e..097556d16 100644 --- a/js/views/conversation_view.js +++ b/js/views/conversation_view.js @@ -1511,7 +1511,8 @@ onClose, }); - const update = async () => view.update(await message.getPropsForMessageDetail()); + const update = async () => + view.update(await message.getPropsForMessageDetail()); this.listenTo(message, 'change', update); this.listenTo(message, 'expired', onClose); // We could listen to all involved contacts, but we'll call that overkill