Skip to content

Commit d4d339b

Browse files
committed
Improve message builder documentation (fixes #77)
1 parent 8de73e2 commit d4d339b

1 file changed

Lines changed: 22 additions & 12 deletions

File tree

src/message.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ impl Display for Urgency {
8686
pub struct WebPushMessage {
8787
/// The endpoint URI where to send the payload.
8888
pub endpoint: Uri,
89-
/// Time to live, how long the message should wait in the server if user is
90-
/// not online. Some services require this value to be set.
89+
/// Maximum time to live in seconds. Determines how long the message should
90+
/// be retained by the push server if the user is not online.
9191
pub ttl: u32,
92-
/// The urgency of the message (very-low | low | normal | high)
92+
/// The urgency of the message.
9393
pub urgency: Option<Urgency>,
94-
/// The topic of the mssage
94+
/// The topic of the mssage.
9595
pub topic: Option<String>,
9696
/// The encrypted request payload, if sending any data.
9797
pub payload: Option<WebPushPayload>,
@@ -128,18 +128,26 @@ impl<'a> WebPushMessageBuilder<'a> {
128128
}
129129
}
130130

131-
/// How long the server should keep the message if it cannot be delivered
132-
/// currently. If not set, the message is deleted immediately on failed
133-
/// delivery.
134-
pub fn set_ttl(&mut self, ttl: u32) {
135-
self.ttl = ttl;
131+
/// Maximum time to live in seconds. Determines how long the message should
132+
/// be retained by the push server if the user is not online for delivery.
133+
///
134+
/// Some services may not accurately account for TTL or choose to retain
135+
/// messages for a shorter duration.
136+
///
137+
/// A TTL of 0 seconds is valid and the message is delivered only if the
138+
/// user is immediately available for delivery.
139+
///
140+
/// Defaults to 28 days.
141+
pub fn set_ttl(&mut self, seconds: u32) {
142+
self.ttl = seconds;
136143
}
137144

138145
/// Urgency indicates to the push service how important a message is to the
139146
/// user. This can be used by the push service to help conserve the battery
140147
/// life of a user's device by only waking up for important messages when
141148
/// battery is low.
142-
/// Possible values are 'very-low', 'low', 'normal' and 'high'.
149+
///
150+
/// Defaults to not specify an urgency.
143151
pub fn set_urgency(&mut self, urgency: Urgency) {
144152
self.urgency = Some(urgency);
145153
}
@@ -152,20 +160,22 @@ impl<'a> WebPushMessageBuilder<'a> {
152160
/// user agent. A message with a topic replaces any outstanding push
153161
/// messages with an identical topic. It is an arbitrary string
154162
/// consisting of at most 32 base64url characters.
163+
///
164+
/// Defaults to not specify a topic.
155165
pub fn set_topic(&mut self, topic: String) {
156166
self.topic = Some(topic);
157167
}
158168

159169
/// Add a VAPID signature to the request. To be generated with the
160-
/// [VapidSignatureBuilder](struct.VapidSignatureBuilder.html).
170+
/// [`VapidSignatureBuilder`](struct.VapidSignatureBuilder.html).
161171
pub fn set_vapid_signature(&mut self, vapid_signature: VapidSignature) {
162172
self.vapid_signature = Some(vapid_signature);
163173
}
164174

165175
/// If set, the client will get content in the notification. Has a maximum size of
166176
/// 3800 characters.
167177
///
168-
/// Aes128gcm is preferred, if the browser supports it.
178+
/// `Aes128Gcm` is preferred, if the browser supports it.
169179
pub fn set_payload(&mut self, encoding: ContentEncoding, content: &'a [u8]) {
170180
self.payload = Some(WebPushPayloadBuilder { content, encoding });
171181
}

0 commit comments

Comments
 (0)