Skip to content

Commit 4f86b2a

Browse files
author
Javen
committed
Add new feature: big push duration - push slowly
1 parent 1fa704c commit 4f86b2a

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/main/java/cn/jpush/api/push/model/Options.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,23 @@ public class Options implements PushModel {
1212
private static final String OVERRIDE_MSG_ID = "override_msg_id";
1313
private static final String TIME_TO_LIVE = "time_to_live";
1414
private static final String APNS_PRODUCTION = "apns_production";
15+
private static final String BIG_PUSH_DURATION = "big_push_duration";
1516

1617
private static final long NONE_TIME_TO_LIVE = -1;
1718

1819
private final int sendno;
1920
private final long overrideMsgId;
2021
private long timeToLive;
2122
private boolean apnsProduction;
23+
private int bigPushDuration; // minutes
2224

23-
private Options(int sendno, long overrideMsgId, long timeToLive, boolean apnsProduction) {
25+
private Options(int sendno, long overrideMsgId, long timeToLive, boolean apnsProduction,
26+
int bigPushDuration) {
2427
this.sendno = sendno;
2528
this.overrideMsgId = overrideMsgId;
2629
this.timeToLive = timeToLive;
2730
this.apnsProduction = apnsProduction;
31+
this.bigPushDuration = bigPushDuration;
2832
}
2933

3034
public static Builder newBuilder() {
@@ -47,6 +51,10 @@ public void setTimeToLive(long timeToLive) {
4751
this.timeToLive = timeToLive;
4852
}
4953

54+
public void setBigPushDuration(int bigPushDuration) {
55+
this.bigPushDuration = bigPushDuration;
56+
}
57+
5058
public int getSendno() {
5159
return this.sendno;
5260
}
@@ -66,6 +74,10 @@ public JsonElement toJSON() {
6674

6775
json.add(APNS_PRODUCTION, new JsonPrimitive(apnsProduction));
6876

77+
if (bigPushDuration > 0) {
78+
json.add(BIG_PUSH_DURATION, new JsonPrimitive(bigPushDuration));
79+
}
80+
6981
return json;
7082
}
7183

@@ -74,6 +86,7 @@ public static class Builder {
7486
private long overrideMsgId = 0;
7587
private long timeToLive = NONE_TIME_TO_LIVE;
7688
private boolean apnsProduction = false;
89+
private int bigPushDuration = 0;
7790

7891
public Builder setSendno(int sendno) {
7992
this.sendno = sendno;
@@ -95,15 +108,21 @@ public Builder setApnsProduction(boolean apnsProduction) {
95108
return this;
96109
}
97110

111+
public Builder setBigPushDuration(int bigPushDuration) {
112+
this.bigPushDuration = bigPushDuration;
113+
return this;
114+
}
115+
98116
public Options build() {
99117
Preconditions.checkArgument(sendno >= 0, "sendno should be greater than 0.");
100118
Preconditions.checkArgument(overrideMsgId >= 0, "override_msg_id should be greater than 0.");
101119
Preconditions.checkArgument(timeToLive >= NONE_TIME_TO_LIVE, "time_to_live should be greater than 0.");
120+
Preconditions.checkArgument(bigPushDuration >= 0, "bigPushDuration should be greater than 0.");
102121
if (sendno <= 0) {
103122
sendno = ServiceHelper.generateSendno();
104123
}
105124

106-
return new Options(sendno, overrideMsgId, timeToLive, apnsProduction);
125+
return new Options(sendno, overrideMsgId, timeToLive, apnsProduction, bigPushDuration);
107126
}
108127
}
109128

src/test/java/cn/jpush/api/push/model/OptionsTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,19 @@ public void testApnsProduction_True() {
113113
assertThat(options.toJSON(), is((JsonElement) json));
114114
}
115115

116-
116+
@Test
117+
public void testBigPushDuration() {
118+
int sendno = ServiceHelper.generateSendno();
119+
Options options = Options.newBuilder()
120+
.setSendno(sendno)
121+
.setBigPushDuration(10)
122+
.build();
123+
124+
JsonObject json = new JsonObject();
125+
json.add("big_push_duration", new JsonPrimitive(11));
126+
json.add("sendno", new JsonPrimitive(sendno));
127+
128+
assertThat(options.toJSON(), is((JsonElement) json));
129+
}
117130
}
118131

0 commit comments

Comments
 (0)