From 54b36898140c657fceb247eaf19abbf1bd184ee0 Mon Sep 17 00:00:00 2001 From: Andrea Maria Piana Date: Fri, 29 Oct 2021 16:18:21 +0100 Subject: [PATCH] Allow setting ens name --- protocol/messenger_contacts.go | 14 ++++++++++++-- protocol/requests/add_contact.go | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) 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 {