Add MarshalJSON for LeaveResponse

This commit is contained in:
Till Faelligen 2022-10-04 14:05:41 +02:00
parent d5b5708329
commit fe774899d3
No known key found for this signature in database
GPG key ID: 3DF82D8AB9211D4E

View file

@ -540,6 +540,18 @@ type LeaveResponse struct {
Timeline *Timeline `json:"timeline,omitempty"` Timeline *Timeline `json:"timeline,omitempty"`
} }
func (lr LeaveResponse) MarshalJSON() ([]byte, error) {
type alias LeaveResponse
a := alias(lr)
if lr.State != nil && len(lr.State.Events) == 0 {
a.State = nil
}
if lr.Timeline != nil && len(lr.Timeline.Events) == 0 {
a.Timeline = nil
}
return json.Marshal(a)
}
// NewLeaveResponse creates an empty response with initialised arrays. // NewLeaveResponse creates an empty response with initialised arrays.
func NewLeaveResponse() *LeaveResponse { func NewLeaveResponse() *LeaveResponse {
res := LeaveResponse{ res := LeaveResponse{