Skip to content

Commit cea9c39

Browse files
C Hemidyhiranya911
authored andcommitted
add analytics_label in FcmOptions + fix FcmOptions for WebpushFcmOptions (#256)
* add analytics_label in FcmOptions + fix FcmOptions for WebpushFcmOptions * fix comment * refactor fcm to FCM
1 parent 324b660 commit cea9c39

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

messaging/messaging.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ type Message struct {
148148
Android *AndroidConfig `json:"android,omitempty"`
149149
Webpush *WebpushConfig `json:"webpush,omitempty"`
150150
APNS *APNSConfig `json:"apns,omitempty"`
151+
FCMOptions *FCMOptions `json:"fcm_options,omitempty"`
151152
Token string `json:"token,omitempty"`
152153
Topic string `json:"-"`
153154
Condition string `json:"condition,omitempty"`
@@ -198,6 +199,7 @@ type AndroidConfig struct {
198199
RestrictedPackageName string `json:"restricted_package_name,omitempty"`
199200
Data map[string]string `json:"data,omitempty"` // if specified, overrides the Data field on Message type
200201
Notification *AndroidNotification `json:"notification,omitempty"`
202+
FCMOptions *AndroidFCMOptions `json:"fcm_options,omitempty"`
201203
}
202204

203205
// MarshalJSON marshals an AndroidConfig into JSON (for internal use only).
@@ -274,6 +276,11 @@ type AndroidNotification struct {
274276
ChannelID string `json:"channel_id,omitempty"`
275277
}
276278

279+
// AndroidFCMOptions contains additional options for features provided by the FCM Android SDK.
280+
type AndroidFCMOptions struct {
281+
AnalyticsLabel string `json:"analytics_label,omitempty"`
282+
}
283+
277284
// WebpushConfig contains messaging options specific to the WebPush protocol.
278285
//
279286
// See https://tools.ietf.org/html/rfc8030#section-5 for additional details, and supported
@@ -282,7 +289,7 @@ type WebpushConfig struct {
282289
Headers map[string]string `json:"headers,omitempty"`
283290
Data map[string]string `json:"data,omitempty"`
284291
Notification *WebpushNotification `json:"notification,omitempty"`
285-
FcmOptions *WebpushFcmOptions `json:"fcmOptions,omitempty"`
292+
FcmOptions *WebpushFcmOptions `json:"fcm_options,omitempty"`
286293
}
287294

288295
// WebpushNotificationAction represents an action that can be performed upon receiving a WebPush notification.
@@ -398,8 +405,9 @@ type WebpushFcmOptions struct {
398405
// See https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html
399406
// for more details on supported headers and payload keys.
400407
type APNSConfig struct {
401-
Headers map[string]string `json:"headers,omitempty"`
402-
Payload *APNSPayload `json:"payload,omitempty"`
408+
Headers map[string]string `json:"headers,omitempty"`
409+
Payload *APNSPayload `json:"payload,omitempty"`
410+
FCMOptions *APNSFCMOptions `json:"fcm_options,omitempty"`
403411
}
404412

405413
// APNSPayload is the payload that can be included in an APNS message.
@@ -608,6 +616,16 @@ type ApsAlert struct {
608616
LaunchImage string `json:"launch-image,omitempty"`
609617
}
610618

619+
// APNSFCMOptions contains additional options for features provided by the FCM Aps SDK.
620+
type APNSFCMOptions struct {
621+
AnalyticsLabel string `json:"analytics_label,omitempty"`
622+
}
623+
624+
// FCMOptions contains additional options to use across all platforms.
625+
type FCMOptions struct {
626+
AnalyticsLabel string `json:"analytics_label,omitempty"`
627+
}
628+
611629
// ErrorInfo is a topic management error.
612630
type ErrorInfo struct {
613631
Index int

messaging/messaging_test.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,19 @@ var validMessages = []struct {
8282
"k1": "v1",
8383
"k2": "v2",
8484
},
85+
FCMOptions: &FCMOptions{
86+
AnalyticsLabel: "Analytics",
87+
},
8588
Topic: "test-topic",
8689
},
8790
want: map[string]interface{}{
8891
"data": map[string]interface{}{
8992
"k1": "v1",
9093
"k2": "v2",
9194
},
95+
"fcm_options": map[string]interface{}{
96+
"analytics_label": "Analytics",
97+
},
9298
"topic": "test-topic",
9399
},
94100
},
@@ -153,6 +159,9 @@ var validMessages = []struct {
153159
ChannelID: "channel",
154160
},
155161
TTL: &ttlWithNanos,
162+
FCMOptions: &AndroidFCMOptions{
163+
AnalyticsLabel: "Analytics",
164+
},
156165
},
157166
Topic: "test-topic",
158167
},
@@ -171,6 +180,9 @@ var validMessages = []struct {
171180
"channel_id": "channel",
172181
},
173182
"ttl": "1.500000000s",
183+
"fcm_options": map[string]interface{}{
184+
"analytics_label": "Analytics",
185+
},
174186
},
175187
"topic": "test-topic",
176188
},
@@ -260,7 +272,7 @@ var validMessages = []struct {
260272
"k1": "v1",
261273
"k2": "v2",
262274
},
263-
"fcmOptions": map[string]interface{}{
275+
"fcm_options": map[string]interface{}{
264276
"link": "https://link.com",
265277
},
266278
},
@@ -308,6 +320,9 @@ var validMessages = []struct {
308320
"k2": true,
309321
},
310322
},
323+
FCMOptions: &APNSFCMOptions{
324+
AnalyticsLabel: "Analytics",
325+
},
311326
},
312327
Topic: "test-topic",
313328
},
@@ -327,6 +342,9 @@ var validMessages = []struct {
327342
"k1": "v1",
328343
"k2": true,
329344
},
345+
"fcm_options": map[string]interface{}{
346+
"analytics_label": "Analytics",
347+
},
330348
},
331349
"topic": "test-topic",
332350
},

0 commit comments

Comments
 (0)