Skip to content

Commit aba69a2

Browse files
committed
Add client support for push_time
1 parent e741077 commit aba69a2

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

Parse/src/main/java/com/parse/ParsePush.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ private static void checkArgument(boolean expression, Object errorMessage) {
5555
private ParseQuery<ParseInstallation> query;
5656
private Long expirationTime;
5757
private Long expirationTimeInterval;
58+
private Long pushTime;
5859
private Boolean pushToIOS;
5960
private Boolean pushToAndroid;
6061
private JSONObject data;
@@ -96,6 +97,18 @@ public Builder expirationTimeInterval(Long expirationTimeInterval) {
9697
return this;
9798
}
9899

100+
public Builder pushTime(Long pushTime) {
101+
if (pushTime != null) {
102+
long now = System.currentTimeMillis() / 1000;
103+
long twoWeeks = 60*60*24*7*2;
104+
checkArgument(pushTime > now, "Scheduled push time can not be in the past");
105+
checkArgument(pushTime < now + twoWeeks, "Scheduled push time can not be more than " +
106+
"two weeks in the future");
107+
}
108+
this.pushTime = pushTime;
109+
return this;
110+
}
111+
99112
public Builder pushToIOS(Boolean pushToIOS) {
100113
checkArgument(query == null, "Cannot set push targets (i.e. setPushToAndroid or " +
101114
"setPushToIOS) when pushing to a query");
@@ -151,6 +164,7 @@ public State build() {
151164
private final ParseQuery.State<ParseInstallation> queryState;
152165
private final Long expirationTime;
153166
private final Long expirationTimeInterval;
167+
private final Long pushTime;
154168
private final Boolean pushToIOS;
155169
private final Boolean pushToAndroid;
156170
private final JSONObject data;
@@ -161,6 +175,7 @@ private State(Builder builder) {
161175
this.queryState = builder.query == null ? null : builder.query.getBuilder().build();
162176
this.expirationTime = builder.expirationTime;
163177
this.expirationTimeInterval = builder.expirationTimeInterval;
178+
this.pushTime = builder.pushTime;
164179
this.pushToIOS = builder.pushToIOS;
165180
this.pushToAndroid = builder.pushToAndroid;
166181
// Since in builder.build() we check data is not null, we do not need to check it again here.
@@ -189,6 +204,10 @@ public Long expirationTimeInterval() {
189204
return expirationTimeInterval;
190205
}
191206

207+
public Long pushTime() {
208+
return pushTime;
209+
}
210+
192211
public Boolean pushToIOS() {
193212
return pushToIOS;
194213
}
@@ -421,6 +440,14 @@ public void clearExpiration() {
421440
builder.expirationTimeInterval(null);
422441
}
423442

443+
/**
444+
* Sets a UNIX epoch timestamp at which this notification should be delivered, in seconds (UTC).
445+
* Scheduled time can not be in the past and must be at most two weeks in the future.
446+
*/
447+
public void setPushTime(long time) {
448+
builder.pushTime(time);
449+
}
450+
424451
/**
425452
* Set whether this push notification will go to iOS devices.
426453
* <p/>

Parse/src/main/java/com/parse/ParsePushController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public Task<Void> sendInBackground(ParsePush.State state, String sessionToken) {
4343
}
4444
}
4545
return ParseRESTPushCommand.sendPushCommand(state.queryState(), state.channelSet(), deviceType,
46-
state.expirationTime(), state.expirationTimeInterval(), state.data(), sessionToken);
46+
state.expirationTime(), state.expirationTimeInterval(), state.pushTime(), state.data(),
47+
sessionToken);
4748
}
4849
}

Parse/src/main/java/com/parse/ParseRESTPushCommand.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
/* package */ final static String KEY_DEVICE_TYPE = "deviceType";
2424
/* package */ final static String KEY_EXPIRATION_TIME = "expiration_time";
2525
/* package */ final static String KEY_EXPIRATION_INTERVAL = "expiration_interval";
26+
/* package */ final static String KEY_PUSH_TIME = "push_time";
2627
/* package */ final static String KEY_DATA = "data";
2728

2829
public ParseRESTPushCommand(
@@ -35,7 +36,7 @@ public ParseRESTPushCommand(
3536

3637
public static ParseRESTPushCommand sendPushCommand(ParseQuery.State<ParseInstallation> query,
3738
Set<String> targetChannels, String targetDeviceType, Long expirationTime,
38-
Long expirationInterval, JSONObject payload, String sessionToken) {
39+
Long expirationInterval, Long pushTime, JSONObject payload, String sessionToken) {
3940
JSONObject parameters = new JSONObject();
4041
try {
4142
if (targetChannels != null) {
@@ -63,9 +64,14 @@ public static ParseRESTPushCommand sendPushCommand(ParseQuery.State<ParseInstall
6364
parameters.put(KEY_EXPIRATION_INTERVAL, expirationInterval);
6465
}
6566

67+
if (pushTime != null) {
68+
parameters.put(KEY_PUSH_TIME, pushTime);
69+
}
70+
6671
if (payload != null) {
6772
parameters.put(KEY_DATA, payload);
6873
}
74+
6975
} catch (JSONException e) {
7076
throw new RuntimeException(e);
7177
}

0 commit comments

Comments
 (0)