Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(onboarding)_: add a notification when importing old account #6255

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

jrainville
Copy link
Member

Needed for status-im/status-desktop#17028

When a user imports an old account, we start fetching the backups. Now, we show an activity center notification to let the user know, because the onboarding doesn't block during the fetching anymore, so it happens in the background.

After a timeout, the notification turns into a failure state (full or partial). The user can then restart the fetching.

I added a test to validate the logic of calculating if the fetching was a success. That logic used to be in Nim.

@status-im-auto
Copy link
Member

status-im-auto commented Jan 15, 2025

Jenkins Builds

Click to see older builds (48)
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ cc655fc #1 2025-01-15 18:50:52 ~4 min ios 📦zip
✖️ cc655fc #1 2025-01-15 18:50:58 ~4 min tests 📄log
✔️ cc655fc #1 2025-01-15 18:51:50 ~5 min macos 📦zip
✔️ cc655fc #1 2025-01-15 18:52:02 ~5 min linux 📦zip
✔️ cc655fc #1 2025-01-15 18:52:13 ~5 min macos 📦zip
✔️ cc655fc #1 2025-01-15 18:52:19 ~5 min windows 📦zip
✔️ cc655fc #1 2025-01-15 18:52:33 ~5 min android 📦aar
✔️ cc655fc #1 2025-01-15 18:53:17 ~6 min tests-rpc 📄log
✔️ 4ed5c9a #2 2025-01-15 19:09:31 ~3 min macos 📦zip
✔️ 4ed5c9a #2 2025-01-15 19:09:39 ~3 min windows 📦zip
✔️ 4ed5c9a #2 2025-01-15 19:10:40 ~4 min ios 📦zip
✔️ 4ed5c9a #2 2025-01-15 19:10:52 ~5 min linux 📦zip
✔️ 4ed5c9a #2 2025-01-15 19:11:12 ~5 min macos 📦zip
✔️ 4ed5c9a #2 2025-01-15 19:12:06 ~6 min android 📦aar
✔️ 4ed5c9a #2 2025-01-15 19:12:57 ~7 min tests-rpc 📄log
✔️ 4ed5c9a #2 2025-01-15 19:37:23 ~31 min tests 📄log
✔️ 4ed5c9a #3 2025-01-21 18:33:07 ~3 min macos 📦zip
✔️ 4ed5c9a #3 2025-01-21 18:33:26 ~3 min ios 📦zip
✔️ 4ed5c9a #3 2025-01-21 18:35:04 ~5 min macos 📦zip
✔️ 4ed5c9a #3 2025-01-21 18:35:13 ~5 min linux 📦zip
✔️ 4ed5c9a #3 2025-01-21 18:35:15 ~5 min windows 📦zip
✔️ 4ed5c9a #3 2025-01-21 18:35:20 ~5 min android 📦aar
✔️ 4ed5c9a #3 2025-01-21 18:36:10 ~6 min tests-rpc 📄log
✖️ 4ed5c9a #3 2025-01-21 18:47:32 ~17 min tests 📄log
✔️ b8a3d32 #4 2025-01-23 16:50:03 ~3 min macos 📦zip
✔️ b8a3d32 #4 2025-01-23 16:50:43 ~4 min ios 📦zip
✔️ b8a3d32 #4 2025-01-23 16:51:32 ~4 min windows 📦zip
✔️ b8a3d32 #4 2025-01-23 16:53:09 ~6 min macos 📦zip
✔️ b8a3d32 #4 2025-01-23 16:56:53 ~10 min android 📦aar
✔️ b8a3d32 #4 2025-01-23 16:58:40 ~12 min linux 📦zip
✖️ b8a3d32 #4 2025-01-23 17:00:06 ~13 min tests-rpc 📄log
✔️ b8a3d32 #4 2025-01-23 17:25:07 ~38 min tests 📄log
✔️ 746cb48 #5 2025-01-24 15:49:12 ~3 min macos 📦zip
✔️ 746cb48 #5 2025-01-24 15:49:46 ~4 min windows 📦zip
✔️ 746cb48 #5 2025-01-24 15:49:53 ~4 min ios 📦zip
✔️ 746cb48 #5 2025-01-24 15:50:57 ~5 min linux 📦zip
✔️ 746cb48 #5 2025-01-24 15:51:08 ~5 min macos 📦zip
✔️ 746cb48 #5 2025-01-24 15:51:31 ~5 min android 📦aar
✔️ 746cb48 #5 2025-01-24 15:51:47 ~6 min tests-rpc 📄log
✔️ 746cb48 #5 2025-01-24 16:17:12 ~31 min tests 📄log
✔️ 68eb5b5 #6 2025-01-27 16:13:24 ~4 min macos 📦zip
✔️ 68eb5b5 #6 2025-01-27 16:13:54 ~5 min windows 📦zip
✔️ 68eb5b5 #6 2025-01-27 16:14:20 ~5 min macos 📦zip
✔️ 68eb5b5 #6 2025-01-27 16:15:23 ~6 min android 📦aar
✔️ 68eb5b5 #6 2025-01-27 16:15:36 ~7 min ios 📦zip
✔️ 68eb5b5 #6 2025-01-27 16:15:36 ~7 min linux 📦zip
✔️ 68eb5b5 #6 2025-01-27 16:19:11 ~10 min tests-rpc 📄log
✔️ 68eb5b5 #6 2025-01-27 16:42:37 ~34 min tests 📄log
Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ 43276bf #7 2025-01-27 19:00:09 ~3 min macos 📦zip
✔️ 43276bf #7 2025-01-27 19:00:28 ~3 min windows 📦zip
✔️ 43276bf #7 2025-01-27 19:00:33 ~3 min ios 📦zip
✔️ 43276bf #7 2025-01-27 19:02:04 ~5 min macos 📦zip
✔️ 43276bf #7 2025-01-27 19:02:15 ~5 min linux 📦zip
✔️ 43276bf #7 2025-01-27 19:02:23 ~5 min android 📦aar
✔️ 43276bf #7 2025-01-27 19:03:07 ~6 min tests-rpc 📄log
✔️ 43276bf #7 2025-01-27 19:26:32 ~29 min tests 📄log
✔️ e4aad76 #8 2025-01-28 18:36:43 ~3 min macos 📦zip
✔️ e4aad76 #8 2025-01-28 18:37:05 ~3 min windows 📦zip
✔️ e4aad76 #8 2025-01-28 18:38:34 ~5 min macos 📦zip
✔️ e4aad76 #8 2025-01-28 18:38:46 ~5 min linux 📦zip
✔️ e4aad76 #8 2025-01-28 18:38:55 ~5 min ios 📦zip
✔️ e4aad76 #8 2025-01-28 18:39:00 ~5 min android 📦aar
✔️ e4aad76 #8 2025-01-28 18:39:21 ~6 min tests-rpc 📄log
✖️ e4aad76 #8 2025-01-28 19:02:59 ~29 min tests 📄log

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 66.66667% with 27 lines in your changes missing coverage. Please review.

Project coverage is 61.86%. Comparing base (06d2419) to head (43276bf).

Files with missing lines Patch % Lines
protocol/messenger_backup_handler.go 68.57% 10 Missing and 12 partials ⚠️
protocol/messenger.go 50.00% 1 Missing and 1 partial ⚠️
protocol/messenger_mailserver.go 50.00% 1 Missing and 1 partial ⚠️
protocol/messenger_testing_utils.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #6255      +/-   ##
===========================================
+ Coverage    61.84%   61.86%   +0.02%     
===========================================
  Files          843      843              
  Lines       111287   111366      +79     
===========================================
+ Hits         68823    68900      +77     
+ Misses       34497    34486      -11     
- Partials      7967     7980      +13     
Flag Coverage Δ
functional 21.61% <14.81%> (-0.02%) ⬇️
unit 60.33% <66.66%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
protocol/activity_center.go 89.47% <ø> (ø)
protocol/wakusync/progress_response.go 86.66% <ø> (+86.66%) ⬆️
protocol/messenger_testing_utils.go 60.86% <66.66%> (+0.86%) ⬆️
protocol/messenger.go 64.41% <50.00%> (+0.16%) ⬆️
protocol/messenger_mailserver.go 45.81% <50.00%> (-2.32%) ⬇️
protocol/messenger_backup_handler.go 57.19% <68.57%> (+8.09%) ⬆️

... and 26 files with indirect coverage changes

Base automatically changed from feat/new-onbaording to develop January 21, 2025 18:29
@jrainville jrainville force-pushed the feat/new-onboarding-fetching-notification branch 3 times, most recently from 746cb48 to 68eb5b5 Compare January 27, 2025 16:08
Copy link
Contributor

@osmaczko osmaczko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks ok to me, but if @saledjenic would be able to take a look as well, it would be great 🤞

notifications, err := m.persistence.GetActivityCenterNotificationsByID(hexBytesIds)
if err != nil {
m.logger.Error("failed to get activity center notification", zap.Error(err))
} else if len(notifications) == 1 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I get this condition. Can there be more than one notification with the same ID?

Copy link
Member Author

@jrainville jrainville Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I used the wrong function. I should have used GetActivityCenterNotificationByID instead.
I'll fix


// Add a timeout to mark the backup syncing as failed after 1 minute and 30 seconds
time.AfterFunc(1*time.Minute+30*time.Second, func() {
if m.fetchingBackedUpDataCompleted {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it need a mutex or the risk of race condition is neglectable?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, will do

return response, nil
}

func (m *Messenger) startBackupFetchingTracking(response *MessengerResponse) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move it to messenger_backup_handler.go ?

Comment on lines +66 to +69
select {
case m.wakuBackedUpDataResponseChan <- response:
default:
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please elaborate why changed to non-blocking?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It blocked my test. To be honest, I don't fully know how this code works, I just discovered that if I change this code to this, it makes my test work and the other test that uses it still works, so it sounded fine.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all channel reads/writes operations must be wrapped into a select/case, with some cancellation options: Code smell #1: Accessing channels.

s.Require().Len(bob1.fetchingBackedUpDataProgress, 3)
s.Require().Equal(uint32(1), bob1.fetchingBackedUpDataProgress[SyncWakuSectionKeyContacts].TotalNumber)

// Parse a backup with a higher clock so reset the fetching
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering what will happen if the previous backup has completed before the next one kicks in?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question. I think in theory, it would mark the whole fetching as completed, so a false positive.

The old Nim logic had a minimum of 30 seconds before letting the user go to the next page, even if it said it received all data.

Maybe I should add that sort of timer too? Or maybe it doesn't matter, because the data will still get processed when the new backup comes in. Though the user would have a false sense of it being completed, so they could close the app too early.

protocol/messenger_backup_test.go Show resolved Hide resolved
@@ -9,6 +9,11 @@ type FetchingBackupedDataDetails struct {
TotalNumber uint32 `json:"totalNumber,omitempty"`
}

type FetchingBackedUpDataTracking struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not used in any kind of response. Not sure if it is a proper place for it (could be messenger's implementation detail).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. I put it with the other Backup type. I'm open to move it though

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, perhaps just put it in the messenger_backup.go or smth. Probably together with the BackupFetchStatus that I proposed

@osmaczko osmaczko requested a review from saledjenic January 27, 2025 17:32
@jrainville jrainville force-pushed the feat/new-onboarding-fetching-notification branch from 68eb5b5 to 43276bf Compare January 27, 2025 18:56
Comment on lines 201 to 205

fetchingBackedUpDataProgress map[string]wakusync.FetchingBackedUpDataTracking
lastKnownBackedUpMsgClock uint64
fetchingBackedUpDataCompleted bool
fetchingBackedUpDataCompletedMutex sync.Mutex
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but Messenger is already so huge, maybe we could compose these properties into a single BackupFetchStatus struct? It will also enable to remove the fetchingBackedUpData prefix in each field.

Comment on lines 101 to 120
m.fetchingBackedUpDataCompletedMutex.Lock()
defer m.fetchingBackedUpDataCompletedMutex.Unlock()

if !m.fetchingBackedUpDataCompleted {
evaluate := true
if m.lastKnownBackedUpMsgClock > message.Clock {
evaluate = false
} else if m.lastKnownBackedUpMsgClock < message.Clock {
// Reset the progress tracker because we have access to a more recent copy of the backup
m.lastKnownBackedUpMsgClock = message.Clock
m.fetchingBackedUpDataProgress = make(map[string]wakusync.FetchingBackedUpDataTracking)
for backupName, details := range response.FetchingBackedUpDataDetails() {
m.fetchingBackedUpDataProgress[backupName] = wakusync.FetchingBackedUpDataTracking{
LoadedItems: make(map[uint32]bool),
TotalNumber: details.TotalNumber,
}
}
if len(m.fetchingBackedUpDataProgress) == 0 {
evaluate = false
}
}

// Evaluate the progress of the backup
if evaluate {
// Set the new items before evaluating
for backupName, details := range response.FetchingBackedUpDataDetails() {
m.fetchingBackedUpDataProgress[backupName].LoadedItems[details.DataNumber] = true
}

receivedEverything := true
for _, tracker := range m.fetchingBackedUpDataProgress {
if len(tracker.LoadedItems)-1 < int(tracker.TotalNumber) {
receivedEverything = false
break
}
}

if receivedEverything {
m.fetchingBackedUpDataCompleted = true

// Update the AC notification and add it to the response
notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(backupSyncingNotificationID))
if err != nil {
errors = append(errors, err)
} else if notification != nil {
notification.UpdatedAt = m.GetCurrentTimeInMillis()
notification.Type = ActivityCenterNotificationTypeBackupSyncingSuccess
_, err = m.persistence.SaveActivityCenterNotification(notification, true)
if err != nil {
errors = append(errors, err)
} else {
state.Response.AddActivityCenterNotification(notification)
}
}
}
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be best to extract this to a function.
Then you can use early return pattern, avoid special flags like evaluate and receivedEverything and it will make the code flat without 7 layers of enclosure.

func (m *Messenger) updateBackupFetchProgress(message *protobuf.Backup, response *wakusync.WakuBackedUpDataResponse, state *ReceivedMessageState) error {
	m.fetchingBackedUpDataCompletedMutex.Lock()
	defer m.fetchingBackedUpDataCompletedMutex.Unlock()

	if m.fetchingBackedUpDataCompleted {
		return nil
	}

	if m.lastKnownBackedUpMsgClock > message.Clock {
		return nil
	}

	if m.lastKnownBackedUpMsgClock < message.Clock {
		// Reset the progress tracker because we have access to a more recent copy of the backup
		m.lastKnownBackedUpMsgClock = message.Clock
		m.fetchingBackedUpDataProgress = make(map[string]wakusync.FetchingBackedUpDataTracking)
		for backupName, details := range response.FetchingBackedUpDataDetails() {
			m.fetchingBackedUpDataProgress[backupName] = wakusync.FetchingBackedUpDataTracking{
				LoadedItems: make(map[uint32]bool),
				TotalNumber: details.TotalNumber,
			}
		}

		if len(m.fetchingBackedUpDataProgress) == 0 {
			return nil
		}
	}

	// Evaluate the progress of the backup

	// Set the new items before evaluating
	for backupName, details := range response.FetchingBackedUpDataDetails() {
		m.fetchingBackedUpDataProgress[backupName].LoadedItems[details.DataNumber] = true
	}

	for _, tracker := range m.fetchingBackedUpDataProgress {
		if len(tracker.LoadedItems)-1 < int(tracker.TotalNumber) {
			// have not received everything yet
			return nil
		}
	}

	m.fetchingBackedUpDataCompleted = true

	// Update the AC notification and add it to the response
	notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(backupSyncingNotificationID))
	if err != nil {
		return err
	}

	if notification == nil {
		return nil
	}

	notification.UpdatedAt = m.GetCurrentTimeInMillis()
	notification.Type = ActivityCenterNotificationTypeBackupSyncingSuccess
	_, err = m.persistence.SaveActivityCenterNotification(notification, true)
	if err != nil {
		return err
	}

	state.Response.AddActivityCenterNotification(notification)
	return nil
}

Then call it like this here:

Suggested change
m.fetchingBackedUpDataCompletedMutex.Lock()
defer m.fetchingBackedUpDataCompletedMutex.Unlock()
if !m.fetchingBackedUpDataCompleted {
evaluate := true
if m.lastKnownBackedUpMsgClock > message.Clock {
evaluate = false
} else if m.lastKnownBackedUpMsgClock < message.Clock {
// Reset the progress tracker because we have access to a more recent copy of the backup
m.lastKnownBackedUpMsgClock = message.Clock
m.fetchingBackedUpDataProgress = make(map[string]wakusync.FetchingBackedUpDataTracking)
for backupName, details := range response.FetchingBackedUpDataDetails() {
m.fetchingBackedUpDataProgress[backupName] = wakusync.FetchingBackedUpDataTracking{
LoadedItems: make(map[uint32]bool),
TotalNumber: details.TotalNumber,
}
}
if len(m.fetchingBackedUpDataProgress) == 0 {
evaluate = false
}
}
// Evaluate the progress of the backup
if evaluate {
// Set the new items before evaluating
for backupName, details := range response.FetchingBackedUpDataDetails() {
m.fetchingBackedUpDataProgress[backupName].LoadedItems[details.DataNumber] = true
}
receivedEverything := true
for _, tracker := range m.fetchingBackedUpDataProgress {
if len(tracker.LoadedItems)-1 < int(tracker.TotalNumber) {
receivedEverything = false
break
}
}
if receivedEverything {
m.fetchingBackedUpDataCompleted = true
// Update the AC notification and add it to the response
notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(backupSyncingNotificationID))
if err != nil {
errors = append(errors, err)
} else if notification != nil {
notification.UpdatedAt = m.GetCurrentTimeInMillis()
notification.Type = ActivityCenterNotificationTypeBackupSyncingSuccess
_, err = m.persistence.SaveActivityCenterNotification(notification, true)
if err != nil {
errors = append(errors, err)
} else {
state.Response.AddActivityCenterNotification(notification)
}
}
}
}
}
err = m.updateBackupFetchProgress(message, &response, state)
if err != nil {
errors = append(errors, err)
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way cleaner! I do prefer early returns, but not sure why I didn't think of just extracting it.

}

// Add a timeout to mark the backup syncing as failed after 1 minute and 30 seconds
time.AfterFunc(1*time.Minute+30*time.Second, func() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, there should be no timeout.
Backup fetching is done with a store node request(s). We know if any data was found, and we know if there was a timeout fetching, which id defined on the store node request level.
Do you think we can take that out here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good idea. I'm not sure how to hook to that though. I don't think we specifically call "fetchAllBackups". We seem to only set processBackedupMessages which tells the Messenger to handle those backup messages.

I'm not sure where we do the call to fetch all those backup messages. In theory, we should call that only on restore, but I don't see it using the fetchBackup flag, so maybe we have a small issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah now when I think of this, there's probably no simple way to do it in current architecture...

Comment on lines +66 to +69
select {
case m.wakuBackedUpDataResponseChan <- response:
default:
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, all channel reads/writes operations must be wrapped into a select/case, with some cancellation options: Code smell #1: Accessing channels.

@@ -9,6 +9,11 @@ type FetchingBackupedDataDetails struct {
TotalNumber uint32 `json:"totalNumber,omitempty"`
}

type FetchingBackedUpDataTracking struct {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, perhaps just put it in the messenger_backup.go or smth. Probably together with the BackupFetchStatus that I proposed

Needed for status-im/status-desktop#17028

When a user imports an old account, we start fetching the backups. Now, we show an activity center notification to let the user know, because the onboarding doesn't block during the fetching anymore, so it happens in the background.

After a timeout, the notification turns into a failure state (full or partial). The user can then restart the fetching.

I added a test to validate the logic of calculating if the fetching was a success. That logic used to be in Nim.
@jrainville jrainville force-pushed the feat/new-onboarding-fetching-notification branch from 43276bf to e4aad76 Compare January 28, 2025 18:32
Copy link
Member Author

@jrainville jrainville left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@igor-sirotin thanks for the review. I addressed your comments.
I'm not sure how to hook on the mailserver one though

Comment on lines 101 to 120
m.fetchingBackedUpDataCompletedMutex.Lock()
defer m.fetchingBackedUpDataCompletedMutex.Unlock()

if !m.fetchingBackedUpDataCompleted {
evaluate := true
if m.lastKnownBackedUpMsgClock > message.Clock {
evaluate = false
} else if m.lastKnownBackedUpMsgClock < message.Clock {
// Reset the progress tracker because we have access to a more recent copy of the backup
m.lastKnownBackedUpMsgClock = message.Clock
m.fetchingBackedUpDataProgress = make(map[string]wakusync.FetchingBackedUpDataTracking)
for backupName, details := range response.FetchingBackedUpDataDetails() {
m.fetchingBackedUpDataProgress[backupName] = wakusync.FetchingBackedUpDataTracking{
LoadedItems: make(map[uint32]bool),
TotalNumber: details.TotalNumber,
}
}
if len(m.fetchingBackedUpDataProgress) == 0 {
evaluate = false
}
}

// Evaluate the progress of the backup
if evaluate {
// Set the new items before evaluating
for backupName, details := range response.FetchingBackedUpDataDetails() {
m.fetchingBackedUpDataProgress[backupName].LoadedItems[details.DataNumber] = true
}

receivedEverything := true
for _, tracker := range m.fetchingBackedUpDataProgress {
if len(tracker.LoadedItems)-1 < int(tracker.TotalNumber) {
receivedEverything = false
break
}
}

if receivedEverything {
m.fetchingBackedUpDataCompleted = true

// Update the AC notification and add it to the response
notification, err := m.persistence.GetActivityCenterNotificationByID(types.FromHex(backupSyncingNotificationID))
if err != nil {
errors = append(errors, err)
} else if notification != nil {
notification.UpdatedAt = m.GetCurrentTimeInMillis()
notification.Type = ActivityCenterNotificationTypeBackupSyncingSuccess
_, err = m.persistence.SaveActivityCenterNotification(notification, true)
if err != nil {
errors = append(errors, err)
} else {
state.Response.AddActivityCenterNotification(notification)
}
}
}
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice way cleaner! I do prefer early returns, but not sure why I didn't think of just extracting it.

}

// Add a timeout to mark the backup syncing as failed after 1 minute and 30 seconds
time.AfterFunc(1*time.Minute+30*time.Second, func() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a good idea. I'm not sure how to hook to that though. I don't think we specifically call "fetchAllBackups". We seem to only set processBackedupMessages which tells the Messenger to handle those backup messages.

I'm not sure where we do the call to fetch all those backup messages. In theory, we should call that only on restore, but I don't see it using the fetchBackup flag, so maybe we have a small issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants