Update wakuext_buildContact

This commit is contained in:
Roman Volosovskyi 2023-03-14 16:34:35 +01:00
parent cd96f557f9
commit 290579f74f
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
8 changed files with 39 additions and 13 deletions

View File

@ -1 +1 @@
0.138.2
0.138.3

View File

@ -290,7 +290,7 @@ func (m *Messenger) CreateOneToOneChat(request *requests.CreateOneToOneChat) (*M
if err != nil {
return nil, err
}
contact, err := m.BuildContact(chatID)
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: chatID})
if err != nil {
return nil, err
}

View File

@ -1722,3 +1722,18 @@ func (s *MessengerContactRequestSuite) TestAliceOfflineRetractsAndAddsWrongOrder
s.Require().True(result.newContactRequestReceived)
}
func (s *MessengerContactRequestSuite) TestBuildContact() {
contactID := types.EncodeHex(crypto.FromECDSAPub(&s.m.identity.PublicKey))
contact, err := s.m.BuildContact(&requests.BuildContact{PublicKey: contactID})
s.Require().NoError(err)
s.Require().Equal(contact.EnsName, "")
s.Require().False(contact.ENSVerified)
contact, err = s.m.BuildContact(&requests.BuildContact{PublicKey: contactID, ENSName: "foobar"})
s.Require().NoError(err)
s.Require().Equal(contact.EnsName, "foobar")
s.Require().True(contact.ENSVerified)
}

View File

@ -54,7 +54,7 @@ func (m *Messenger) declineContactRequest(requestID string, syncing bool) (*Mess
return nil, err
}
contact, err := m.BuildContact(contactRequest.From)
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: contactRequest.From})
if err != nil {
return nil, err
}
@ -313,7 +313,7 @@ func (m *Messenger) updateAcceptedContactRequest(response *MessengerResponse, co
}
func (m *Messenger) addContact(pubKey, ensName, nickname, displayName, contactRequestID string, contactRequestText string, syncing bool, sendContactUpdate bool, createOutgoingContactRequestNotification bool) (*MessengerResponse, error) {
contact, err := m.BuildContact(pubKey)
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: pubKey})
if err != nil {
return nil, err
}
@ -672,7 +672,7 @@ func (m *Messenger) SetContactLocalNickname(request *requests.SetContactLocalNic
pubKey := request.ID.String()
nickname := request.Nickname
contact, err := m.BuildContact(pubKey)
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: pubKey})
if err != nil {
return nil, err
}
@ -704,7 +704,7 @@ func (m *Messenger) SetContactLocalNickname(request *requests.SetContactLocalNic
}
func (m *Messenger) blockContact(contactID string, isDesktopFunc bool) ([]*Chat, error) {
contact, err := m.BuildContact(contactID)
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: contactID})
if err != nil {
return nil, err
}
@ -1024,14 +1024,19 @@ func defaultContactRequestID(contactID string) string {
return "0x" + types.Bytes2Hex(append(types.Hex2Bytes(contactID), 0x20))
}
func (m *Messenger) BuildContact(contactID string) (*Contact, error) {
contact, ok := m.allContacts.Load(contactID)
func (m *Messenger) BuildContact(request *requests.BuildContact) (*Contact, error) {
contact, ok := m.allContacts.Load(request.PublicKey)
if !ok {
var err error
contact, err = buildContactFromPkString(contactID)
contact, err = buildContactFromPkString(request.PublicKey)
if err != nil {
return nil, err
}
if request.ENSName != "" {
contact.ENSVerified = true
contact.EnsName = request.ENSName
}
}
// Schedule sync filter to fetch information about the contact

View File

@ -1805,7 +1805,7 @@ func (m *Messenger) HandleChatMessage(state *ReceivedMessageState) error {
if receivedMessage.ContentType == protobuf.ChatMessage_CONTACT_REQUEST && chat.OneToOne() {
chatContact := contact
if isSyncMessage {
chatContact, err = m.BuildContact(chat.ID)
chatContact, err = m.BuildContact(&requests.BuildContact{PublicKey: chat.ID})
if err != nil {
return err
}

View File

@ -351,7 +351,7 @@ func (m *Messenger) addContactRequestPropagatedState(message *common.Message) er
return nil
}
contact, err := m.BuildContact(chat.ID)
contact, err := m.BuildContact(&requests.BuildContact{PublicKey: chat.ID})
if err != nil {
return err
}

View File

@ -0,0 +1,6 @@
package requests
type BuildContact struct {
PublicKey string `json:"publicKey"`
ENSName string `json:"ENSName"`
}

View File

@ -1248,8 +1248,8 @@ func (api *PublicAPI) RequestCancelDiscordCommunityImport(id string) {
api.service.messenger.MarkDiscordCommunityImportAsCancelled(id)
}
func (api *PublicAPI) BuildContact(publicKey string) (*protocol.Contact, error) {
return api.service.messenger.BuildContact(publicKey)
func (api *PublicAPI) BuildContact(request *requests.BuildContact) (*protocol.Contact, error) {
return api.service.messenger.BuildContact(request)
}
func (api *PublicAPI) GetCommunityTokens(communityID string) ([]*communities.CommunityToken, error) {