From f1adb1492eed7646f3319cf955ee96567c1786bb Mon Sep 17 00:00:00 2001 From: Leander Beernaert Date: Wed, 27 Sep 2023 11:11:10 +0200 Subject: [PATCH] feat(GODT-2948): Add used space per product to user info --- server/backend/api.go | 23 ++++++++++++++++++++++- user_types.go | 16 +++++++++++++--- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/server/backend/api.go b/server/backend/api.go index 17101c8..63c0d4f 100644 --- a/server/backend/api.go +++ b/server/backend/api.go @@ -17,7 +17,28 @@ import ( func (b *Backend) GetUser(userID string) (proton.User, error) { return withAcc(b, userID, func(acc *account) (proton.User, error) { - return acc.toUser(), nil + return withMessages(b, func(m map[string]*message) (proton.User, error) { + return withAtts(b, func(attachments map[string]*attachment) (proton.User, error) { + user := acc.toUser() + + var messageBytes uint64 + for _, v := range m { + if _, ok := acc.addresses[v.addrID]; ok { + messageBytes += uint64(len(v.armBody)) + } + + for _, a := range v.attIDs { + if attach, ok := attachments[a]; ok { + messageBytes += uint64(len(b.attData[attach.attDataID])) + } + } + } + + user.ProductUsedSpace.Mail = messageBytes + + return user, nil + }) + }) }) } diff --git a/user_types.go b/user_types.go index 6960f71..61af703 100644 --- a/user_types.go +++ b/user_types.go @@ -7,12 +7,14 @@ type User struct { Email string Keys Keys - UsedSpace int - MaxSpace int - MaxUpload int + UsedSpace uint64 + MaxSpace uint64 + MaxUpload uint64 Credit int Currency string + + ProductUsedSpace ProductUsedSpace } type DeleteUserReq struct { @@ -20,3 +22,11 @@ type DeleteUserReq struct { Feedback string Email string } + +type ProductUsedSpace struct { + Calendar uint64 + Contact uint64 + Drive uint64 + Mail uint64 + Pass uint64 +}