mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-11 05:06:51 +00:00
fix(GODT-3129): Bad Event during after address order change
When syncing an account, if the user creates a new address and then changes it to be the default address in combined address mode we need to update the connector maps so that the new primary address ID can be found in that map. Includes https://github.com/ProtonMail/go-proton-api/pull/130
This commit is contained in:
@ -274,6 +274,10 @@ func (s *Service) HandleRefreshEvent(ctx context.Context, _ proton.RefreshFlag)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.rebuildConnectors(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.syncStateProvider.ClearSyncStatus(ctx); err != nil {
|
||||
return fmt.Errorf("failed to clear sync status:%w", err)
|
||||
}
|
||||
@ -292,6 +296,7 @@ func (s *Service) HandleUserEvent(_ context.Context, user *proton.User) error {
|
||||
|
||||
return s.identityState.Write(func(identity *useridentity.State) error {
|
||||
identity.OnUserEvent(*user)
|
||||
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@ -24,12 +24,18 @@ import (
|
||||
"github.com/ProtonMail/go-proton-api"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/services/useridentity"
|
||||
"github.com/ProtonMail/proton-bridge/v3/internal/usertypes"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func (s *Service) HandleAddressEvents(ctx context.Context, events []proton.AddressEvent) error {
|
||||
s.log.Debug("handling address event")
|
||||
|
||||
if s.addressMode == usertypes.AddressModeCombined {
|
||||
oldPrimaryAddr, err := s.identityState.GetPrimaryAddress()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get primary addr: %w", err)
|
||||
}
|
||||
|
||||
if err := s.identityState.Write(func(identity *useridentity.State) error {
|
||||
identity.OnAddressEvents(events)
|
||||
return nil
|
||||
@ -38,6 +44,28 @@ func (s *Service) HandleAddressEvents(ctx context.Context, events []proton.Addre
|
||||
return err
|
||||
}
|
||||
|
||||
newPrimaryAddr, err := s.identityState.GetPrimaryAddress()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get primary addr after update: %w", err)
|
||||
}
|
||||
|
||||
if oldPrimaryAddr.ID == newPrimaryAddr.ID {
|
||||
return nil
|
||||
}
|
||||
|
||||
connector, ok := s.connectors[oldPrimaryAddr.ID]
|
||||
if !ok {
|
||||
return fmt.Errorf("could not find old primary addr conncetor after default address change")
|
||||
}
|
||||
|
||||
s.connectors[newPrimaryAddr.ID] = connector
|
||||
delete(s.connectors, oldPrimaryAddr.ID)
|
||||
|
||||
s.log.WithFields(logrus.Fields{
|
||||
"old": oldPrimaryAddr.Email,
|
||||
"new": newPrimaryAddr.Email,
|
||||
}).Debug("Primary address changed")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user