Skip to content

Commit 7c0235d

Browse files
committed
nits
1 parent c2c4f51 commit 7c0235d

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

src/APNS.js

+7-34
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ APNS.prototype.send = function(data, devices) {
105105
let expirationTime = data['expiration_time'];
106106
let notification = generateNotification(coreData, expirationTime);
107107
let allPromises = [];
108-
108+
let devicesPerConnIndex = {};
109109
// Start by clustering the devices per connections
110-
let devicesPerConnIndex = devices.reduce((memo, device) => {
110+
devices.forEach((device) => {
111111
let qualifiedConnIndexs = chooseConns(this.conns, device);
112112
if (qualifiedConnIndexs.length == 0) {
113113
log.error(LOG_PREFIX, 'no qualified connections for %s %s', device.appIdentifier, device.deviceToken);
@@ -126,11 +126,10 @@ APNS.prototype.send = function(data, devices) {
126126
if (device.appIdentifier) {
127127
apnDevice.appIdentifier = device.appIdentifier;
128128
}
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);
131131
}
132-
return memo;
133-
}, {})
132+
})
134133

135134
allPromises = Object.keys(devicesPerConnIndex).reduce((memo, connIndex) => {
136135
let devices = devicesPerConnIndex[connIndex];
@@ -143,35 +142,9 @@ APNS.prototype.send = function(data, devices) {
143142
let conn = this.conns[connIndex];
144143
conn.pushNotification(notification, devices);
145144
return memo.concat(promises);
146-
}, allPromises)
145+
}, allPromises);
147146

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);
175148
}
176149

177150
function handleTransmissionError(conns, errCode, notification, apnDevice) {

0 commit comments

Comments
 (0)