Skip to content

Support push time, expiration time, and expiration interval #773

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions src/dashboard/Push/PushNew.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ import Toggle from 'components/Toggle/Toggle.react';
import Toolbar from 'components/Toolbar/Toolbar.react';
import { Directions } from 'lib/Constants';
import { Promise } from 'parse';
import { extractExpiration, extractPushTime } from 'lib/extractTime';

const PARSE_SERVER_SUPPORTS_AB_TESTING = false;
const PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH = false;

let formatErrorMessage = (emptyInputMessages, key) => {
let boldMessages = emptyInputMessages.map((message) => {
Expand Down Expand Up @@ -202,10 +202,14 @@ export default class PushNew extends DashboardView {
payload.badge = "Increment";
}

const push_time = extractPushTime(changes);
let body = {
data: payload,
where: changes.target || new Parse.Query(Parse.Installation),
data: payload
}
push_time,
};
Object.assign(body, extractExpiration(changes));

let audience_id = changes.audience_id;
// Only set the audience ID if it is a saved audience.
if (audience_id != PushConstants.NEW_SEGMENT_ID && audience_id != "everyone") {
Expand Down Expand Up @@ -631,7 +635,7 @@ export default class PushNew extends DashboardView {
legend='Choose your recipients.'
description='Send to everyone, or use an audience to target the right users.'>
<PushAudiencesData
loaded={true /* Parse Server doesn't support push audiences yet. once it does, pass: this.state.pushAudiencesFetched */}
loaded={this.state.pushAudiencesFetched}
schema={schema}
pushAudiencesStore={this.props.pushaudiences}
current={fields.audience_id}
Expand Down Expand Up @@ -677,18 +681,21 @@ export default class PushNew extends DashboardView {
{this.renderExperimentContent(fields, setField)}
</Fieldset> : null;

const timeFieldsLegend = PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ?
const {push} = this.context.currentApp.serverInfo.features;
const hasScheduledPushSupport = push && push.scheduledPush;

const timeFieldsLegend = hasScheduledPushSupport ?
'Choose a delivery time' :
'Choose exiry';
'Choose expiry';

const timeFieldsDescription = PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ?
const timeFieldsDescription = hasScheduledPushSupport ?
'We can send the campaign immediately, or any time in the next 2 weeks.' :
"If your push hasn't been send by this time, it won't get sent.";

const deliveryTimeFields = PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ? <Fieldset
const deliveryTimeFields = hasScheduledPushSupport ? <Fieldset
legend={timeFieldsLegend}
description={timeFieldsDescription}>
{PARSE_SERVER_SUPPORTS_SCHEDULE_PUSH ? this.renderDeliveryContent(fields, setField) : null}
{hasScheduledPushSupport ? this.renderDeliveryContent(fields, setField) : null}
<Field
label={<Label text='Should this notification expire?' />}
input={<Toggle value={fields.push_expires} onChange={setField.bind(null, 'push_expires')} />} />
Expand Down
51 changes: 51 additions & 0 deletions src/lib/extractTime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
export function extractPushTime(changes) {
const {
local_time: isLocalTime,
push_time_type,
push_time,
push_time_iso,
} = changes;

if (push_time_type === 'time') {
if (isLocalTime) {
return push_time;
}
return push_time_iso;
}
}

export function extractExpiration(changes) {
const {
local_time: isLocalTime,
push_time,
push_expires,
expiration_time_type,
expiration_interval_unit,
expiration_interval_num,
expiration_time
} = changes;

if (push_expires) {
if (expiration_time_type === 'interval') {
let time = parseInt(expiration_interval_num, 10);
if (expiration_interval_unit === 'hours') {
time *= 60 * 60;
} else if (expiration_interval_unit === 'days') {
time *= 60 * 60 * 24;
}

return { expiration_interval: time };
} else if (expiration_time_type === 'time') {
if (isLocalTime) {
const pushTime = new Date(push_time);
const expirationTime = new Date(expiration_time);
const diffSeconds = Math.floor((expirationTime - pushTime) / 1000);
return { expiration_interval: diffSeconds };
}

return { expiration_time };
}
}

return {};
}
Loading