diff --git a/pkg/pmapi/events.go b/pkg/pmapi/events.go index f2ae6273..38b924f0 100644 --- a/pkg/pmapi/events.go +++ b/pkg/pmapi/events.go @@ -45,6 +45,9 @@ type Event struct { Addresses []*EventAddress // Messages to show to the user. Notices []string + + // Update of used user space + UsedSpace *int64 } // EventAction is the action that created a change. @@ -184,6 +187,21 @@ func (c *client) getEvent(ctx context.Context, eventID string, numberOfMergedEve return nil, err } + // API notifies about used space two ways: + // - by `event.User.UsedSpace` + // - by `event.UsedSpace` + // + // Because event merging is implemented for User object we copy the + // value from event.UsedSpace to event.User.UsedSpace and continue with + // user. + if event.UsedSpace != nil { + if event.User == nil { + event.User = &User{UsedSpace: event.UsedSpace} + } else { + event.User.UsedSpace = event.UsedSpace + } + } + if event.More && numberOfMergedEvents < maxNumberOfMergedEvents { nextEvent, err := c.getEvent(ctx, event.EventID, numberOfMergedEvents+1) if err != nil { diff --git a/pkg/pmapi/events_test.go b/pkg/pmapi/events_test.go index f0e7eba0..d32d702f 100644 --- a/pkg/pmapi/events_test.go +++ b/pkg/pmapi/events_test.go @@ -420,7 +420,6 @@ const ( "Unread": 0 } ], - "UsedSpace": 7552905, "Notices": ["Server will be down in 2min because of a NSA attack"], "Code": 1000 } @@ -465,7 +464,7 @@ const ( "User": { "ID": "userID1", "Name": "user", - "UsedSpace": 12345, + "UsedSpace": 444, "MaxSpace": 12345678 }, "Addresses": [ @@ -478,6 +477,7 @@ const ( } } ], + "UsedSpace": 12345, "Notices": ["Server will be down in 2min because of a NSA attack"] } `