diff --git a/protocol/messenger_contacts.go b/protocol/messenger_contacts.go index 50fbdfa2c..e9ae7ac54 100644 --- a/protocol/messenger_contacts.go +++ b/protocol/messenger_contacts.go @@ -20,6 +20,8 @@ func (m *Messenger) AddContact(ctx context.Context, request *requests.AddContact pubKey := request.ID.String() + ensName := request.ENSName + contact, ok := m.allContacts.Load(pubKey) if !ok { var err error @@ -29,6 +31,14 @@ func (m *Messenger) AddContact(ctx context.Context, request *requests.AddContact } } + if ensName != "" { + clock := m.getTimesource().GetCurrentTime() + err := m.ensVerifier.ENSVerified(pubKey, ensName, clock) + if err != nil { + return nil, err + } + } + if err := m.addENSNameToContact(contact); err != nil { return nil, err } @@ -87,12 +97,12 @@ func (m *Messenger) AddContact(ctx context.Context, request *requests.AddContact } m.scheduleSyncFilter(filter) - // Finally we send a contact update so they are notified we added them - ensName, err := m.settings.ENSName() + ensName, err = m.settings.ENSName() if err != nil { return nil, err } + // Finally we send a contact update so they are notified we added them response, err := m.sendContactUpdate(context.Background(), pubKey, ensName, "") if err != nil { return nil, err diff --git a/protocol/requests/add_contact.go b/protocol/requests/add_contact.go index ff221151c..927f8b1b7 100644 --- a/protocol/requests/add_contact.go +++ b/protocol/requests/add_contact.go @@ -11,6 +11,7 @@ var ErrAddContactInvalidID = errors.New("add-contact: invalid id") type AddContact struct { ID types.HexBytes `json:"id"` Nickname string `json:"nickname"` + ENSName string `json:"ensName"` } func (a *AddContact) Validate() error {