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.
This commit is contained in:
parent
640f5533ca
commit
0ff2542939
|
@ -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}
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Reference in New Issue