mirror of
https://github.com/status-im/status-go.git
synced 2025-01-12 23:55:03 +00:00
Fix syncing of contact request local state
This commit is contained in:
parent
7c7c3a1f13
commit
6cdc0ed5a1
@ -279,7 +279,7 @@ func (c *Contact) DismissContactRequest(clock uint64) ContactRequestProcessingRe
|
||||
|
||||
// Remote actions
|
||||
|
||||
func (c *Contact) contactRequestRetracted(clock uint64, r ContactRequestProcessingResponse) ContactRequestProcessingResponse {
|
||||
func (c *Contact) contactRequestRetracted(clock uint64, syncing bool, r ContactRequestProcessingResponse) ContactRequestProcessingResponse {
|
||||
if clock <= c.ContactRequestRemoteClock {
|
||||
return r
|
||||
}
|
||||
@ -289,7 +289,7 @@ func (c *Contact) contactRequestRetracted(clock uint64, r ContactRequestProcessi
|
||||
// the side it was sent from. The only exception is when the contact
|
||||
// request has been explicitly dismissed, in which case we don't
|
||||
// change state
|
||||
if c.ContactRequestLocalState != ContactRequestStateDismissed {
|
||||
if c.ContactRequestLocalState != ContactRequestStateDismissed && !syncing {
|
||||
c.ContactRequestLocalClock = clock
|
||||
c.ContactRequestLocalState = ContactRequestStateNone
|
||||
}
|
||||
@ -299,8 +299,8 @@ func (c *Contact) contactRequestRetracted(clock uint64, r ContactRequestProcessi
|
||||
return r
|
||||
}
|
||||
|
||||
func (c *Contact) ContactRequestRetracted(clock uint64) ContactRequestProcessingResponse {
|
||||
return c.contactRequestRetracted(clock, ContactRequestProcessingResponse{})
|
||||
func (c *Contact) ContactRequestRetracted(clock uint64, syncing bool) ContactRequestProcessingResponse {
|
||||
return c.contactRequestRetracted(clock, syncing, ContactRequestProcessingResponse{})
|
||||
}
|
||||
|
||||
func (c *Contact) contactRequestReceived(clock uint64, r ContactRequestProcessingResponse) ContactRequestProcessingResponse {
|
||||
@ -379,7 +379,7 @@ func contactIDFromPublicKeyString(key string) (string, error) {
|
||||
return contactIDFromPublicKey(pubKey), nil
|
||||
}
|
||||
|
||||
func (c *Contact) processSyncContactRequestState(remoteState ContactRequestState, remoteClock uint64, localState ContactRequestState, localClock uint64) {
|
||||
func (c *Contact) ProcessSyncContactRequestState(remoteState ContactRequestState, remoteClock uint64, localState ContactRequestState, localClock uint64) {
|
||||
// We process the two separately, first local state
|
||||
switch localState {
|
||||
case ContactRequestStateDismissed:
|
||||
@ -395,7 +395,7 @@ func (c *Contact) processSyncContactRequestState(remoteState ContactRequestState
|
||||
case ContactRequestStateReceived:
|
||||
c.ContactRequestReceived(remoteClock)
|
||||
case ContactRequestStateNone:
|
||||
c.ContactRequestRetracted(remoteClock)
|
||||
c.ContactRequestRetracted(remoteClock, true)
|
||||
}
|
||||
}
|
||||
|
||||
@ -481,7 +481,7 @@ func (c *Contact) ContactRequestPropagatedStateReceived(state *protobuf.ContactR
|
||||
if remoteState == ContactRequestStateSent {
|
||||
response = c.contactRequestReceived(remoteClock, response)
|
||||
} else if remoteState == ContactRequestStateNone {
|
||||
response = c.contactRequestRetracted(remoteClock, response)
|
||||
response = c.contactRequestRetracted(remoteClock, false, response)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -402,7 +402,7 @@ func TestContactContactRequestRetracted(t *testing.T) {
|
||||
for testNum, tc := range tests {
|
||||
contact := tc.Contact()
|
||||
|
||||
contact.ContactRequestRetracted(clock)
|
||||
contact.ContactRequestRetracted(clock, false)
|
||||
validateContactTest(t, contact, tc, testNum+1)
|
||||
|
||||
}
|
||||
@ -765,3 +765,18 @@ func TestPrimaryName(t *testing.T) {
|
||||
require.Equal(t, "nickname", contact.PrimaryName())
|
||||
require.Equal(t, "alias", contact.SecondaryName())
|
||||
}
|
||||
|
||||
func TestProcessSyncContactRequestState(t *testing.T) {
|
||||
c := &Contact{}
|
||||
c.ContactRequestLocalState = ContactRequestStateNone
|
||||
c.ContactRequestLocalClock = 1
|
||||
c.ContactRequestRemoteState = ContactRequestStateNone
|
||||
c.ContactRequestRemoteClock = 1
|
||||
|
||||
c.ProcessSyncContactRequestState(ContactRequestStateNone, 2, ContactRequestStateSent, 2)
|
||||
|
||||
// Here we need to confirm that resulting Local/RemoteState is equal
|
||||
// to what comes from the contact sync message, otherwise it will be inconsistent
|
||||
require.Equal(t, ContactRequestStateSent, c.ContactRequestLocalState)
|
||||
require.Equal(t, ContactRequestStateNone, c.ContactRequestRemoteState)
|
||||
}
|
||||
|
@ -483,7 +483,7 @@ func (m *Messenger) HandleSyncInstallationContact(state *ReceivedMessageState, m
|
||||
if message.ContactRequestRemoteClock != 0 || message.ContactRequestLocalClock != 0 {
|
||||
// Some local action about contact requests were performed,
|
||||
// process them
|
||||
contact.processSyncContactRequestState(
|
||||
contact.ProcessSyncContactRequestState(
|
||||
ContactRequestState(message.ContactRequestRemoteState),
|
||||
uint64(message.ContactRequestRemoteClock),
|
||||
ContactRequestState(message.ContactRequestLocalState),
|
||||
@ -888,7 +888,7 @@ func (m *Messenger) handleRetractContactRequest(contact *Contact, message protob
|
||||
}
|
||||
|
||||
m.logger.Debug("handling retracted contact request", zap.Uint64("clock", message.Clock))
|
||||
r := contact.ContactRequestRetracted(message.Clock)
|
||||
r := contact.ContactRequestRetracted(message.Clock, false)
|
||||
if !r.processed {
|
||||
m.logger.Debug("not handling retract since clock lower")
|
||||
return nil
|
||||
|
Loading…
x
Reference in New Issue
Block a user