fix: fix contact not updating when an ID verif is canceled (#4719)

Fixes https://github.com/status-im/status-desktop/issues/13412
This commit is contained in:
Jonathan Rainville 2024-02-13 14:34:56 -05:00 committed by GitHub
parent e6db622cdb
commit 3a0fe0e62f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 0 deletions

View File

@ -214,6 +214,8 @@ func (m *Messenger) CancelVerificationRequest(ctx context.Context, id string) (*
response.AddVerificationRequest(verifRequest) response.AddVerificationRequest(verifRequest)
response.AddContact(contact)
err = m.SyncVerificationRequest(context.Background(), verifRequest, m.dispatchMessage) err = m.SyncVerificationRequest(context.Background(), verifRequest, m.dispatchMessage)
if err != nil { if err != nil {
return nil, err return nil, err
@ -483,6 +485,8 @@ func (m *Messenger) VerifiedTrusted(ctx context.Context, request *requests.Verif
} }
response.AddMessage(msg) response.AddMessage(msg)
response.AddContact(contact)
return response, nil return response, nil
} }
@ -962,6 +966,24 @@ func (m *Messenger) HandleDeclineContactVerification(state *ReceivedMessageState
return nil // Do nothing, We have already cancelled the verification request 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 { if persistedVR == nil {
// This is a response for which we have not received its request before // This is a response for which we have not received its request before
persistedVR = &verification.Request{} persistedVR = &verification.Request{}

View File

@ -248,6 +248,7 @@ func (s *MessengerVerificationRequests) TestAcceptVerificationRequests() {
s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false) s.Require().Equal(resp.ActivityCenterNotifications()[0].Accepted, false)
s.Require().Equal(resp.ActivityCenterNotifications()[0].Dismissed, 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)}) resp, err = s.m.VerifiedTrusted(context.Background(), &requests.VerifiedTrusted{ID: types.FromHex(verificationRequestID)})
s.Require().NoError(err) s.Require().NoError(err)
s.Require().NotNil(resp) s.Require().NotNil(resp)
@ -260,6 +261,9 @@ func (s *MessengerVerificationRequests) TestAcceptVerificationRequests() {
s.Require().Len(resp.Messages(), 1) s.Require().Len(resp.Messages(), 1)
s.Require().Equal(common.ContactVerificationStateTrusted, resp.Messages()[0].ContactVerificationState) 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() { func (s *MessengerVerificationRequests) TestTrustedVerificationRequests() {
@ -606,6 +610,10 @@ func (s *MessengerVerificationRequests) TestDeclineVerificationRequests() {
s.Require().Len(resp.Messages(), 1) s.Require().Len(resp.Messages(), 1)
s.Require().Equal(resp.Messages()[0].ContactVerificationState, common.ContactVerificationStateDeclined) 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().Len(resp.ActivityCenterNotifications(), 1)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID) s.Require().Equal(resp.ActivityCenterNotifications()[0].ID.String(), verificationRequestID)
s.Require().Equal(resp.ActivityCenterNotifications()[0].ContactVerificationStatus, verification.RequestStatusDECLINED) 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].ID, verificationRequestID)
s.Require().Equal(resp.VerificationRequests()[0].RequestStatus, verification.RequestStatusCANCELED) 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 // Check canceled state on the receiver's side
resp, err = WaitOnMessengerResponse( resp, err = WaitOnMessengerResponse(
theirMessenger, theirMessenger,