MCPcopy Index your code
hub / github.com/parse-community/parse-server / trackSent

Function trackSent

src/StatusHandler.js:200–306  ·  view source on GitHub ↗
(
    results,
    UTCOffset,
    cleanupInstallations = process.env.PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS
  )

Source from the content-addressed store, hash-verified

198 };
199
200 const trackSent = function (
201 results,
202 UTCOffset,
203 cleanupInstallations = process.env.PARSE_SERVER_CLEANUP_INVALID_INSTALLATIONS
204 ) {
205 const update = {
206 numSent: 0,
207 numFailed: 0,
208 };
209 const devicesToRemove = [];
210 if (Array.isArray(results)) {
211 results = flatten(results);
212 results.reduce((memo, result) => {
213 // Cannot handle that
214 if (!result || !result.device || !result.device.deviceType) {
215 return memo;
216 }
217 const deviceType = result.device.deviceType;
218 const key = result.transmitted
219 ? `sentPerType.${deviceType}`
220 : `failedPerType.${deviceType}`;
221 memo[key] = incrementOp(memo, key);
222 if (typeof UTCOffset !== 'undefined') {
223 const offsetKey = result.transmitted
224 ? `sentPerUTCOffset.${UTCOffset}`
225 : `failedPerUTCOffset.${UTCOffset}`;
226 memo[offsetKey] = incrementOp(memo, offsetKey);
227 }
228 if (result.transmitted) {
229 memo.numSent++;
230 } else {
231 if (
232 result &&
233 result.response &&
234 result.response.error &&
235 result.device &&
236 result.device.deviceToken
237 ) {
238 const token = result.device.deviceToken;
239 const error = result.response.error;
240 // GCM / FCM HTTP v1 API errors; see:
241 // https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
242 if (error === 'NotRegistered' || error === 'InvalidRegistration') {
243 devicesToRemove.push(token);
244 }
245 // FCM API v2 errors; see:
246 // https://firebase.google.com/docs/cloud-messaging/manage-tokens
247 // https://github.com/firebase/functions-samples/blob/703c0359eacf07a551751d1319d34f912a2cd828/Node/fcm-notifications/functions/index.js#L89-L93C16
248 if (
249 error?.code === 'messaging/registration-token-not-registered' ||
250 error?.code === 'messaging/invalid-registration-token' ||
251 (error?.code === 'messaging/invalid-argument' && error?.message === 'The registration token is not a valid FCM registration token')
252 ) {
253 devicesToRemove.push(token);
254 }
255 // APNS errors; see:
256 // https://developer.apple.com/documentation/usernotifications/handling-notification-responses-from-apns
257 if (error === 'Unregistered' || error === 'BadDeviceToken') {

Callers

nothing calls this directly

Calls 5

flattenFunction · 0.85
incrementOpFunction · 0.85
verboseMethod · 0.80
infoMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected