mirror of
https://github.com/status-im/status-go.git
synced 2025-01-17 18:22:13 +00:00
fix(backup)_: dont generate a CR if the synced contact is mutual (#6184)
Fixes https://github.com/status-im/status-desktop/issues/15849 The problem was that we generated a "fake" contact request for all synced contacts. While it's true that even mutual contacts have a contact request, we don't need it anymore once mutual and since we don't sync messages, we had to generate it with a default message and that message looked very out of place after a recovery.
This commit is contained in:
parent
f2f32c42b0
commit
90ce72a2d5
@ -601,6 +601,7 @@ func (m *Messenger) generateContactRequest(clock uint64, timestamp uint64, conta
|
||||
contactRequest := common.NewMessage()
|
||||
contactRequest.ChatId = contact.ID
|
||||
contactRequest.WhisperTimestamp = timestamp
|
||||
contactRequest.Timestamp = timestamp
|
||||
contactRequest.Seen = true
|
||||
contactRequest.Text = text
|
||||
if outgoing {
|
||||
|
@ -478,6 +478,10 @@ func (m *Messenger) handleCommandMessage(state *ReceivedMessageState, message *c
|
||||
}
|
||||
|
||||
func (m *Messenger) syncContactRequestForInstallationContact(contact *Contact, state *ReceivedMessageState, chat *Chat, outgoing bool) error {
|
||||
if contact.mutual() {
|
||||
// We only need to generate a contact request if we are not mutual
|
||||
return nil
|
||||
}
|
||||
|
||||
if chat == nil {
|
||||
return fmt.Errorf("no chat restored during the contact synchronisation, contact.ID = %s", contact.ID)
|
||||
|
@ -619,7 +619,7 @@ func (s *SyncDeviceSuite) TestPairPendingContactRequest() {
|
||||
type contactRequestAction func(messenger *protocol.Messenger, contactRequestID string) (*protocol.MessengerResponse, error)
|
||||
type notificationValidateFunc func(r *protocol.ActivityCenterPaginationResponse)
|
||||
|
||||
func (s *SyncDeviceSuite) testPairContactRequest(requestAction contactRequestAction, validateFunc notificationValidateFunc) {
|
||||
func (s *SyncDeviceSuite) testPairContactRequest(requestAction contactRequestAction, validateFunc notificationValidateFunc, validateFuncPaired notificationValidateFunc) {
|
||||
bobBackend, _ := s.createUser("bob")
|
||||
defer func() {
|
||||
s.Require().NoError(bobBackend.Logout())
|
||||
@ -648,7 +648,7 @@ func (s *SyncDeviceSuite) testPairContactRequest(requestAction contactRequestAct
|
||||
}()
|
||||
s.pairAccounts(alice1Backend, alice1TmpDir, alice2Backend, alice2TmpDir)
|
||||
|
||||
internalNotificationValidateFunc := func(m *protocol.Messenger) {
|
||||
internalNotificationValidateFunc := func(m *protocol.Messenger, isPairedDevice bool) {
|
||||
acRequest := protocol.ActivityCenterNotificationsRequest{
|
||||
ActivityTypes: []protocol.ActivityCenterType{
|
||||
protocol.ActivityCenterNotificationTypeContactRequest,
|
||||
@ -658,35 +658,51 @@ func (s *SyncDeviceSuite) testPairContactRequest(requestAction contactRequestAct
|
||||
}
|
||||
r, err := m.ActivityCenterNotifications(acRequest)
|
||||
s.Require().NoError(err)
|
||||
validateFunc(r)
|
||||
if isPairedDevice {
|
||||
validateFuncPaired(r)
|
||||
} else {
|
||||
validateFunc(r)
|
||||
}
|
||||
}
|
||||
|
||||
internalNotificationValidateFunc(alice1Backend.Messenger())
|
||||
internalNotificationValidateFunc(alice2Backend.Messenger())
|
||||
internalNotificationValidateFunc(alice1Backend.Messenger(), false)
|
||||
internalNotificationValidateFunc(alice2Backend.Messenger(), true)
|
||||
}
|
||||
|
||||
func (s *SyncDeviceSuite) TestPairDeclineContactRequest() {
|
||||
declineContactRequest := func(messenger *protocol.Messenger, contactRequestID string) (*protocol.MessengerResponse, error) {
|
||||
return messenger.DeclineContactRequest(context.Background(), &requests.DeclineContactRequest{ID: types.Hex2Bytes(contactRequestID)})
|
||||
}
|
||||
s.testPairContactRequest(declineContactRequest, func(r *protocol.ActivityCenterPaginationResponse) {
|
||||
validateFunc := func(r *protocol.ActivityCenterPaginationResponse) {
|
||||
s.Require().Len(r.Notifications, 1)
|
||||
s.Require().False(r.Notifications[0].Accepted)
|
||||
s.Require().True(r.Notifications[0].Dismissed)
|
||||
s.Require().True(r.Notifications[0].Read)
|
||||
})
|
||||
}
|
||||
s.testPairContactRequest(
|
||||
declineContactRequest,
|
||||
validateFunc,
|
||||
// The paired device will get a notification because the request will not be fulfilled (not mutual)
|
||||
validateFunc,
|
||||
)
|
||||
}
|
||||
|
||||
func (s *SyncDeviceSuite) TestPairAcceptContactRequest() {
|
||||
acceptContactRequest := func(messenger *protocol.Messenger, contactRequestID string) (*protocol.MessengerResponse, error) {
|
||||
return messenger.AcceptContactRequest(context.Background(), &requests.AcceptContactRequest{ID: types.Hex2Bytes(contactRequestID)})
|
||||
}
|
||||
s.testPairContactRequest(acceptContactRequest, func(r *protocol.ActivityCenterPaginationResponse) {
|
||||
s.Require().Len(r.Notifications, 1)
|
||||
s.Require().True(r.Notifications[0].Accepted)
|
||||
s.Require().False(r.Notifications[0].Dismissed)
|
||||
s.Require().True(r.Notifications[0].Read)
|
||||
})
|
||||
s.testPairContactRequest(
|
||||
acceptContactRequest,
|
||||
func(r *protocol.ActivityCenterPaginationResponse) {
|
||||
s.Require().Len(r.Notifications, 1)
|
||||
s.Require().True(r.Notifications[0].Accepted)
|
||||
s.Require().False(r.Notifications[0].Dismissed)
|
||||
s.Require().True(r.Notifications[0].Read)
|
||||
},
|
||||
// The paired device doesn't need a notification because it will receive the fully mutual contact
|
||||
func(r *protocol.ActivityCenterPaginationResponse) {
|
||||
s.Require().Len(r.Notifications, 0)
|
||||
})
|
||||
}
|
||||
|
||||
type testTimeSource struct{}
|
||||
|
Loading…
x
Reference in New Issue
Block a user