From 44782a2429dcc456901638cd8648e24c9e5b9eb1 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 23 Apr 2025 12:11:10 -0400 Subject: [PATCH] fix(backup)_: do not show the backup notifi backup during normal fetch Fixes https://github.com/status-im/status-desktop/issues/17555 We were adding the Notification of the back ups by accident when creating a normal account (not restored), because I added the code to create the notification in the `RequestAllHistoricMessages` function as well, even though the Messenger already does it. So for normal restores, it probably tried to add it twice, though they have the same ID, so it wasn't noticed --- api/backend_test.go | 7 +++++++ api/geth_backend.go | 5 +++++ multiaccounts/settings/database.go | 6 ++++-- multiaccounts/settings/structs.go | 1 + protocol/messenger_backup_handler.go | 4 ++++ protocol/messenger_backup_test.go | 31 ++++++++++++++++++++++++++++ protocol/messenger_mailserver.go | 5 ----- 7 files changed, 52 insertions(+), 7 deletions(-) diff --git a/api/backend_test.go b/api/backend_test.go index 0e0a6b97f8a..4b1967b6a9b 100644 --- a/api/backend_test.go +++ b/api/backend_test.go @@ -865,6 +865,13 @@ func TestLoginAccount(t *testing.T) { acc, err := b.CreateAccountAndLogin(createAccountRequest) require.NoError(t, err) require.Equal(t, nameserver, b.config.WakuV2Config.Nameserver) + + accountsDB, err := b.accountsDB() + require.NoError(t, err) + backupFecthed, err := accountsDB.BackupFetched() + require.NoError(t, err) + require.True(t, backupFecthed) + require.True(t, acc.HasAcceptedTerms) waitForLogin(c) diff --git a/api/geth_backend.go b/api/geth_backend.go index 4288c6ef85e..37ddfcfd545 100644 --- a/api/geth_backend.go +++ b/api/geth_backend.go @@ -1773,6 +1773,11 @@ func (b *GethStatusBackend) prepareSettings(request *requests.CreateAccount, inp //settings.MnemonicWasNotShown = true } + if !input.fetchBackup { + // This is a an account created from scratch, we can mark the BackupFetched as true + settings.BackupFetched = true + } + if request.WakuV2Fleet != "" { settings.Fleet = &request.WakuV2Fleet } diff --git a/multiaccounts/settings/database.go b/multiaccounts/settings/database.go index 4ca7d9ecbed..388ca9d5ae3 100644 --- a/multiaccounts/settings/database.go +++ b/multiaccounts/settings/database.go @@ -148,10 +148,11 @@ INSERT INTO settings ( test_networks_enabled, fleet, auto_refresh_tokens_enabled, - news_feed_last_fetched_timestamp + news_feed_last_fetched_timestamp, + backup_fetched ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?, -?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?,?,?)`, +?,?,?,?,?,?,?,?,?,'id',?,?,?,?,?,?,?,?,?,?,?,?,?)`, s.Address, s.Currency, s.CurrentNetwork, @@ -188,6 +189,7 @@ INSERT INTO settings ( s.AutoRefreshTokensEnabled, // Default the news feed last fetched timestamp to now time.Now().Unix(), + s.BackupFetched, ) if err != nil { return err diff --git a/multiaccounts/settings/structs.go b/multiaccounts/settings/structs.go index d9f9fb10a47..9a0218fe9ab 100644 --- a/multiaccounts/settings/structs.go +++ b/multiaccounts/settings/structs.go @@ -216,6 +216,7 @@ type Settings struct { TelemetrySendPeriodMs int `json:"telemetry-send-period-ms,omitempty"` LastBackup uint64 `json:"last-backup,omitempty"` BackupEnabled bool `json:"backup-enabled?,omitempty"` + BackupFetched bool `json:"backup-fetched?,omitempty"` AutoMessageEnabled bool `json:"auto-message-enabled?,omitempty"` GifAPIKey string `json:"gifs/api-key"` TestNetworksEnabled bool `json:"test-networks-enabled?,omitempty"` diff --git a/protocol/messenger_backup_handler.go b/protocol/messenger_backup_handler.go index c0165d9177c..b217fa9b240 100644 --- a/protocol/messenger_backup_handler.go +++ b/protocol/messenger_backup_handler.go @@ -127,6 +127,10 @@ func (m *Messenger) handleBackup(state *ReceivedMessageState, message *protobuf. } func (m *Messenger) updateBackupFetchProgress(message *protobuf.Backup, response *wakusync.WakuBackedUpDataResponse, state *ReceivedMessageState) error { + if m.backedUpFetchingStatus == nil { + return nil + } + m.backedUpFetchingStatus.fetchingCompletedMutex.Lock() defer m.backedUpFetchingStatus.fetchingCompletedMutex.Unlock() diff --git a/protocol/messenger_backup_test.go b/protocol/messenger_backup_test.go index 3403e5cc8b5..6067a99a310 100644 --- a/protocol/messenger_backup_test.go +++ b/protocol/messenger_backup_test.go @@ -417,6 +417,37 @@ func (s *MessengerBackupSuite) TestFetchingDuringBackup() { s.Require().Equal(ActivityCenterNotificationTypeBackupSyncingSuccess, state.Response.ActivityCenterNotifications()[0].Type) } +func (s *MessengerBackupSuite) TestBackupWithoutStatusFetching() { + bob1 := s.m + // Remove the status fetching + bob1.backedUpFetchingStatus = nil + bob1.config.messengerSignalsHandler = &MessengerSignalsHandlerMock{ + wakuBackedUpDataResponseChan: make(chan *wakusync.WakuBackedUpDataResponse, 1000), + } + + state := ReceivedMessageState{ + Response: &MessengerResponse{}, + } + + backup := &protobuf.Backup{ + Clock: 1, + ContactsDetails: &protobuf.FetchingBackedUpDataDetails{ + DataNumber: uint32(0), + TotalNumber: uint32(1), + }, + } + + err := bob1.HandleBackup( + &state, + backup, + &v1protocol.StatusMessage{}, + ) + s.Require().NoError(err) + // The backup was handled but nothing was sent to the AC + s.Require().Len(state.Response.ActivityCenterNotifications(), 0) + s.Require().True(state.Response.BackupHandled) +} + func (s *MessengerBackupSuite) TestBackupSettings() { s.T().Skip("flaky test") const ( diff --git a/protocol/messenger_mailserver.go b/protocol/messenger_mailserver.go index d8d80f226c6..f27fbf9c7f0 100644 --- a/protocol/messenger_mailserver.go +++ b/protocol/messenger_mailserver.go @@ -320,11 +320,6 @@ func (m *Messenger) RequestAllHistoricMessages(forceFetchingBackup, withRetries allResponses := &MessengerResponse{} if forceFetchingBackup || !backupFetched { - err = m.startBackupFetchingTracking(allResponses) - if err != nil { - return nil, err - } - m.logger.Info("fetching backup") err := m.syncBackup() if err != nil {