@@ -105,9 +105,9 @@ APNS.prototype.send = function(data, devices) {
105
105
let expirationTime = data [ 'expiration_time' ] ;
106
106
let notification = generateNotification ( coreData , expirationTime ) ;
107
107
let allPromises = [ ] ;
108
-
108
+ let devicesPerConnIndex = { } ;
109
109
// Start by clustering the devices per connections
110
- let devicesPerConnIndex = devices . reduce ( ( memo , device ) => {
110
+ devices . forEach ( ( device ) => {
111
111
let qualifiedConnIndexs = chooseConns ( this . conns , device ) ;
112
112
if ( qualifiedConnIndexs . length == 0 ) {
113
113
log . error ( LOG_PREFIX , 'no qualified connections for %s %s' , device . appIdentifier , device . deviceToken ) ;
@@ -126,11 +126,10 @@ APNS.prototype.send = function(data, devices) {
126
126
if ( device . appIdentifier ) {
127
127
apnDevice . appIdentifier = device . appIdentifier ;
128
128
}
129
- memo [ apnDevice . connIndex ] = memo [ apnDevice . connIndex ] || [ ] ;
130
- memo [ apnDevice . connIndex ] . push ( apnDevice ) ;
129
+ devicesPerConnIndex [ apnDevice . connIndex ] = devicesPerConnIndex [ apnDevice . connIndex ] || [ ] ;
130
+ devicesPerConnIndex [ apnDevice . connIndex ] . push ( apnDevice ) ;
131
131
}
132
- return memo ;
133
- } , { } )
132
+ } )
134
133
135
134
allPromises = Object . keys ( devicesPerConnIndex ) . reduce ( ( memo , connIndex ) => {
136
135
let devices = devicesPerConnIndex [ connIndex ] ;
@@ -143,35 +142,9 @@ APNS.prototype.send = function(data, devices) {
143
142
let conn = this . conns [ connIndex ] ;
144
143
conn . pushNotification ( notification , devices ) ;
145
144
return memo . concat ( promises ) ;
146
- } , allPromises )
145
+ } , allPromises ) ;
147
146
148
- // let promises = devices.map((device) => {
149
- // let qualifiedConnIndexs = chooseConns(this.conns, device);
150
- // // We can not find a valid conn, just ignore this device
151
- // if (qualifiedConnIndexs.length == 0) {
152
- // log.error(LOG_PREFIX, 'no qualified connections for %s %s', device.appIdentifier, device.deviceToken);
153
- // return Promise.resolve({
154
- // transmitted: false,
155
- // device: {
156
- // deviceToken: device.deviceToken,
157
- // deviceType: 'ios'
158
- // },
159
- // result: {error: 'No connection available'}
160
- // });
161
- // }
162
- // let conn = this.conns[qualifiedConnIndexs[0]];
163
- // let apnDevice = new apn.Device(device.deviceToken);
164
- // apnDevice.connIndex = qualifiedConnIndexs[0];
165
- // // Add additional appIdentifier info to apn device instance
166
- // if (device.appIdentifier) {
167
- // apnDevice.appIdentifier = device.appIdentifier;
168
- // }
169
- // return new Promise((resolve, reject) => {
170
- // apnDevice.callback = resolve;
171
- // conn.pushNotification(notification, apnDevice);
172
- // });
173
- // });
174
- return Parse . Promise . when ( allPromises ) ;
147
+ return Promise . all ( allPromises ) ;
175
148
}
176
149
177
150
function handleTransmissionError ( conns , errCode , notification , apnDevice ) {
0 commit comments