@@ -214,36 +214,53 @@ func (p *APNSPayload) MarshalJSON() ([]byte, error) {
214
214
// Alert may be specified as a string (via the AlertString field), or as a struct (via the Alert
215
215
// field).
216
216
type Aps struct {
217
- AlertString string `json:"-"`
218
- Alert * ApsAlert `json:"-"`
219
- Badge * int `json:"badge,omitempty"`
220
- Sound string `json:"sound,omitempty"`
221
- ContentAvailable bool `json:"-"`
222
- Category string `json:"category,omitempty"`
223
- ThreadID string `json:"thread-id,omitempty"`
217
+ AlertString string
218
+ Alert * ApsAlert
219
+ Badge * int
220
+ Sound string
221
+ ContentAvailable bool
222
+ MutableContent bool
223
+ Category string
224
+ ThreadID string
225
+ CustomData map [string ]interface {}
224
226
}
225
227
226
- // MarshalJSON marshals an Aps into JSON (for internal use only).
227
- func (a * Aps ) MarshalJSON () ([]byte , error ) {
228
- type apsAlias Aps
229
- s := & struct {
230
- Alert interface {} `json:"alert,omitempty"`
231
- ContentAvailable * int `json:"content-available,omitempty"`
232
- * apsAlias
233
- }{
234
- apsAlias : (* apsAlias )(a ),
235
- }
236
-
228
+ // standardFields creates a map containing all the fields except the custom data.
229
+ func (a * Aps ) standardFields () map [string ]interface {} {
230
+ m := make (map [string ]interface {})
237
231
if a .Alert != nil {
238
- s . Alert = a .Alert
232
+ m [ "alert" ] = a .Alert
239
233
} else if a .AlertString != "" {
240
- s . Alert = a .AlertString
234
+ m [ "alert" ] = a .AlertString
241
235
}
242
236
if a .ContentAvailable {
243
- one := 1
244
- s .ContentAvailable = & one
237
+ m ["content-available" ] = 1
245
238
}
246
- return json .Marshal (s )
239
+ if a .MutableContent {
240
+ m ["mutable-content" ] = 1
241
+ }
242
+ if a .Badge != nil {
243
+ m ["badge" ] = * a .Badge
244
+ }
245
+ if a .Sound != "" {
246
+ m ["sound" ] = a .Sound
247
+ }
248
+ if a .Category != "" {
249
+ m ["category" ] = a .Category
250
+ }
251
+ if a .ThreadID != "" {
252
+ m ["thread-id" ] = a .ThreadID
253
+ }
254
+ return m
255
+ }
256
+
257
+ // MarshalJSON marshals an Aps into JSON (for internal use only).
258
+ func (a * Aps ) MarshalJSON () ([]byte , error ) {
259
+ m := a .standardFields ()
260
+ for k , v := range a .CustomData {
261
+ m [k ] = v
262
+ }
263
+ return json .Marshal (m )
247
264
}
248
265
249
266
// ApsAlert is the alert payload that can be included in an Aps.
0 commit comments