Skip to content
This repository was archived by the owner on Oct 26, 2024. It is now read-only.

Commit cdfc3d8

Browse files
committed
Added support for setting X-WNS-Cache-Policy, X-WNS-RequestForStatus and X-WNS-TTL.
1 parent 474b76d commit cdfc3d8

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/main/java/com/notnoop/mpns/notifications/AbstractNotificationBuilder.java

+61
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,67 @@ public A notificationType(String type) {
103103
return (A)this;
104104
}
105105

106+
/**
107+
* Sets the X-WNS-TTL property.
108+
*
109+
* Specifies the TTL (expiration time) for a notification.
110+
* This is not typically needed, but can be used if you want to ensure that your notifications are not displayed
111+
* later than a certain time. The TTL is specified in seconds and is relative to the time that WNS receives the
112+
* request.
113+
*
114+
* When a TTL is specified, the device will not display the notification after that time.
115+
* Note that this could result in the notification never being shown at all if the TTL is too short.
116+
* In general, an expiration time will be measured in at least minutes.
117+
*
118+
* This header is optional.
119+
* If no value is specified, the notification does not expire and will be replaced under the normal notification
120+
* replacement scheme.
121+
*
122+
* @param ttl the life span of the notification, in seconds, after WNS receives the request.
123+
* @return this
124+
*/
125+
public A ttl(Long ttl) {
126+
this.headers.add(Pair.of("X-WNS-TTL", Long.toString(ttl)));
127+
return (A)this;
128+
}
129+
130+
/**
131+
* Sets the X-WNS-Cache-Policy property.
132+
*
133+
* When the notification target device is offline, WNS will cache one badge and one tile notification per app.
134+
* If notification cycling is enabled for the app, WNS will cache up to five tile notifications.
135+
* By default, raw notifications are not cached, but if raw notification caching is enabled,
136+
* one raw notification is cached.
137+
* Items are not held in the cache indefinitely and will be dropped after a reasonable period of time.
138+
* Otherwise, the cached content is delivered when the device next comes online.
139+
*
140+
* This header is optional and should be used only in cases where the cloud service wants to override the
141+
* default caching behavior
142+
*
143+
* @param enabled if true caching is enabled (default)
144+
* @return this
145+
*/
146+
public A cache(boolean enabled) {
147+
this.headers.add(Pair.of("X-WNS-Cache-Policy", enabled ? "cache" : "no-cache"));
148+
return (A)this;
149+
}
150+
151+
/**
152+
* Sets the X-WNS-RequestForStatus property.
153+
*
154+
* Specifies whether the response should include the device status and WNS connection status.
155+
*
156+
* The default value is false.
157+
*
158+
* @param enabled if true specifies that the response should include the device status and WNS connection status.
159+
* else, do not return the device status and notification status.
160+
* @return this
161+
*/
162+
public A requestForStatus(boolean enabled) {
163+
this.headers.add(Pair.of("X-WNS-RequestForStatus", enabled ? "true" : "false"));
164+
return (A)this;
165+
}
166+
106167
/**
107168
* Sets the notification channel URI that the registered callback message
108169
* will be sent to.

0 commit comments

Comments
 (0)