Skip to content

Commit f0e7cde

Browse files
committed
Adds interface for localized push notifications
- This is somewhat different from parse.com and probably more efficient
1 parent 161a06a commit f0e7cde

File tree

4 files changed

+53
-42
lines changed

4 files changed

+53
-42
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Fix: Updating array of Dates now keeps it's type (was changing to array of ISO strings, issue #590), thanks to [David Riha](https://github.com/rihadavid)
77
* Fix: NaN displayed when filter input is empty or negative number (#749), thanks to [Miguel Serrrano](https://github.com/miguel-s)
88
* Fix: Addresses issue related to displaying iOS alert object containing title and body keys (#539), thanks to [Robert Martin del Campo](https://github.com/repertus)
9+
* Feature: Adds support for localized push notifications if server version is high enough, thanks to [Florent Vilmart](https://github.com/flovilmart)
910

1011
### 1.1.0
1112

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,27 @@ You can give read only access to a user on a per-app basis:
359359

360360
With this configuration, user1 will have read only access to `myAppId1` and read/write access to `myAppId2`.
361361

362+
## Configuring Localized Push Notifications
363+
364+
With the latest version of the dashboard, it is possible to send localized messages for push notifications.
365+
You can provide a list of locales or languages you want to support for your dashboard users.
366+
367+
```json
368+
{
369+
"apps": [
370+
{
371+
"serverURL": "http://localhost:1337/parse",
372+
"appId": "myAppId",
373+
"masterKey": "myMasterKey",
374+
"appName": "My Parse Server App",
375+
"iconName": "MyAppIcon.png",
376+
"supportedPushLocales": ["en", "ru", "fr"]
377+
}
378+
],
379+
"iconsFolder": "icons"
380+
}
381+
```
382+
362383
## Run with Docker
363384

364385
It is easy to use it with Docker. First build the image:

src/dashboard/Push/PushNew.react.js

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -159,28 +159,23 @@ export default class PushNew extends DashboardView {
159159
this.setState({ pushAudiencesFetched :true });
160160
});
161161

162-
let {xhr, promise} = this.context.currentApp.isLocalizationAvailable();
163-
this.xhrs.push(xhr);
164-
promise.then(({ available }) => {
165-
if (available) {
166-
this.setState({ isLocalizationAvailable : true });
167-
let {xhr, promise} = this.context.currentApp.fetchPushLocales();
168-
this.xhrs.push(xhr);
169-
promise.then(({ options }) => {
170-
let filteredLocales = options.filter((locale) => {
171-
if (locale === '' || locale === undefined) {
172-
return false;
173-
}
174-
return true;
175-
});
176-
this.setState({
177-
locales: filteredLocales,
178-
availableLocales: filteredLocales
179-
});
180-
}).always(() => {
181-
this.setState({ loadingLocale: false });
182-
});
183-
}
162+
const available = this.context.currentApp.isLocalizationAvailable();
163+
if (available) {
164+
const locales = this.context.currentApp.fetchPushLocales();
165+
let filteredLocales = locales.filter((locale) => {
166+
if (locale === '' || locale === undefined) {
167+
return false;
168+
}
169+
return true;
170+
});
171+
this.setState({
172+
isLocalizationAvailable: true,
173+
locales: filteredLocales,
174+
availableLocales: filteredLocales
175+
});
176+
}
177+
this.setState({
178+
loadingLocale: false
184179
});
185180
}
186181

@@ -203,6 +198,15 @@ export default class PushNew extends DashboardView {
203198
}
204199

205200
const push_time = extractPushTime(changes);
201+
202+
// Gather the translations, and inject into the payload
203+
Object.keys(changes).forEach((key) => {
204+
if (key.indexOf('translation[') === 0) {
205+
const locale = key.slice(12, key.length - 1);
206+
payload[`alert-${locale}`] = changes[key];
207+
}
208+
});
209+
206210
let body = {
207211
data: payload,
208212
where: changes.target || new Parse.Query(Parse.Installation),
@@ -530,16 +534,6 @@ export default class PushNew extends DashboardView {
530534
setField('translation_enable', value || null);
531535
}} />} />
532536
);
533-
if (fields.translation_enable) {
534-
translationSegment.push(
535-
<SliderWrap key='warning' direction={Directions.DOWN} expanded={fields.translation_enable} block={true}>
536-
<div className={styles.warning}>
537-
<span>In some cases a locale may not be available for a user, either because they are running an earlier version of the SDK or their client has sent up an invalid locale. In those cases, they will receive the default message.</span>
538-
<a target='_blank' style={{ paddingLeft: '5px' }}href={getSiteDomain() + TRANSLATE_MORE_INFO_URL}>More info.</a>
539-
</div>
540-
</SliderWrap>
541-
);
542-
}
543537
if (fields.translation_enable) {
544538
//locales change based on existing selection
545539

@@ -759,14 +753,9 @@ export default class PushNew extends DashboardView {
759753
// localized message is empty
760754
if (changes.translation_enable) {
761755
this.state.localizedMessages.forEach((message) => {
762-
if (changes.data_type === 'json') {
763-
if (!isValidJSON(message.value)) {
764-
invalidInputMessages.push(<span key='invalid-json'>Your <strong>message for {message.locale}</strong> is not valid JSON.</span>);
765-
}
766-
} else if (!message.value || message.value.trim() === '') {
756+
if (!message.value || message.value.trim() === '') {
767757
emptyInputMessages.push(`message for ${message.locale} locale`);
768758
}
769-
770759
});
771760
}
772761

src/lib/ParseApp.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default class ParseApp {
3939
serverInfo,
4040
production,
4141
iconName,
42+
supportedPushLocales,
4243
}) {
4344
this.name = appName;
4445
this.createdAt = created_at ? new Date(created_at) : new Date();
@@ -59,6 +60,7 @@ export default class ParseApp {
5960
this.serverURL = serverURL;
6061
this.serverInfo = serverInfo;
6162
this.icon = iconName;
63+
this.supportedPushLocales = supportedPushLocales;
6264

6365
this.settings = {
6466
fields: {},
@@ -404,13 +406,11 @@ export default class ParseApp {
404406
}
405407

406408
isLocalizationAvailable() {
407-
let path = '/apps/' + this.slug + '/is_localization_available';
408-
return AJAX.abortableGet(path);
409+
return this.serverInfo.features.push.localization === true;
409410
}
410411

411412
fetchPushLocales() {
412-
let path = '/apps/' + this.slug + '/installation_column_options?column=localeIdentifier';
413-
return AJAX.abortableGet(path);
413+
return this.supportedPushLocales;
414414
}
415415

416416
fetchPushLocaleDeviceCount(audienceId, where, locales) {

0 commit comments

Comments
 (0)