Skip to content

Commit 863bc0f

Browse files
authored
Push Audiences improvements (#813)
* Uses proper limit parameter * More support for audiences, sizes, creation time
1 parent 67b556c commit 863bc0f

File tree

7 files changed

+21
-15
lines changed

7 files changed

+21
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"js-beautify": "~1.6.14",
7171
"marked": "^0.3.5",
7272
"node-sass": "^4.5.3",
73-
"parse": "1.9.2",
73+
"parse": "^1.10.2",
7474
"prismjs": "~1.6.0",
7575
"react": "^15.0.1",
7676
"react-addons-test-utils": "^15.0.1",

src/components/PushAudienceDialog/PushAudienceDialog.react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import TextInput from 'components/TextInput/TextInput.react';
2626
import Toggle from 'components/Toggle/Toggle.react';
2727
import { List, Map } from 'immutable';
2828

29-
const PARSE_SERVER_SUPPORTS_SAVED_AUDIENCES = false;
30-
const AUDIENCE_SIZE_FETCHING_ENABLED = false;
29+
const PARSE_SERVER_SUPPORTS_SAVED_AUDIENCES = true;
30+
const AUDIENCE_SIZE_FETCHING_ENABLED = true;
3131

3232
let filterFormatter = (filters, schema) => {
3333
return filters.map((filter) => {

src/components/PushAudiencesSelector/PushAudiencesOption.react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import PushAudiencesBaseRow from 'components/PushAudiencesSelector/PushAudi
1616

1717
const FORM_PREFIX = 'audience_radio';
1818

19-
const AUDIENCE_SIZE_FETCHING_ENABLED = false;
20-
const AUDIENCE_CREATED_DATE_ENABLED = false;
19+
const AUDIENCE_SIZE_FETCHING_ENABLED = true;
20+
const AUDIENCE_CREATED_DATE_ENABLED = true;
2121

2222
export default class PushAudiencesOption extends PushAudiencesBaseRow {
2323
constructor() {

src/components/PushAudiencesSelector/PushAudiencesSelector.react.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import React from 'react';
1212
import styles from 'components/PushAudiencesSelector/PushAudiencesSelector.scss';
1313
import { fromJS } from 'immutable';
1414

15-
const AUDIENCE_SIZE_FETCHING_ENABLED = false;
16-
const AUDIENCE_CREATED_DATE_ENABLED = false;
15+
const AUDIENCE_SIZE_FETCHING_ENABLED = true;
16+
const AUDIENCE_CREATED_DATE_ENABLED = true;
1717

1818
const PushAudiencesOptions = ({
1919
current,

src/dashboard/Push/PushAudiencesData.react.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,9 @@ export default class PushAudiencesData extends React.Component {
126126
// Horrible code here is due to old rails code that sent pushes through it's own endpoint, while Parse Server sends through Parse.Push.
127127
// Ideally, we would pass a Parse.Query around everywhere.
128128
parseQuery.containedIn('deviceType', platforms);
129-
this.props.onChange(saveForFuture ? (() => {throw "Audiences not supported"})() : PushConstants.NEW_SEGMENT_ID, parseQuery, 1 /* TODO: get the read device count */);
129+
if (!saveForFuture) {
130+
this.props.onChange(PushConstants.NEW_SEGMENT_ID, parseQuery, 1 /* TODO: get the read device count */);
131+
}
130132

131133
if (saveForFuture){
132134
this.props.pushAudiencesStore.dispatch(PushAudiencesStore.ActionTypes.CREATE, {

src/lib/ParseApp.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,17 @@ export default class ParseApp {
382382
}
383383

384384
fetchPushSubscriberCount(audienceId, query) {
385-
let path = '/apps/' + this.slug + '/dashboard_ajax/push_subscriber_count';
386-
let urlsSeparator = '?';
387-
if (query){
388-
path += `?where=${encodeURI(JSON.stringify(query))}`;
389-
urlsSeparator = '&';
385+
let promise;
386+
if (!query) {
387+
promise = new Parse.Query('_Audience').get(audienceId, { useMasterKey: true }).then(function(audience) {
388+
return Parse.Query.fromJSON('_Installation', { where: audience.get('query') }).count({ useMasterKey: true })
389+
});
390+
} else {
391+
promise = Parse.Query.fromJSON('_Installation', { where: query }).count({ useMasterKey: true })
390392
}
391-
return AJAX.abortableGet(audienceId ? `${path}${urlsSeparator}audienceId=${audienceId}` : path);
393+
return { xhr: undefined, promise: promise.then(function (count) {
394+
return { count: count };
395+
}) };
392396
}
393397

394398
fetchPushNotifications(type, page, limit) {

src/lib/stores/PushAudiencesStore.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function PushAudiencesStore(state, action) {
2929
return Parse.Promise.as(state);
3030
}
3131
}
32-
const path = action.limit ? `push_audiences?audience_limit=${action.limit}` : 'push_audiences';
32+
const path = action.limit ? `push_audiences?limit=${action.limit}` : 'push_audiences';
3333
const promise = Parse._request('GET', path, {}, { useMasterKey: true });
3434

3535
return promise.then(({ results, showMore }) => {

0 commit comments

Comments
 (0)