MCPcopy
hub / github.com/parse-community/parse-server / sendToAdapter

Method sendToAdapter

src/Push/PushWorker.js:57–98  ·  view source on GitHub ↗
(
    body: any,
    installations: any[],
    pushStatus: any,
    config: Config,
    UTCOffset: ?any
  )

Source from the content-addressed store, hash-verified

55 }
56
57 sendToAdapter(
58 body: any,
59 installations: any[],
60 pushStatus: any,
61 config: Config,
62 UTCOffset: ?any
63 ): Promise<*> {
64 // Check if we have locales in the push body
65 const locales = utils.getLocalesFromPush(body);
66 if (locales.length > 0) {
67 // Get all tranformed bodies for each locale
68 const bodiesPerLocales = utils.bodiesPerLocales(body, locales);
69
70 // Group installations on the specified locales (en, fr, default etc...)
71 const grouppedInstallations = utils.groupByLocaleIdentifier(installations, locales);
72 const promises = Object.keys(grouppedInstallations).map(locale => {
73 const installations = grouppedInstallations[locale];
74 const body = bodiesPerLocales[locale];
75 return this.sendToAdapter(body, installations, pushStatus, config, UTCOffset);
76 });
77 return Promise.all(promises);
78 }
79
80 if (!utils.isPushIncrementing(body)) {
81 logger.verbose(`Sending push to ${installations.length}`);
82 return this.adapter.send(body, installations, pushStatus.objectId).then(results => {
83 return pushStatus.trackSent(results, UTCOffset).then(() => results);
84 });
85 }
86
87 // Collect the badges to reduce the # of calls
88 const badgeInstallationsMap = groupByBadge(installations);
89
90 // Map the on the badges count and return the send result
91 const promises = Object.keys(badgeInstallationsMap).map(badge => {
92 const payload = structuredClone(body);
93 payload.data.badge = parseInt(badge);
94 const installations = badgeInstallationsMap[badge];
95 return this.sendToAdapter(payload, installations, pushStatus, config, UTCOffset);
96 });
97 return Promise.all(promises);
98 }
99}
100
101export default PushWorker;

Callers 1

runMethod · 0.95

Calls 3

groupByBadgeFunction · 0.85
verboseMethod · 0.80
sendMethod · 0.45

Tested by

no test coverage detected