forked from Silverfish/proton-bridge
fix(GODT-2327): Clear update channels whenever clearing sync status
This commit is contained in:
@ -113,11 +113,8 @@ func (user *User) handleRefreshEvent(ctx context.Context, refresh proton.Refresh
|
|||||||
user.apiAddrs = groupBy(apiAddrs, func(addr proton.Address) string { return addr.ID })
|
user.apiAddrs = groupBy(apiAddrs, func(addr proton.Address) string { return addr.ID })
|
||||||
user.apiLabels = groupBy(apiLabels, func(label proton.Label) string { return label.ID })
|
user.apiLabels = groupBy(apiLabels, func(label proton.Label) string { return label.ID })
|
||||||
|
|
||||||
// Reinitialize the update channels.
|
|
||||||
user.initUpdateCh(user.vault.AddressMode())
|
|
||||||
|
|
||||||
// Clear sync status; we want to sync everything again.
|
// Clear sync status; we want to sync everything again.
|
||||||
if err := user.vault.ClearSyncStatus(); err != nil {
|
if err := user.clearSyncStatus(); err != nil {
|
||||||
return fmt.Errorf("failed to clear sync status: %w", err)
|
return fmt.Errorf("failed to clear sync status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -274,18 +274,16 @@ func (user *User) SetAddressMode(_ context.Context, mode vault.AddressMode) erro
|
|||||||
defer user.goSync()
|
defer user.goSync()
|
||||||
|
|
||||||
return safe.LockRet(func() error {
|
return safe.LockRet(func() error {
|
||||||
user.initUpdateCh(mode)
|
|
||||||
|
|
||||||
if err := user.vault.SetAddressMode(mode); err != nil {
|
if err := user.vault.SetAddressMode(mode); err != nil {
|
||||||
return fmt.Errorf("failed to set address mode: %w", err)
|
return fmt.Errorf("failed to set address mode: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user.vault.ClearSyncStatus(); err != nil {
|
if err := user.clearSyncStatus(); err != nil {
|
||||||
return fmt.Errorf("failed to clear sync status: %w", err)
|
return fmt.Errorf("failed to clear sync status: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}, user.apiAddrsLock, user.updateChLock)
|
}, user.eventLock, user.apiAddrsLock, user.updateChLock)
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetShowAllMail sets whether to show the All Mail mailbox.
|
// SetShowAllMail sets whether to show the All Mail mailbox.
|
||||||
@ -477,16 +475,25 @@ func (user *User) ClearSyncStatus() error {
|
|||||||
user.log.Info("Clearing sync status")
|
user.log.Info("Clearing sync status")
|
||||||
|
|
||||||
return safe.LockRet(func() error {
|
return safe.LockRet(func() error {
|
||||||
user.initUpdateCh(user.vault.AddressMode())
|
return user.clearSyncStatus()
|
||||||
|
|
||||||
if err := user.vault.ClearSyncStatus(); err != nil {
|
|
||||||
return fmt.Errorf("failed to clear sync status: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}, user.eventLock, user.apiAddrsLock, user.updateChLock)
|
}, user.eventLock, user.apiAddrsLock, user.updateChLock)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clearSyncStatus clears the sync status of the user.
|
||||||
|
// This also drops any updates in the update channel(s).
|
||||||
|
// It is assumed that the eventLock, apiAddrsLock and updateChLock are already locked.
|
||||||
|
func (user *User) clearSyncStatus() error {
|
||||||
|
user.log.Info("Clearing sync status")
|
||||||
|
|
||||||
|
user.initUpdateCh(user.vault.AddressMode())
|
||||||
|
|
||||||
|
if err := user.vault.ClearSyncStatus(); err != nil {
|
||||||
|
return fmt.Errorf("failed to clear sync status: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// Logout logs the user out from the API.
|
// Logout logs the user out from the API.
|
||||||
func (user *User) Logout(ctx context.Context, withAPI bool) error {
|
func (user *User) Logout(ctx context.Context, withAPI bool) error {
|
||||||
user.log.WithField("withAPI", withAPI).Info("Logging out user")
|
user.log.WithField("withAPI", withAPI).Info("Logging out user")
|
||||||
|
|||||||
Reference in New Issue
Block a user