Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CH-5411] Add support for Attributes/AttributesType for push-to-start live activities #7

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions payload/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ type aps struct {
StaleDate int64 `json:"stale-date,omitempty"`
Event ELiveActivityEvent `json:"event,omitempty"`
Timestamp int64 `json:"timestamp,omitempty"`
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

timestamp already supported

AttributesType string `json:"attributes-type,omitempty"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
}

type alert struct {
Expand Down Expand Up @@ -142,6 +144,24 @@ func (p *Payload) SetTimestamp(timestamp int64) *Payload {
return p
}

// SetAttributesType sets the aps attributes-type field on the payload.
// This is used for push-to-start live activities
//
// {"aps":{"attributes-type": attributesType }}`
func (p *Payload) SetAttributesType(attributesType string) *Payload {
p.aps().AttributesType = attributesType
return p
}

// SetAttributes sets the aps attributes field on the payload.
// This is used for push-to-start live activities
//
// {"aps":{"attributes": attributes }}`
func (p *Payload) SetAttributes(attributes map[string]interface{}) *Payload {
p.aps().Attributes = attributes
return p
}

// Badge sets the aps badge on the payload.
// This will display a numeric badge on the app icon.
//
Expand Down
21 changes: 21 additions & 0 deletions payload/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,27 @@ func TestTimestamp(t *testing.T) {
assert.Equal(t, `{"aps":{"timestamp":1674821640}}`, string(b))
}

func TestAttributesType(t *testing.T) {
attributesType := "AdventureAttributes"
payload := NewPayload().SetAttributesType(attributesType)
b, _ := json.Marshal(payload)
assert.Equal(t, `{"aps":{"attributes-type":"AdventureAttributes"}}`, string(b))
}

func TestAttributes(t *testing.T) {
attributes := map[string]interface{}{
"currentHealthLevel": 100,
"eventDescription": "Adventure has begun!",
}
payload := NewPayload().SetAttributes(attributes)
b, _ := json.Marshal(payload)
assert.Equal(
t,
`{"aps":{"attributes":{"currentHealthLevel":100,"eventDescription":"Adventure has begun!"}}}`,
string(b),
)
}

func TestMdm(t *testing.T) {
payload := NewPayload().Mdm("996ac527-9993-4a0a-8528-60b2b3c2f52b")
b, _ := json.Marshal(payload)
Expand Down
Loading