File tree Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Expand file tree Collapse file tree 3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change @@ -6,4 +6,5 @@ export default {
6
6
GRAPHIQL_PATH : '/graphiql' ,
7
7
GRAPHQL_PATH : '/graphql' ,
8
8
BUNDESTAGIO_SERVER_URL : process . env . BUNDESTAGIO_SERVER_URL || 'http://localhost:3100/graphql' ,
9
+ NOTIFICATION_ANDROID_SERVER_KEY : process . env . NOTIFICATION_ANDROID_SERVER_KEY || false ,
9
10
} ;
Original file line number Diff line number Diff line change
1
+ import gcm from 'node-gcm' ;
2
+ import CONSTANTS from '../../config/constants' ;
3
+
4
+ let gcmProvider ; // eslint-disable-line
5
+
6
+ if ( ! gcmProvider ) {
7
+ gcmProvider = new gcm . Sender ( CONSTANTS . NOTIFICATION_ANDROID_SERVER_KEY ) ;
8
+ console . log ( 'NOTIFICATION_ANDROID_SERVER_KEY' , CONSTANTS . NOTIFICATION_ANDROID_SERVER_KEY ) ;
9
+ }
10
+
11
+ export default gcmProvider ;
Original file line number Diff line number Diff line change 2
2
3
3
import _ from 'lodash' ;
4
4
import apn from 'apn' ;
5
+ import gcm from 'node-gcm' ;
5
6
6
7
import apnProvider from './apn' ;
8
+ import gcmProvider from './gcm' ;
7
9
import UserModel from '../../models/User' ;
8
10
9
11
export default async ( { message, user } ) => {
@@ -13,6 +15,7 @@ export default async ({ message, user }) => {
13
15
}
14
16
const userObj = await UserModel . findById ( userId ) ;
15
17
if ( userObj ) {
18
+ const androidNotificationTokens = [ ] ;
16
19
userObj . pushTokens . forEach ( ( { token, os } ) => {
17
20
switch ( os ) {
18
21
case 'ios' :
@@ -29,15 +32,30 @@ export default async ({ message, user }) => {
29
32
}
30
33
break ;
31
34
32
- // Hier android und checken ob der case identifier korrekt ist.
33
35
case 'android' :
34
- // gcm
35
-
36
+ // Prepare android notifications
37
+ androidNotificationTokens . push ( token ) ;
36
38
break ;
37
39
38
40
default :
39
41
break ;
40
42
}
41
43
} ) ;
44
+ // send bulk send android notifications
45
+ if ( androidNotificationTokens . length > 0 ) {
46
+ const gcmMessage = new gcm . Message ( {
47
+ notification : {
48
+ body : message ,
49
+ } ,
50
+ } ) ;
51
+ gcmProvider . send (
52
+ gcmMessage ,
53
+ { registrationTokens : androidNotificationTokens } ,
54
+ ( err , response ) => {
55
+ if ( err ) console . error ( 'gcmProvider' , err ) ;
56
+ else console . log ( 'gcmProvider' , response ) ;
57
+ } ,
58
+ ) ;
59
+ }
42
60
}
43
61
} ;
You can’t perform that action at this time.
0 commit comments