Skip to content

Commit 5a20169

Browse files
committed
Upgrade push service with required iOS Topic field
1 parent f41798d commit 5a20169

File tree

1 file changed

+27
-18
lines changed

1 file changed

+27
-18
lines changed

services/push/routes/push.js

+27-18
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,34 @@ const platform = {
99

1010
const generatePayload = async function (title, message) {
1111

12-
return {
13-
notifications: [
14-
{
15-
tokens: await getDevicesByPlatform(platform.android),
16-
platform: platform.android,
17-
message: message,
18-
title: title
19-
},
20-
{
21-
tokens: await getDevicesByPlatform(platform.ios),
22-
platform: platform.ios,
23-
message: message,
24-
'alert': {
25-
'title': title,
26-
'body': message,
27-
}
12+
let notifications = [];
13+
14+
let iosTokens = await getDevicesByPlatform(platform.ios),
15+
androidTokens = await getDevicesByPlatform(platform.android);
16+
17+
if (androidTokens.length > 0) {
18+
notifications.push({
19+
tokens: androidTokens,
20+
platform: platform.android,
21+
message: message,
22+
title: title
23+
});
24+
}
25+
26+
if (iosTokens.length > 0) {
27+
notifications.push({
28+
tokens: iosTokens,
29+
platform: platform.ios,
30+
topic: 'com.hackfsu.ios',
31+
message: message,
32+
'alert': {
33+
'title': title,
34+
'body': message,
2835
}
29-
]
30-
};
36+
})
37+
}
38+
39+
return { notifications };
3140
};
3241

3342
module.exports = async function (req, res) {

0 commit comments

Comments
 (0)