mirror of
https://github.com/ProtonMail/go-proton-api.git
synced 2025-12-23 23:57:50 -05:00
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:
committed by
LBeernaertProton
parent
83e98cb35c
commit
71c20587e0
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user