Skip to content

Commit 648dbf3

Browse files
committed
fix push notifications for ios
1 parent 9e4c2a8 commit 648dbf3

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

.env.example

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ ENGINE_API_KEY=
44
APPLE_TEAMID=
55
APPLE_APN_KEY_ID=
66
APPLE_APN_KEY=
7-
NOTIFICATION_ANDROID_SERVER_KEY=
7+
NOTIFICATION_ANDROID_SERVER_KEY=
8+
STAGE= # alpha | beta | production
9+
NODE_ENV= # development | production

src/config/constants.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,18 @@ export default {
77
GRAPHQL_PATH: '/graphql',
88
BUNDESTAGIO_SERVER_URL: process.env.BUNDESTAGIO_SERVER_URL || 'http://localhost:3100/graphql',
99
NOTIFICATION_ANDROID_SERVER_KEY: process.env.NOTIFICATION_ANDROID_SERVER_KEY || false,
10+
APN_TOPIC: (() => {
11+
switch (process.env.STAGE) {
12+
case 'alpha':
13+
return 'de.democracy-deutschland.clientapp.alpha';
14+
case 'beta':
15+
return 'de.democracy-deutschland.clientapp.beta';
16+
case 'production':
17+
return 'de.democracy-deutschland.clientapp';
18+
19+
default:
20+
console.error('ERROR: no STAGE defined!');
21+
return 'de.democracy-deutschland.clientapp';
22+
}
23+
})(),
1024
};

src/services/notifications/apn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if (!apnProvider) {
1010
keyId: process.env.APPLE_APN_KEY_ID,
1111
teamId: process.env.APPLE_TEAMID,
1212
},
13-
production: process.env.NODE_ENV === 'production', // TODO: handle APLPHA/BETA/PRODUCTION
13+
production: process.env.NODE_ENV === 'production',
1414
};
1515

1616
if (_.filter(options.token, option => !option).length > 0) {

src/services/notifications/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import _ from 'lodash';
44
import apn from 'apn';
55
import gcm from 'node-gcm';
6+
import util from 'util';
67

78
import apnProvider from './apn';
89
import gcmProvider from './gcm';
910
import UserModel from '../../models/User';
1011
import ProcedureModel from '../../models/Procedure';
12+
import CONFIG from '../../config/constants';
1113

1214
const sendNotifications = ({ tokenObjects, message }) => {
1315
const androidNotificationTokens = [];
@@ -19,7 +21,7 @@ const sendNotifications = ({ tokenObjects, message }) => {
1921

2022
note.alert = message;
2123
// note.payload = { messageFrom: 'John Appleseed' };
22-
note.topic = 'de.democracy-deutschland.clientapp';
24+
note.topic = CONFIG.APN_TOPIC;
2325

2426
apnProvider.send(note, token).then((result) => {
2527
console.log('apnProvider.send', result);
@@ -120,10 +122,10 @@ export default async ({ message, user }) => {
120122

121123
note.alert = message;
122124
// note.payload = { messageFrom: 'John Appleseed' };
123-
note.topic = 'de.democracy-deutschland.clientapp';
125+
note.topic = CONFIG.APN_TOPIC;
124126

125127
apnProvider.send(note, token).then((result) => {
126-
console.log('apnProvider.send', result);
128+
console.log('apnProvider.send', util.inspect(result, false, null));
127129
});
128130
}
129131
break;

0 commit comments

Comments
 (0)