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

Add iOS10 thread-id to notification #41

Merged
merged 1 commit into from
Sep 24, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func setHeaders(r *http.Request, n *Notification) {
if n.CollapseID != "" {
r.Header.Set("apns-collapse-id", n.CollapseID)
}
if n.ThreadID != "" {
r.Header.Set("thread-id", n.ThreadID)
}
if n.Priority > 0 {
r.Header.Set("apns-priority", fmt.Sprintf("%v", n.Priority))
}
Expand Down
3 changes: 3 additions & 0 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ func TestDefaultHeaders(t *testing.T) {
assert.Equal(t, "", r.Header.Get("apns-priority"))
assert.Equal(t, "", r.Header.Get("apns-topic"))
assert.Equal(t, "", r.Header.Get("apns-expiration"))
assert.Equal(t, "", r.Header.Get("thread-id"))
}))
defer server.Close()
_, err := mockClient(server.URL).Push(n)
Expand All @@ -132,13 +133,15 @@ func TestHeaders(t *testing.T) {
n := mockNotification()
n.ApnsID = "84DB694F-464F-49BD-960A-D6DB028335C9"
n.CollapseID = "game1.start.identifier"
n.ThreadID = "game1.thread.1"
n.Topic = "com.testapp"
n.Priority = 10
n.Expiration = time.Now()
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
assert.Equal(t, n.ApnsID, r.Header.Get("apns-id"))
assert.Equal(t, n.CollapseID, r.Header.Get("apns-collapse-id"))
assert.Equal(t, "10", r.Header.Get("apns-priority"))
assert.Equal(t, n.ThreadID, r.Header.Get("thread-id"))
assert.Equal(t, n.Topic, r.Header.Get("apns-topic"))
assert.Equal(t, fmt.Sprintf("%v", n.Expiration.Unix()), r.Header.Get("apns-expiration"))
}))
Expand Down
9 changes: 7 additions & 2 deletions notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ type Notification struct {
// response.
ApnsID string

// A string which allows a notification to be replaced by a new notification
// with the same CollapseID.
// A string which allows multiple notifications with the same collapse identifier
// to be displayed to the user as a single notification. The value should not
// exceed 64 bytes.
CollapseID string

// A string containing hexadecimal bytes of the device token for the target device.
Expand All @@ -47,6 +48,10 @@ type Notification struct {
// server uses the certificate’s Subject as the default topic.
Topic string

// An optional app specific identifier. When displaying notifications, the
// system visually groups notifications with the same thread identifier together.
ThreadID string

// An optional time at which the notification is no longer valid and can be
// discarded by APNs. If this value is in the past, APNs treats the
// notification as if it expires immediately and does not store the
Expand Down