Skip to content

Commit

Permalink
[live-activity]: fit in Events in payload in aps
Browse files Browse the repository at this point in the history
  • Loading branch information
GonzaloAvilez committed Jul 7, 2023
1 parent 5c7f708 commit 00b4bcf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions payload/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type aps struct {
ThreadID string `json:"thread-id,omitempty"`
URLArgs []string `json:"url-args,omitempty"`
StaleDate int64 `json:"stale-date,omitempty"`
Event string `json:"event,omitempty"`
Events string `json:"event,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
ContentState map[string]interface{} `json:"content-state,omitempty"`
}
Expand Down Expand Up @@ -394,13 +394,13 @@ func (p *Payload) StaleDate(staledate int64) *Payload {
return p
}

// Event defines the value event for the aps payload
// Events defines the value event for the aps payload
// Describes whether you update or end an ongoing Live Activity
// ref: https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/generating_a_remote_notification
//
// {"aps":{"event":"update"}}
func (p *Payload) Event(event string) *Payload {
p.aps().Event = event
// {"aps":{"events":"update"}}
func (p *Payload) Events(event string) *Payload {
p.aps().Events = event
return p
}

Expand Down
6 changes: 3 additions & 3 deletions payload/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func TestCombined(t *testing.T) {
}

func TestEvent(t *testing.T) {
payload := NewPayload().Event("update")
payload := NewPayload().Events("update")
data, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"event":"update"}}`, string(data))
}
Expand All @@ -261,13 +261,13 @@ func TestContentState(t *testing.T) {
}

func TestLiveActivityAttributes(t *testing.T) {
payload := NewPayload().Event("update").Timestamp(1168364460).StaleDate(12324243).ContentState(D{"item_id": 3, "availability": 1, "volume": 4.5, "item_status": "ACCEPTED"})
payload := NewPayload().Events("update").Timestamp(1168364460).StaleDate(12324243).ContentState(D{"item_id": 3, "availability": 1, "volume": 4.5, "item_status": "ACCEPTED"})
data, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"stale-date":12324243,"event":"update","timestamp":1168364460,"content-state":{"availability":1,"item_id":3,"item_status":"ACCEPTED","volume":4.5}}}`, string(data))
}

func TestLiveActivityAttributesMixedWithAlert(t *testing.T) {
payload := NewPayload().Alert("hello").Badge(1).Sound("Default.caf").InterruptionLevel(InterruptionLevelActive).RelevanceScore(0.1).Event("update").Timestamp(1168364460).StaleDate(12324243).ContentState(D{"item_id": 3, "availability": 1, "volume": 4.5, "item_status": "ACCEPTED"})
payload := NewPayload().Alert("hello").Badge(1).Sound("Default.caf").InterruptionLevel(InterruptionLevelActive).RelevanceScore(0.1).Events("update").Timestamp(1168364460).StaleDate(12324243).ContentState(D{"item_id": 3, "availability": 1, "volume": 4.5, "item_status": "ACCEPTED"})
data, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"alert":"hello","badge":1,"interruption-level":"active","relevance-score":0.1,"sound":"Default.caf","stale-date":12324243,"event":"update","timestamp":1168364460,"content-state":{"availability":1,"item_id":3,"item_status":"ACCEPTED","volume":4.5}}}`, string(data))
}

0 comments on commit 00b4bcf

Please sign in to comment.