From fe774899d318d1906cad4e89aed27ce30cabd98a Mon Sep 17 00:00:00 2001 From: Till Faelligen <2353100+S7evinK@users.noreply.github.com> Date: Tue, 4 Oct 2022 14:05:41 +0200 Subject: [PATCH] Add MarshalJSON for LeaveResponse --- syncapi/types/types.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/syncapi/types/types.go b/syncapi/types/types.go index af1237f67..ad0230810 100644 --- a/syncapi/types/types.go +++ b/syncapi/types/types.go @@ -540,6 +540,18 @@ type LeaveResponse struct { 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. func NewLeaveResponse() *LeaveResponse { res := LeaveResponse{