From 3a0fe0e62f5fdac5ebb7818f7d861cd09c72b099 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Tue, 13 Feb 2024 14:34:56 -0500 Subject: [PATCH] fix: fix contact not updating when an ID verif is canceled (#4719) Fixes https://github.com/status-im/status-desktop/issues/13412 --- protocol/messenger_contact_verification.go | 22 +++++++++++++++++++ .../messenger_contact_verification_test.go | 12 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/protocol/messenger_contact_verification.go b/protocol/messenger_contact_verification.go index 9a73edc04..05016eede 100644 --- a/protocol/messenger_contact_verification.go +++ b/protocol/messenger_contact_verification.go @@ -214,6 +214,8 @@ func (m *Messenger) CancelVerificationRequest(ctx context.Context, id string) (* response.AddVerificationRequest(verifRequest) + response.AddContact(contact) + err = m.SyncVerificationRequest(context.Background(), verifRequest, m.dispatchMessage) if err != nil { return nil, err @@ -483,6 +485,8 @@ func (m *Messenger) VerifiedTrusted(ctx context.Context, request *requests.Verif } response.AddMessage(msg) + response.AddContact(contact) + return response, nil } @@ -962,6 +966,24 @@ func (m *Messenger) HandleDeclineContactVerification(state *ReceivedMessageState return nil // Do nothing, We have already cancelled the verification request } + contact.VerificationStatus = VerificationStatusUNVERIFIED + contact.LastUpdatedLocally = m.getTimesource().GetCurrentTime() + + err = m.persistence.SaveContact(contact, nil) + if err != nil { + return err + } + + // We sync the contact with the other devices + err = m.syncContact(context.Background(), contact, m.dispatchMessage) + if err != nil { + return err + } + + m.allContacts.Store(contact.ID, contact) + + state.Response.AddContact(contact) + if persistedVR == nil { // This is a response for which we have not received its request before persistedVR = &verification.Request{} diff --git a/protocol/messenger_contact_verification_test.go b/protocol/messenger_contact_verification_test.go index e82a17b81..d33105629 100644 --- a/protocol/messenger_contact_verification_test.go +++ b/protocol/messenger_contact_verification_test.go @@ -248,6 +248,7 @@ func (s *MessengerVerificationRequests) TestAcceptVerificationRequests() { s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false) s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, false) + // Mark as tusted resp, err = s.m.VerifiedTrusted(context.Background(), &requests.VerifiedTrusted{ID: types.FromHex(verificationRequestID)}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -260,6 +261,9 @@ func (s *MessengerVerificationRequests) TestAcceptVerificationRequests() { s.Require().Len(resp.Messages(), 1) s.Require().Equal(common.ContactVerificationStateTrusted, resp.Messages()[0].ContactVerificationState) + s.Require().Len(resp.Contacts, 1) + s.Require().Equal(resp.Contacts[0].ID, theirPk) + s.Require().Equal(resp.Contacts[0].VerificationStatus, VerificationStatusVERIFIED) } func (s *MessengerVerificationRequests) TestTrustedVerificationRequests() { @@ -606,6 +610,10 @@ func (s *MessengerVerificationRequests) TestDeclineVerificationRequests() { s.Require().Len(resp.Messages(), 1) s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStateDeclined) + s.Require().Len(resp.Contacts, 1) + s.Require().Equal(resp.Contacts[0].ID, theirPk) + s.Require().Equal(resp.Contacts[0].VerificationStatus, VerificationStatusUNVERIFIED) + s.Require().Len(resp.ActivityCenterNotifications(), 1) s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID) s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusDECLINED) @@ -683,6 +691,10 @@ func (s *MessengerVerificationRequests) TestCancelVerificationRequest() { s.Require().Equal(resp.VerificationRequests()[0].ID, verificationRequestID) s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusCANCELED) + s.Require().Len(resp.Contacts, 1) + s.Require().Equal(resp.Contacts[0].ID, theirPk) + s.Require().Equal(resp.Contacts[0].VerificationStatus, VerificationStatusUNVERIFIED) + // Check canceled state on the receiver's side resp, err = WaitOnMessengerResponse( theirMessenger,