Adds support for localized push notification in push payload (#4129)
* Adds support for localized push data keys - passign alert-[lang|locale] or title-[lang|locale] will inject the proper locale on the push body based on the installation * Better handling of the default cases * Updates changelog * nits * nits
This commit is contained in:
@@ -65,6 +65,22 @@ export class PushWorker {
|
||||
|
||||
sendToAdapter(body: any, installations: any[], pushStatus: any, config: Config): Promise<*> {
|
||||
pushStatus = pushStatusHandler(config, pushStatus.objectId);
|
||||
// Check if we have locales in the push body
|
||||
const locales = utils.getLocalesFromPush(body);
|
||||
if (locales.length > 0) {
|
||||
// Get all tranformed bodies for each locale
|
||||
const bodiesPerLocales = utils.bodiesPerLocales(body, locales);
|
||||
|
||||
// Group installations on the specified locales (en, fr, default etc...)
|
||||
const grouppedInstallations = utils.groupByLocaleIdentifier(installations, locales);
|
||||
const promises = Object.keys(grouppedInstallations).map((locale) => {
|
||||
const installations = grouppedInstallations[locale];
|
||||
const body = bodiesPerLocales[locale];
|
||||
return this.sendToAdapter(body, installations, pushStatus, config);
|
||||
});
|
||||
return Promise.all(promises);
|
||||
}
|
||||
|
||||
if (!utils.isPushIncrementing(body)) {
|
||||
return this.adapter.send(body, installations, pushStatus.objectId).then((results) => {
|
||||
return pushStatus.trackSent(results);
|
||||
|
||||
Reference in New Issue
Block a user