@@ -40,6 +40,14 @@ public class Notification {
40
40
*/
41
41
private Urgency urgency ;
42
42
43
+ /**
44
+ * Push Message Topic
45
+ *
46
+ * @see <a href="https://tools.ietf.org/html/rfc8030#section-5.4">Replacing Push Messages</a>
47
+ *
48
+ */
49
+ private String topic ;
50
+
43
51
/**
44
52
* Time in seconds that the push message is retained by the push service
45
53
*/
@@ -48,18 +56,18 @@ public class Notification {
48
56
private static final int ONE_DAY_DURATION_IN_SECONDS = 86400 ;
49
57
private static int DEFAULT_TTL = 28 * ONE_DAY_DURATION_IN_SECONDS ;
50
58
51
-
52
- public Notification (String endpoint , ECPublicKey userPublicKey , byte [] userAuth , byte [] payload , int ttl , Urgency urgency ) {
59
+ public Notification (String endpoint , ECPublicKey userPublicKey , byte [] userAuth , byte [] payload , int ttl , Urgency urgency , String topic ) {
53
60
this .endpoint = endpoint ;
54
61
this .userPublicKey = userPublicKey ;
55
62
this .userAuth = userAuth ;
56
63
this .payload = payload ;
57
64
this .ttl = ttl ;
58
65
this .urgency = urgency ;
66
+ this .topic = topic ;
59
67
}
60
68
61
69
public Notification (String endpoint , PublicKey userPublicKey , byte [] userAuth , byte [] payload , int ttl ) {
62
- this (endpoint , (ECPublicKey ) userPublicKey , userAuth , payload , ttl , null );
70
+ this (endpoint , (ECPublicKey ) userPublicKey , userAuth , payload , ttl , null , null );
63
71
}
64
72
65
73
public Notification (String endpoint , String userPublicKey , String userAuth , byte [] payload , int ttl ) throws NoSuchAlgorithmException , NoSuchProviderException , InvalidKeySpecException {
@@ -116,6 +124,10 @@ public boolean hasUrgency() {
116
124
return urgency != null ;
117
125
}
118
126
127
+ public boolean hasTopic () {
128
+ return topic != null ;
129
+ }
130
+
119
131
/**
120
132
* Detect if the notification is for a GCM-based subscription
121
133
*
@@ -137,6 +149,10 @@ public Urgency getUrgency() {
137
149
return urgency ;
138
150
}
139
151
152
+ public String getTopic () {
153
+ return topic ;
154
+ }
155
+
140
156
public String getOrigin () throws MalformedURLException {
141
157
URL url = new URL (getEndpoint ());
142
158
@@ -153,12 +169,14 @@ public static class NotificationBuilder {
153
169
private byte [] userAuth = null ;
154
170
private byte [] payload = null ;
155
171
private int ttl = DEFAULT_TTL ;
172
+ private Urgency urgency = null ;
173
+ private String topic = null ;
156
174
157
175
private NotificationBuilder () {
158
176
}
159
177
160
178
public Notification build () {
161
- return new Notification (endpoint , userPublicKey , userAuth , payload , ttl );
179
+ return new Notification (endpoint , userPublicKey , userAuth , payload , ttl , urgency , topic );
162
180
}
163
181
164
182
public NotificationBuilder endpoint (String endpoint ) {
@@ -191,10 +209,25 @@ public NotificationBuilder payload(byte[] payload) {
191
209
return this ;
192
210
}
193
211
212
+ public NotificationBuilder payload (String payload ) {
213
+ this .payload = payload .getBytes (UTF_8 );
214
+ return this ;
215
+ }
216
+
194
217
public NotificationBuilder ttl (int ttl ) {
195
218
this .ttl = ttl ;
196
219
return this ;
197
220
}
221
+
222
+ public NotificationBuilder urgency (Urgency urgency ) {
223
+ this .urgency = urgency ;
224
+ return this ;
225
+ }
226
+
227
+ public NotificationBuilder topic (String topic ) {
228
+ this .topic = topic ;
229
+ return this ;
230
+ }
198
231
}
199
232
200
233
}
0 commit comments