-
-
Notifications
You must be signed in to change notification settings - Fork 735
Add client support for scheduling push notifications #675
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,7 @@ private static void checkArgument(boolean expression, Object errorMessage) { | |
private ParseQuery<ParseInstallation> query; | ||
private Long expirationTime; | ||
private Long expirationTimeInterval; | ||
private Long pushTime; | ||
private Boolean pushToIOS; | ||
private Boolean pushToAndroid; | ||
private JSONObject data; | ||
|
@@ -72,6 +73,7 @@ public Builder(State state) { | |
: new ParseQuery<>(new ParseQuery.State.Builder<ParseInstallation>(state.queryState())); | ||
this.expirationTime = state.expirationTime(); | ||
this.expirationTimeInterval = state.expirationTimeInterval(); | ||
this.pushTime = state.pushTime(); | ||
this.pushToIOS = state.pushToIOS(); | ||
this.pushToAndroid = state.pushToAndroid(); | ||
// Since in state.build() we check data is not null, we do not need to check it again here. | ||
|
@@ -96,6 +98,18 @@ public Builder expirationTimeInterval(Long expirationTimeInterval) { | |
return this; | ||
} | ||
|
||
public Builder pushTime(Long pushTime) { | ||
if (pushTime != null) { | ||
long now = System.currentTimeMillis() / 1000; | ||
long twoWeeks = 60*60*24*7*2; | ||
checkArgument(pushTime > now, "Scheduled push time can not be in the past"); | ||
checkArgument(pushTime < now + twoWeeks, "Scheduled push time can not be more than " + | ||
"two weeks in the future"); | ||
} | ||
this.pushTime = pushTime; | ||
return this; | ||
} | ||
|
||
public Builder pushToIOS(Boolean pushToIOS) { | ||
checkArgument(query == null, "Cannot set push targets (i.e. setPushToAndroid or " + | ||
"setPushToIOS) when pushing to a query"); | ||
|
@@ -151,6 +165,7 @@ public State build() { | |
private final ParseQuery.State<ParseInstallation> queryState; | ||
private final Long expirationTime; | ||
private final Long expirationTimeInterval; | ||
private final Long pushTime; | ||
private final Boolean pushToIOS; | ||
private final Boolean pushToAndroid; | ||
private final JSONObject data; | ||
|
@@ -161,6 +176,7 @@ private State(Builder builder) { | |
this.queryState = builder.query == null ? null : builder.query.getBuilder().build(); | ||
this.expirationTime = builder.expirationTime; | ||
this.expirationTimeInterval = builder.expirationTimeInterval; | ||
this.pushTime = builder.pushTime; | ||
this.pushToIOS = builder.pushToIOS; | ||
this.pushToAndroid = builder.pushToAndroid; | ||
// Since in builder.build() we check data is not null, we do not need to check it again here. | ||
|
@@ -189,6 +205,10 @@ public Long expirationTimeInterval() { | |
return expirationTimeInterval; | ||
} | ||
|
||
public Long pushTime() { | ||
return pushTime; | ||
} | ||
|
||
public Boolean pushToIOS() { | ||
return pushToIOS; | ||
} | ||
|
@@ -421,6 +441,14 @@ public void clearExpiration() { | |
builder.expirationTimeInterval(null); | ||
} | ||
|
||
/** | ||
* Sets a UNIX epoch timestamp at which this notification should be delivered, in seconds (UTC). | ||
* Scheduled time can not be in the past and must be at most two weeks in the future. | ||
*/ | ||
public void setPushTime(long time) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could it be or change the time unit to milliseconds to match Java's timestamp Because unit of UNIX epoch timestamp is seconds, but developers probably using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah seconds are a terrible choice, but we already have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yes, I didn't notice that. We should use the same time unit (seconds) for all relevant methods. |
||
builder.pushTime(time); | ||
} | ||
|
||
/** | ||
* Set whether this push notification will go to iOS devices. | ||
* <p/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the two week restriction something imposed by the server?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes see here. Same code is in iOS version of this feature so it should be ok