From e0c2cf8e9add5deb65544460f0b39a241c64ef64 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 25 Feb 2021 14:23:09 +1100 Subject: [PATCH] Force configuration message on avatar or display name update --- js/background.js | 10 ++++++++-- .../outgoing/content/ConfigurationMessage.ts | 8 ++------ ts/session/utils/Messages.ts | 11 +++++++---- .../unit/messages/ConfigurationMessage_test.ts | 12 ++++++++++-- 4 files changed, 27 insertions(+), 14 deletions(-) diff --git a/js/background.js b/js/background.js index 4a614f831..a4112e1a5 100644 --- a/js/background.js +++ b/js/background.js @@ -615,7 +615,10 @@ displayName: newName, avatar: newAvatarPath, }); - conversation.commit(); + await conversation.commit(); + await window.libsession.Utils.SyncUtils.forceSyncConfigurationNowIfNeeded( + true + ); } catch (error) { window.log.error( 'showEditProfileDialog Error ensuring that image is properly sized:', @@ -627,9 +630,12 @@ conversation.setLokiProfile({ displayName: newName, }); + await conversation.commit(); + await window.libsession.Utils.SyncUtils.forceSyncConfigurationNowIfNeeded( + true + ); } - conversation.commit(); // inform all your registered public servers // could put load on all the servers // if they just keep changing their names without sending messages diff --git a/ts/session/messages/outgoing/content/ConfigurationMessage.ts b/ts/session/messages/outgoing/content/ConfigurationMessage.ts index fd3201698..a34a50ea6 100644 --- a/ts/session/messages/outgoing/content/ConfigurationMessage.ts +++ b/ts/session/messages/outgoing/content/ConfigurationMessage.ts @@ -83,17 +83,13 @@ export class ConfigurationMessage extends ContentMessage { private mapClosedGroupsObjectToProto( closedGroups: Array ): Array { - return (closedGroups || []).map(m => - new ConfigurationMessageClosedGroup(m).toProto() - ); + return (closedGroups || []).map(m => m.toProto()); } private mapContactsObjectToProto( contacts: Array ): Array { - return (contacts || []).map(m => - new ConfigurationMessageContact(m).toProto() - ); + return (contacts || []).map(m => m.toProto()); } } diff --git a/ts/session/utils/Messages.ts b/ts/session/utils/Messages.ts index 4c2110aa3..1957fea66 100644 --- a/ts/session/utils/Messages.ts +++ b/ts/session/utils/Messages.ts @@ -116,14 +116,17 @@ export const getCurrentConfigurationMessage = async ( // Filter contacts const contactsModels = convos.filter( - c => !!c.get('active_at') && c.isPrivate() && !c.isBlocked() + c => + !!c.get('active_at') && + c.getLokiProfile()?.displayName && + c.isPrivate() && + !c.isBlocked() ); const contacts = contactsModels.map(c => { - const groupPubKey = c.get('id'); return new ConfigurationMessageContact({ - publicKey: groupPubKey, - displayName: c.get('name'), + publicKey: c.id, + displayName: c.getLokiProfile()?.displayName, profilePictureURL: c.get('avatarPointer'), profileKey: c.get('profileKey'), }); diff --git a/ts/test/session/unit/messages/ConfigurationMessage_test.ts b/ts/test/session/unit/messages/ConfigurationMessage_test.ts index b937f7cd2..ff4635761 100644 --- a/ts/test/session/unit/messages/ConfigurationMessage_test.ts +++ b/ts/test/session/unit/messages/ConfigurationMessage_test.ts @@ -227,8 +227,16 @@ describe('ConfigurationMessage', () => { expect(() => new ConfigurationMessageContact(params2)).to.throw(); }); - it('throw if the contact has an empty disploy name', () => { - // a display name cannot be empty. It should be undefined rather than empty + it('throw if the contact has an empty display name', () => { + // a display name cannot be empty nor undefined + + const params = { + publicKey: TestUtils.generateFakePubKey().key, + displayName: undefined as any, + }; + + expect(() => new ConfigurationMessageContact(params2)).to.throw(); + const params2 = { publicKey: TestUtils.generateFakePubKey().key, displayName: '',