|
1 | 1 | use std::io::Error; |
2 | 2 | use std::io::ErrorKind; |
3 | | - |
4 | 3 | use crate::pushover::constants; |
5 | 4 |
|
6 | 5 | use super::PushoverSound; |
@@ -126,6 +125,44 @@ impl AttachmentMessageBuilder { |
126 | 125 | /// Resets the priority to default (0, normal) |
127 | 126 | pub fn remove_priority(mut self) -> AttachmentMessageBuilder { |
128 | 127 | self.build.priority = Some("0".into()); |
| 128 | + self.build.retry = None; |
| 129 | + self.build.expire = None; |
| 130 | + self |
| 131 | + } |
| 132 | + |
| 133 | + /// When the priority is set to 2, sets the amount of seconds between each retries. Must be at least 30 seconds. |
| 134 | + pub fn set_retry(mut self, retry_secs: i32) -> AttachmentMessageBuilder { |
| 135 | + if self.build.priority != Some("2".into()) { |
| 136 | + // Retry only makes sense if priority is 2 |
| 137 | + return self; |
| 138 | + } |
| 139 | + |
| 140 | + if retry_secs < 30 { |
| 141 | + self.build.retry = Some("30".into()); |
| 142 | + return self; |
| 143 | + } |
| 144 | + |
| 145 | + self.build.retry = Some(retry_secs.to_string()); |
| 146 | + self |
| 147 | + } |
| 148 | + |
| 149 | + /// When the priority is set to 2, sets the amount of seconds before the notification is expired. The maximum value is 10800 (3 hours). Must be between 60 and 10800. |
| 150 | + pub fn set_expire(mut self, expire_secs: i32) -> AttachmentMessageBuilder { |
| 151 | + if self.build.priority != Some("2".into()) { |
| 152 | + // Expire only makes sense if priority is 2 |
| 153 | + return self; |
| 154 | + } |
| 155 | + |
| 156 | + if expire_secs < 60 { |
| 157 | + self.build.expire = Some("60".into()); |
| 158 | + return self; |
| 159 | + } |
| 160 | + else if expire_secs > 10800 { |
| 161 | + self.build.expire = Some("10800".into()); |
| 162 | + return self; |
| 163 | + } |
| 164 | + |
| 165 | + self.build.expire = Some(expire_secs.to_string()); |
129 | 166 | self |
130 | 167 | } |
131 | 168 |
|
@@ -195,7 +232,16 @@ impl AttachmentMessageBuilder { |
195 | 232 | } |
196 | 233 |
|
197 | 234 | /// Transforms the MessageBuilder into a useable Message |
198 | | - pub fn build(self) -> Result<AttachmentMessage, Box<dyn std::error::Error>> { |
| 235 | + pub fn build(mut self) -> Result<AttachmentMessage, Box<dyn std::error::Error>> { |
| 236 | + if self.build.priority == Some("2".into()) { |
| 237 | + if self.build.retry.is_none() { |
| 238 | + self.build.retry = Some("30".into()); |
| 239 | + } |
| 240 | + if self.build.expire.is_none() { |
| 241 | + self.build.expire = Some("10800".into()); |
| 242 | + } |
| 243 | + } |
| 244 | + |
199 | 245 | if self.build.app_token.is_empty() { |
200 | 246 | return Err(Box::new(Error::new(ErrorKind::InvalidInput, "Application token is empty"))); |
201 | 247 | } |
|
0 commit comments