Skip to content

Commit 0ae5df4

Browse files
author
Felipe Andrade
committed
Check in serverInfo features if push schedule is available
It's assumed that when push scheduling is available, the dashboard should allow users to choose the delivery time. PS: There is no scheduling mechanism on parse-server, so pooling _PushStatus will be the mechanism behind scheduled pushs for now. More info: parse-community/parse-server#3722
1 parent f79b1fe commit 0ae5df4

File tree

2 files changed

+30
-65
lines changed

2 files changed

+30
-65
lines changed

src/dashboard/Push/PushNew.react.js

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ import { Directions } from 'lib/Constants';
3939
import { Promise } from 'parse';
4040

4141
const PARSE_SERVER_SUPPORTS_AB_TESTING = false;
42-
4342
const PARSE_SERVER_SUPPORTS_PUSH_RICH_MEDIA = false;
44-
45-
const PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH = true;
4643
const PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH_EXPIRATION = false;
4744
const PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH_TIMEZONE = false;
4845

@@ -170,7 +167,7 @@ export default class PushNew extends DashboardView {
170167
options).then(() => {
171168
this.setState({ pushAudiencesFetched :true });
172169
});
173-
170+
174171
let {xhr, promise} = this.context.currentApp.isLocalizationAvailable();
175172
this.xhrs.push(xhr);
176173
promise.then(({ available }) => {
@@ -213,39 +210,27 @@ export default class PushNew extends DashboardView {
213210
if (!!changes.increment_badge) {
214211
payload.badge = "Increment";
215212
}
216-
217-
if(changes.push_time_type === 'now') {
218-
Parse.Push.send({
219-
where: changes.target || new Parse.Query(Parse.Installation),
220-
data: payload,
221-
}, {
222-
useMasterKey: true,
223-
}).then(({ error }) => {
224-
//navigate to push index page and clear cache once push store is created
225-
if (error) {
226-
promise.reject({ error });
213+
Parse.Push.send({
214+
where: changes.target || new Parse.Query(Parse.Installation),
215+
data: payload,
216+
}, {
217+
useMasterKey: true,
218+
}).then(({ error }) => {
219+
//navigate to push index page and clear cache once push store is created
220+
if (error) {
221+
promise.reject({ error });
222+
} else {
223+
//TODO: global success message banner for passing successful creation - store should also be cleared
224+
const PARSE_SERVER_SUPPORTS_PUSH_INDEX = false;
225+
if (PARSE_SERVER_SUPPORTS_PUSH_INDEX) {
226+
history.push(this.context.generatePath('push/activity'));
227227
} else {
228-
//TODO: global success message banner for passing successful creation - store should also be cleared
229-
const PARSE_SERVER_SUPPORTS_PUSH_INDEX = false;
230-
if (PARSE_SERVER_SUPPORTS_PUSH_INDEX) {
231-
history.push(this.context.generatePath('push/activity'));
232-
} else {
233-
promise.resolve();
234-
}
235-
}
236-
}, (error) => {
237-
promise.reject(error);
238-
});
239-
} else {
240-
if(changes.push_time_type === 'time' && changes.push_time !== null) {
241-
let schedulePromise = this.context.currentApp.schedulePush(changes);
242-
schedulePromise.then(pushStatus => {
243228
promise.resolve();
244-
}, (error) => {
245-
promise.reject(error);
246-
});
229+
}
247230
}
248-
}
231+
}, (error) => {
232+
promise.reject(error);
233+
});
249234
return promise;
250235
}
251236

@@ -720,7 +705,7 @@ export default class PushNew extends DashboardView {
720705

721706
const richmediaFieldsDescription = PARSE_SERVER_SUPPORTS_PUSH_RICH_MEDIA ?
722707
'We can send images and videos directly to your app.' :
723-
"If your push hasn't been send with rich media, it won't get setup by your dev.";
708+
'Rich media is not currently supported.';
724709

725710
const richmediaTimeFields = PARSE_SERVER_SUPPORTS_PUSH_RICH_MEDIA? <Fieldset
726711
legend={richmediaFieldsLegend}
@@ -731,18 +716,21 @@ export default class PushNew extends DashboardView {
731716
{PARSE_SERVER_SUPPORTS_PUSH_RICH_MEDIA ? this.renderRichMediaContent(fields, setField) : null}
732717
</Fieldset> : null;
733718

734-
const timeFieldsLegend = PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ?
719+
let features = this.context.currentApp.serverInfo.features;
720+
let hasScheduledPush = features.push.scheduledPush;
721+
722+
const timeFieldsLegend = hasScheduledPush ?
735723
'Choose a delivery time' :
736724
'Choose exiry';
737725

738-
const timeFieldsDescription = PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ?
739-
'We can send the campaign immediately, or any time in the next weeks.' :
740-
"If your push hasn't been send by this time, it won't get sent.";
726+
const timeFieldsDescription = hasScheduledPush ?
727+
'We can send the campaign immediately, or any time in the future.' :
728+
'Push schedule is not currently supported.';
741729

742-
const deliveryTimeFields = PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH? <Fieldset
730+
const deliveryTimeFields = hasScheduledPush? <Fieldset
743731
legend={timeFieldsLegend}
744732
description={timeFieldsDescription}>
745-
{PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ? this.renderDeliveryContent(fields, setField) : null}
733+
{hasScheduledPush ? this.renderDeliveryContent(fields, setField) : null}
746734
{PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH_EXPIRATION ?
747735
<Field
748736
label={<Label text='Should this notification expire?' />}
@@ -943,7 +931,7 @@ export default class PushNew extends DashboardView {
943931
);
944932
}
945933
let timeNote = null;
946-
if(changes.push_time_type === 'time' && changes.push_time !== null || changes.push_time_type === 'now') {
934+
if (changes.push_time_type === 'time' && changes.push_time !== null || changes.push_time_type === 'now') {
947935
timeNote = (
948936
<span>
949937
It will be sent <strong>{changes.push_time_type === 'now' ? 'immediately' : String(changes.push_time)}</strong>.&nbsp;

src/lib/ParseApp.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -409,29 +409,6 @@ export default class ParseApp {
409409
return query.first({ useMasterKey: true });
410410
}
411411

412-
schedulePush(changes) {
413-
var pushTime = changes.push_time_iso.toISOString();
414-
var query = changes.target;
415-
let payload = changes.data_type === 'json' ? JSON.parse(changes.data) : { alert: changes.data };
416-
if(query == undefined) {
417-
query = "{}";
418-
} else {
419-
query = JSON.stringify(query);
420-
}
421-
422-
let PushStatus = Parse.Object.extend("_PushStatus");
423-
let pushStatus = new PushStatus();
424-
pushStatus.set("query", query);
425-
pushStatus.set("payload", JSON.stringify(payload));
426-
pushStatus.set("pushTime", pushTime);
427-
pushStatus.set("numSent", 0);
428-
pushStatus.set("numFailed", 0);
429-
pushStatus.set("status", "scheduled");
430-
pushStatus.set("source", "rest");
431-
pushStatus.setACL(new Parse.ACL());
432-
return pushStatus.save(null, { useMasterKey: true });
433-
}
434-
435412
isLocalizationAvailable() {
436413
let path = '/apps/' + this.slug + '/is_localization_available';
437414
return AJAX.abortableGet(path);

0 commit comments

Comments
 (0)