Skip to content

Commit 48ac9d5

Browse files
chemidyhiranya911
authored andcommitted
add subtitle in messaging.ApsAlert payload (#393)
* add subtitle in messaging.ApsAlert payload * fix test * revert for legacy send operations
1 parent 018b7c5 commit 48ac9d5

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Unreleased
22

3-
-
3+
- [added] `messaging.ApsAlert` type now supports subtitle in its payload.
44

55
# v6.2.0
66

src/index.d.ts

+3
Original file line numberDiff line numberDiff line change
@@ -456,11 +456,14 @@ declare namespace admin.messaging {
456456

457457
type ApsAlert = {
458458
title?: string;
459+
subtitle?: string;
459460
body?: string;
460461
locKey?: string;
461462
locArgs?: string[];
462463
titleLocKey?: string;
463464
titleLocArgs?: string[];
465+
subtitleLocKey?: string;
466+
subtitleLocArgs?: string[];
464467
actionLocKey?: string;
465468
launchImage?: string;
466469
};

src/messaging/messaging.ts

+11
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,14 @@ export interface Aps {
180180

181181
export interface ApsAlert {
182182
title?: string;
183+
subtitle?: string;
183184
body?: string;
184185
locKey?: string;
185186
locArgs?: string[];
186187
titleLocKey?: string;
187188
titleLocArgs?: string[];
189+
subtitleLocKey?: string;
190+
subtitleLocArgs?: string[];
188191
actionLocKey?: string;
189192
launchImage?: string;
190193
}
@@ -357,12 +360,20 @@ function validateApsAlert(alert: string | ApsAlert) {
357360
MessagingClientErrorCode.INVALID_PAYLOAD,
358361
'apns.payload.aps.alert.titleLocKey is required when specifying titleLocArgs');
359362
}
363+
if (validator.isNonEmptyArray(apsAlert.subtitleLocArgs) &&
364+
!validator.isNonEmptyString(apsAlert.subtitleLocKey)) {
365+
throw new FirebaseMessagingError(
366+
MessagingClientErrorCode.INVALID_PAYLOAD,
367+
'apns.payload.aps.alert.subtitleLocKey is required when specifying subtitleLocArgs');
368+
}
360369

361370
const propertyMappings = {
362371
locKey: 'loc-key',
363372
locArgs: 'loc-args',
364373
titleLocKey: 'title-loc-key',
365374
titleLocArgs: 'title-loc-args',
375+
subtitleLocKey: 'subtitle-loc-key',
376+
subtitleLocArgs: 'subtitle-loc-args',
366377
actionLocKey: 'action-loc-key',
367378
launchImage: 'launch-image',
368379
};

test/unit/messaging/messaging.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -1737,6 +1737,24 @@ describe('Messaging', () => {
17371737
}).to.throw('titleLocKey is required when specifying titleLocArgs');
17381738
});
17391739

1740+
it('should throw given apns subtitleLocArgs without subtitleLocKey', () => {
1741+
const message: Message = {
1742+
condition: 'topic-name',
1743+
apns: {
1744+
payload: {
1745+
aps: {
1746+
alert: {
1747+
subtitleLocArgs: ['foo'],
1748+
},
1749+
},
1750+
},
1751+
},
1752+
};
1753+
expect(() => {
1754+
messaging.send(message);
1755+
}).to.throw('subtitleLocKey is required when specifying subtitleLocArgs');
1756+
});
1757+
17401758
it('should throw given apns locArgs without locKey', () => {
17411759
const message: Message = {
17421760
condition: 'topic-name',
@@ -2264,11 +2282,17 @@ describe('Messaging', () => {
22642282
payload: {
22652283
aps: {
22662284
alert: {
2285+
title: 'title',
2286+
subtitle: 'subtitle',
2287+
body: 'body',
22672288
titleLocKey: 'title.loc.key',
22682289
titleLocArgs: ['arg1', 'arg2'],
2290+
subtitleLocKey: 'subtitle.loc.key',
2291+
subtitleLocArgs: ['arg1', 'arg2'],
22692292
locKey: 'body.loc.key',
22702293
locArgs: ['arg1', 'arg2'],
22712294
actionLocKey: 'action.loc.key',
2295+
launchImage: 'image',
22722296
},
22732297
badge: 42,
22742298
sound: 'test.sound',
@@ -2291,11 +2315,17 @@ describe('Messaging', () => {
22912315
payload: {
22922316
aps: {
22932317
'alert': {
2318+
'title': 'title',
2319+
'subtitle': 'subtitle',
2320+
'body': 'body',
22942321
'title-loc-key': 'title.loc.key',
22952322
'title-loc-args': ['arg1', 'arg2'],
2323+
'subtitle-loc-key': 'subtitle.loc.key',
2324+
'subtitle-loc-args': ['arg1', 'arg2'],
22962325
'loc-key': 'body.loc.key',
22972326
'loc-args': ['arg1', 'arg2'],
22982327
'action-loc-key': 'action.loc.key',
2328+
'launch-image': 'image',
22992329
},
23002330
'badge': 42,
23012331
'sound': 'test.sound',

0 commit comments

Comments
 (0)