Skip to content

Commit 548a22d

Browse files
committed
Limit Live Activity support to LiveActivityToken field only
As per review feedback, removed all extra Live Activity fields from Aps struct: - Removed StaleDate, ContentState, Timestamp, Event, DismissalDate, AttributesType, and Attributes fields - Removed LiveActivityEvent type and constants - Updated tests to only test LiveActivityToken field - Kept only the essential LiveActivityToken field in APNSConfig as requested
1 parent d676fb8 commit 548a22d

File tree

2 files changed

+0
-106
lines changed

2 files changed

+0
-106
lines changed

messaging/messaging.go

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,6 @@ type Aps struct {
686686
MutableContent bool `json:"-"`
687687
Category string `json:"category,omitempty"`
688688
ThreadID string `json:"thread-id,omitempty"`
689-
StaleDate *time.Time `json:"-"`
690-
ContentState map[string]interface{} `json:"content-state,omitempty"`
691-
Timestamp *time.Time `json:"-"`
692-
Event LiveActivityEvent `json:"-"`
693-
DismissalDate *time.Time `json:"-"`
694-
AttributesType string `json:"attributes-type,omitempty"`
695-
Attributes map[string]interface{} `json:"attributes,omitempty"`
696689
CustomData map[string]interface{} `json:"-"`
697690
}
698691

@@ -724,32 +717,6 @@ func (a *Aps) standardFields() map[string]interface{} {
724717
if a.ThreadID != "" {
725718
m["thread-id"] = a.ThreadID
726719
}
727-
if a.StaleDate != nil {
728-
m["stale-date"] = a.StaleDate.Unix()
729-
}
730-
if a.ContentState != nil {
731-
m["content-state"] = a.ContentState
732-
}
733-
if a.Timestamp != nil {
734-
m["timestamp"] = a.Timestamp.Unix()
735-
}
736-
if a.Event != liveActivityEventUnspecified {
737-
events := map[LiveActivityEvent]string{
738-
LiveActivityEventStart: "start",
739-
LiveActivityEventUpdate: "update",
740-
LiveActivityEventEnd: "end",
741-
}
742-
m["event"] = events[a.Event]
743-
}
744-
if a.DismissalDate != nil {
745-
m["dismissal-date"] = a.DismissalDate.Unix()
746-
}
747-
if a.AttributesType != "" {
748-
m["attributes-type"] = a.AttributesType
749-
}
750-
if a.Attributes != nil {
751-
m["attributes"] = a.Attributes
752-
}
753720
return m
754721
}
755722

@@ -770,10 +737,6 @@ func (a *Aps) UnmarshalJSON(b []byte) error {
770737
SoundObject *json.RawMessage `json:"sound,omitempty"`
771738
ContentAvailableInt int `json:"content-available,omitempty"`
772739
MutableContentInt int `json:"mutable-content,omitempty"`
773-
StaleDate *int64 `json:"stale-date,omitempty"`
774-
Timestamp *int64 `json:"timestamp,omitempty"`
775-
Event string `json:"event,omitempty"`
776-
DismissalDate *int64 `json:"dismissal-date,omitempty"`
777740
*apsInternal
778741
}{
779742
apsInternal: (*apsInternal)(a),
@@ -799,30 +762,6 @@ func (a *Aps) UnmarshalJSON(b []byte) error {
799762
}
800763
}
801764
}
802-
if temp.StaleDate != nil {
803-
staleDate := time.Unix(*temp.StaleDate, 0)
804-
a.StaleDate = &staleDate
805-
}
806-
if temp.Timestamp != nil {
807-
timestamp := time.Unix(*temp.Timestamp, 0)
808-
a.Timestamp = &timestamp
809-
}
810-
if temp.Event != "" {
811-
events := map[string]LiveActivityEvent{
812-
"start": LiveActivityEventStart,
813-
"update": LiveActivityEventUpdate,
814-
"end": LiveActivityEventEnd,
815-
}
816-
if event, ok := events[temp.Event]; ok {
817-
a.Event = event
818-
} else {
819-
return fmt.Errorf("unknown event value: %q", temp.Event)
820-
}
821-
}
822-
if temp.DismissalDate != nil {
823-
dismissalDate := time.Unix(*temp.DismissalDate, 0)
824-
a.DismissalDate = &dismissalDate
825-
}
826765

827766
allFields := make(map[string]interface{})
828767
if err := json.Unmarshal(b, &allFields); err != nil {
@@ -837,22 +776,6 @@ func (a *Aps) UnmarshalJSON(b []byte) error {
837776
return nil
838777
}
839778

840-
// LiveActivityEvent represents an event type for Live Activity in push notification payloads.
841-
type LiveActivityEvent int
842-
843-
const (
844-
liveActivityEventUnspecified LiveActivityEvent = iota
845-
846-
// LiveActivityEventStart starts a Live Activity.
847-
LiveActivityEventStart
848-
849-
// LiveActivityEventUpdate updates a Live Activity.
850-
LiveActivityEventUpdate
851-
852-
// LiveActivityEventEnd ends a Live Activity.
853-
LiveActivityEventEnd
854-
)
855-
856779
// CriticalSound is the sound payload that can be included in an Aps.
857780
type CriticalSound struct {
858781
Critical bool `json:"-"`

messaging/messaging_test.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ var (
4848
badgeZero = 0
4949
timestampMillis = int64(12345)
5050
timestamp = time.Unix(0, 1546304523123*1000000).UTC()
51-
unixTime = time.Unix(1546304, 0)
5251
)
5352

5453
var validMessages = []struct {
@@ -595,40 +594,12 @@ var validMessages = []struct {
595594
Token: "test-token",
596595
APNS: &APNSConfig{
597596
LiveActivityToken: "live-activity-token",
598-
Payload: &APNSPayload{
599-
Aps: &Aps{
600-
StaleDate: &unixTime,
601-
ContentState: map[string]interface{}{
602-
"s1": "v",
603-
"s2": float64(1),
604-
},
605-
Timestamp: &unixTime,
606-
Event: LiveActivityEventStart,
607-
DismissalDate: &unixTime,
608-
AttributesType: "TestAttributes",
609-
Attributes: map[string]interface{}{
610-
"a1": "v",
611-
"a2": float64(1),
612-
},
613-
},
614-
},
615597
},
616598
},
617599
want: map[string]interface{}{
618600
"token": "test-token",
619601
"apns": map[string]interface{}{
620602
"live_activity_token": "live-activity-token",
621-
"payload": map[string]interface{}{
622-
"aps": map[string]interface{}{
623-
"stale-date": float64(unixTime.Unix()),
624-
"content-state": map[string]interface{}{"s1": "v", "s2": float64(1)},
625-
"timestamp": float64(unixTime.Unix()),
626-
"event": "start",
627-
"dismissal-date": float64(unixTime.Unix()),
628-
"attributes-type": "TestAttributes",
629-
"attributes": map[string]interface{}{"a1": "v", "a2": float64(1)},
630-
},
631-
},
632603
},
633604
},
634605
},

0 commit comments

Comments
 (0)