From d81124d45431953dd42d7e9ce61e57a304ee0495 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 2 Oct 2023 21:30:47 -0400 Subject: [PATCH] Ensure Updated field will be omitted when nil or zero --- activitystreams/activity.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/activitystreams/activity.go b/activitystreams/activity.go index cfdab0d..4d42a63 100644 --- a/activitystreams/activity.go +++ b/activitystreams/activity.go @@ -17,12 +17,12 @@ var Extensions = map[string]string{} // process of occurring, or may occur in the future. type Activity struct { BaseObject - Actor string `json:"actor"` - Published time.Time `json:"published,omitempty"` - Updated time.Time `json:"updated,omitempty"` - To []string `json:"to,omitempty"` - CC []string `json:"cc,omitempty"` - Object *Object `json:"object"` + Actor string `json:"actor"` + Published time.Time `json:"published,omitempty"` + Updated *time.Time `json:"updated,omitempty"` + To []string `json:"to,omitempty"` + CC []string `json:"cc,omitempty"` + Object *Object `json:"object"` } type FollowActivity struct { @@ -68,7 +68,9 @@ func NewUpdateActivity(o *Object) *Activity { Actor: o.AttributedTo, Object: o, Published: o.Published, - Updated: o.Updated, + } + if o.Updated != nil && !o.Updated.IsZero() { + a.Updated = o.Updated } return &a } @@ -109,7 +111,7 @@ func NewFollowActivity(actorIRI, followeeIRI string) *FollowActivity { type Object struct { BaseObject Published time.Time `json:"published,omitempty"` - Updated time.Time `json:"updated,omitempty"` + Updated *time.Time `json:"updated,omitempty"` Summary *string `json:"summary,omitempty"` InReplyTo *string `json:"inReplyTo,omitempty"` URL string `json:"url"`