diff --git a/gorush/notification.go b/gorush/notification.go index a0e514f..2861c6e 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -7,6 +7,7 @@ import ( apns "github.com/sideshow/apns2" "github.com/sideshow/apns2/certificate" "github.com/sideshow/apns2/payload" + "time" ) type ExtendJSON struct { @@ -59,14 +60,15 @@ type RequestPushNotification struct { Notification gcm.Notification `json:"notification,omitempty"` // iOS - ApnsID string `json:"apns_id,omitempty"` - Topic string `json:"topic,omitempty"` - Badge int `json:"badge,omitempty"` - Sound string `json:"sound,omitempty"` - Category string `json:"category,omitempty"` - URLArgs []string `json:"url-args,omitempty"` - Extend []ExtendJSON `json:"extend,omitempty"` - Alert Alert `json:"alert,omitempty"` + Expiration int64 `json:"expiration,omitempty"` + ApnsID string `json:"apns_id,omitempty"` + Topic string `json:"topic,omitempty"` + Badge int `json:"badge,omitempty"` + Sound string `json:"sound,omitempty"` + Category string `json:"category,omitempty"` + URLArgs []string `json:"url-args,omitempty"` + Extend []ExtendJSON `json:"extend,omitempty"` + Alert Alert `json:"alert,omitempty"` } func CheckPushConf() error { @@ -141,6 +143,10 @@ func GetIOSNotification(req RequestPushNotification) *apns.Notification { notification.Topic = req.Topic } + if req.Expiration > 0 { + notification.Expiration = time.Unix(req.Expiration, 0) + } + if len(req.Priority) > 0 && req.Priority == "normal" { notification.Priority = apns.PriorityLow } diff --git a/gorush/notification_test.go b/gorush/notification_test.go index ba5f897..0445798 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -8,6 +8,7 @@ import ( "log" "os" "testing" + "time" ) func TestDisabledAndroidIosConf(t *testing.T) { @@ -59,12 +60,14 @@ func TestCorrectConf(t *testing.T) { func TestIOSNotificationStructure(t *testing.T) { var dat map[string]interface{} + var unix = time.Now().Unix() test := "test" message := "Welcome notification Server" req := RequestPushNotification{ ApnsID: test, Topic: test, + Expiration: time.Now().Unix(), Priority: "normal", Message: message, Badge: 1, @@ -106,6 +109,7 @@ func TestIOSNotificationStructure(t *testing.T) { assert.Equal(t, test, notification.ApnsID) assert.Equal(t, test, notification.Topic) + assert.Equal(t, unix, notification.Expiration.Unix()) assert.Equal(t, ApnsPriorityLow, notification.Priority) assert.Equal(t, message, alert) assert.Equal(t, 1, int(badge))