From 0ff2542939fb9a626b26e90fe4900287bb111107 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Wed, 26 Aug 2020 10:36:58 +0200 Subject: [PATCH] Don't add contact on update When sending a contact update we automatically added the contact, but that resulted in the contact not being synced correctly as `saveContact` will not trigger the side effects. For now I have removed this behavior. Ideally we should have a single call that handles the side effects, but for that ENS names should be stored in messenger, so we can propagate it. --- protocol/messenger.go | 18 ++++++++++++++---- protocol/messenger_contact_update_test.go | 7 ++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/protocol/messenger.go b/protocol/messenger.go index 23fb3a49a..15037f958 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -1263,11 +1263,19 @@ func (m *Messenger) BlockContact(contact *Contact) ([]*Chat, error) { if err != nil { return nil, err } + m.allContacts[contact.ID] = contact for _, chat := range chats { m.allChats[chat.ID] = chat } delete(m.allChats, contact.ID) + + // re-register for push notifications + err = m.reregisterForPushNotifications() + if err != nil { + return nil, err + } + return chats, nil } @@ -1562,6 +1570,12 @@ func (m *Messenger) SendContactUpdates(ctx context.Context, ensName, profileImag return nil } +// NOTE: this endpoint does not add the contact, the reason being is that currently +// that's left as a responsibility to the client, which will call both `SendContactUpdate` +// and `SaveContact` with the correct system tag. +// Ideally we have a single endpoint that does both, but probably best to bring `ENS` name +// on the messenger first. + // SendContactUpdate sends a contact update to a user and adds the user to contacts func (m *Messenger) SendContactUpdate(ctx context.Context, chatID, ensName, profileImage string) (*MessengerResponse, error) { m.mutex.Lock() @@ -1623,10 +1637,6 @@ func (m *Messenger) sendContactUpdate(ctx context.Context, chatID, ensName, prof return nil, err } - if !contact.IsAdded() && contact.ID != contactIDFromPublicKey(&m.identity.PublicKey) { - contact.SystemTags = append(contact.SystemTags, contactAdded) - } - response.Contacts = []*Contact{contact} response.Chats = []*Chat{chat} diff --git a/protocol/messenger_contact_update_test.go b/protocol/messenger_contact_update_test.go index c89a7f645..b54f8360d 100644 --- a/protocol/messenger_contact_update_test.go +++ b/protocol/messenger_contact_update_test.go @@ -99,7 +99,12 @@ func (s *MessengerContactUpdateSuite) TestReceiveContactUpdate() { s.Require().Len(response.Contacts, 1) contact := response.Contacts[0] - s.Require().True(contact.IsAdded()) + // It should not add the contact, as that's left to `SaveContact` + s.Require().False(contact.IsAdded()) + + // add contact + contact.SystemTags = []string{contactAdded} + s.Require().NoError(theirMessenger.SaveContact(contact)) s.Require().Len(response.Chats, 1) chat := response.Chats[0]