refactor(GODT-2508): Add CreateAddressAsUpdate

Allow the server to issue and update event rather than create event for
when a new address is created.
This commit is contained in:
Leander Beernaert
2023-03-24 15:08:38 +01:00
committed by LBeernaertProton
parent 83e98cb35c
commit 71c20587e0
2 changed files with 20 additions and 1 deletions

View File

@@ -203,6 +203,14 @@ func (b *Backend) RemoveUserKey(userID, keyID string) error {
}
func (b *Backend) CreateAddress(userID, email string, password []byte, withKey bool, status proton.AddressStatus) (string, error) {
return b.createAddress(userID, email, password, withKey, status, false)
}
func (b *Backend) CreateAddressAsUpdate(userID, email string, password []byte, withKey bool, status proton.AddressStatus) (string, error) {
return b.createAddress(userID, email, password, withKey, status, true)
}
func (b *Backend) createAddress(userID, email string, password []byte, withKey bool, status proton.AddressStatus, issueUpdateInsteadOfCreate bool) (string, error) {
return withAcc(b, userID, func(acc *account) (string, error) {
var keys []key
@@ -250,7 +258,14 @@ func (b *Backend) CreateAddress(userID, email string, password []byte, withKey b
keys: keys,
}
updateID, err := b.newUpdate(&addressCreated{addressID: addressID})
var update update
if issueUpdateInsteadOfCreate {
update = &addressUpdated{addressID: addressID}
} else {
update = &addressCreated{addressID: addressID}
}
updateID, err := b.newUpdate(update)
if err != nil {
return "", err
}

View File

@@ -151,6 +151,10 @@ func (s *Server) CreateAddress(userID, email string, password []byte) (string, e
return s.b.CreateAddress(userID, email, password, true, proton.AddressStatusEnabled)
}
func (s *Server) CreateAddressAsUpdate(userID, email string, password []byte) (string, error) {
return s.b.CreateAddressAsUpdate(userID, email, password, true, proton.AddressStatusEnabled)
}
func (s *Server) RemoveAddress(userID, addrID string) error {
return s.b.RemoveAddress(userID, addrID)
}