Skip to content

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

Merged
merged 3 commits into from
Jun 3, 2017

Conversation

natario1
Copy link
Contributor

@natario1 natario1 commented Jun 1, 2017

This adds ParsePush.setPushTime() which is already present in other client SDKs.

Seems that parse-server will be eventually supporting scheduled pushes so we’ll be ready when it happens.

Fixes #278 .

@codecov
Copy link

codecov bot commented Jun 1, 2017

Codecov Report

Merging #675 into master will increase coverage by 0.08%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #675      +/-   ##
============================================
+ Coverage     52.56%   52.64%   +0.08%     
- Complexity     1678     1680       +2     
============================================
  Files           131      131              
  Lines         10106    10120      +14     
  Branches       1405     1409       +4     
============================================
+ Hits           5312     5328      +16     
+ Misses         4353     4352       -1     
+ Partials        441      440       -1
Impacted Files Coverage Δ Complexity Δ
.../src/main/java/com/parse/ParseRESTPushCommand.java 88.88% <100%> (+0.88%) 9 <0> (+1) ⬆️
Parse/src/main/java/com/parse/ParsePush.java 93.42% <100%> (+0.56%) 30 <1> (+1) ⬆️
...e/src/main/java/com/parse/ParsePushController.java 86.66% <100%> (ø) 10 <0> (ø) ⬇️
...se/src/main/java/com/parse/ParseKeyValueCache.java 47% <0%> (+2%) 16% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e741077...7d81aa5. Read the comment docs.

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 " +
Copy link
Member

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?

Copy link
Contributor Author

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

* 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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could it be public void setPushTime(Date date)?
(pushTime = date.getTime()/1000)

or change the time unit to milliseconds to match Java's timestamp
(pushTime = time/1000)

Because unit of UNIX epoch timestamp is seconds, but developers probably using Date.getTime() or System.currentTimeMillis() to get timestamp (unit is milliseconds), then they will fail if not converted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah seconds are a terrible choice, but we already have setExpirationTime(long) and setExpirationInterval(long) in seconds, it would be confusing to have this in millis or in Date.
Note sure what to do, maybe we should add a Date version for all three methods. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
I think it's okay to add a Date version.

ParsePush.State.Builder builder = new ParsePush.State.Builder();

ParsePush.State state = builder
.pushTime(System.currentTimeMillis() - 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is wrong if pushTime unit not changed as I previously commented.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time unit is not converted
.pushTime(System.currentTimeMillis() / 1000 - 1)

ParsePush.State.Builder builder = new ParsePush.State.Builder();

ParsePush.State state = builder
.pushTime(System.currentTimeMillis() - 1000)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time unit is not converted
.pushTime(System.currentTimeMillis() / 1000 - 1)

ParsePush.State.Builder builder = new ParsePush.State.Builder();

ParsePush.State state = builder
.pushTime(System.currentTimeMillis() + 60*60*24*7*3)
Copy link
Contributor

@hermanliang hermanliang Jun 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.pushTime(System.currentTimeMillis() / 1000 + 60*60*24*7*3)

@natario1 natario1 merged commit 657a478 into parse-community:master Jun 3, 2017
@natario1 natario1 deleted the push-time branch June 3, 2017 10:52
Copy link
Contributor

@flovilmart flovilmart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m not sure you should have implemented that here are client push is disabled unless using masterKey

@natario1
Copy link
Contributor Author

Ah, I didn't think about it 🙄 I just wanted to address a very old issue and get on par with iOS. It should do no harm though

@flovilmart
Copy link
Contributor

Yeah, people may think that 1 we can send push from the clien SDK’s without the master key, and 2 push scheduling is fully supported (only partially IIRC)

@natario1
Copy link
Contributor Author

Yeah, I think you remember correctly, my bad. I also didn't take it into account in the docs PR here where I just wanted docs to be on par with other clients SDK docs. Same story.

@flovilmart should we officially mark as deprecated all the ParsePush.send() stuff, or do you expect that some day there might be an option in parse-server that allows client pushing?

@flovilmart
Copy link
Contributor

Enabling client push is dangerous, and already was in 2014, the recommendation from the Parse team was to disable it: http://blog.parse.com/learn/engineering/the-dangerous-world-of-client-push/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants