Skip to content

Commit

Permalink
Merge pull request #41 from sideshow/feature-thread-id
Browse files Browse the repository at this point in the history
Add iOS10 thread-id to notification
  • Loading branch information
sideshow authored Sep 24, 2016
2 parents 0ef66aa + 94a3a3c commit 741a20d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
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

0 comments on commit 741a20d

Please sign in to comment.