Omit empty fields instead

This commit is contained in:
Neil Alexander 2020-04-22 17:49:09 +01:00
parent 68b6524e14
commit 8123a76117

View file

@ -247,8 +247,8 @@ func NewJoinResponse() *JoinResponse {
// InviteResponse represents a /sync response for a room which is under the 'invite' key. // InviteResponse represents a /sync response for a room which is under the 'invite' key.
type InviteResponse struct { type InviteResponse struct {
InviteState struct { InviteState struct {
Events json.RawMessage `json:"events"` Events json.RawMessage `json:"events,omitempty"`
} `json:"invite_state"` } `json:"invite_state,omitempty"`
} }
// NewInviteResponse creates an empty response with initialised arrays. // NewInviteResponse creates an empty response with initialised arrays.
@ -258,10 +258,9 @@ func NewInviteResponse(ev gomatrixserverlib.HeaderedEvent) *InviteResponse {
InviteRoomState json.RawMessage `json:"invite_room_state"` InviteRoomState json.RawMessage `json:"invite_room_state"`
} }
if err := json.Unmarshal(ev.Unsigned(), &unsigned); err == nil { if err := json.Unmarshal(ev.Unsigned(), &unsigned); err == nil {
if len(unsigned.InviteRoomState) > 0 {
res.InviteState.Events = unsigned.InviteRoomState res.InviteState.Events = unsigned.InviteRoomState
} }
if len(res.InviteState.Events) == 0 || res.InviteState.Events == nil {
res.InviteState.Events = json.RawMessage{'[', ']'}
} }
return &res return &res
} }