You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.all(|c| c.is_ascii_alphanumeric() || c == '_' || c == ':' || c == '-')
134
+
{
135
+
returnOk(StatusCode::GONE);
136
+
}
137
+
138
+
let url = "https://push.ubports.com/notify";
139
+
let expire_on = (Local::now() + TimeDelta::weeks(1)).to_rfc3339();
140
+
let body = format!(
141
+
r#"{{"expire_on":"{expire_on}","appid":"deltatouch.lotharketterer_deltatouch","token":"{token}","data":{{"notification":{{"tag":"sent_by_chatmail_server","card":{{"popup":true,"persist":true,"summary":"New message","body":"You have a new message"}},"sound":true,"vibrate":{{"pattern":[200],"duration":200,"repeat":1}} }},"sent-by":"Chatmail Server"}} }}"#
142
+
);
143
+
let res = client
144
+
.post(url)
145
+
.body(body.clone())
146
+
.header("Content-Type","application/json")
147
+
.send()
148
+
.await?;
149
+
let status = res.status();
150
+
if status.is_client_error(){
151
+
warn!("Failed to deliver UBports notification to {token}");
152
+
warn!("BODY: {body:?}");
153
+
warn!("RES: {res:?}");
154
+
returnOk(StatusCode::GONE);
155
+
}
156
+
if status.is_server_error(){
157
+
warn!("Internal server error while attempting to deliver UBports notification to {token}");
158
+
returnOk(StatusCode::INTERNAL_SERVER_ERROR);
159
+
}
160
+
info!("Delivered notification to UBports token {token}");
161
+
metrics.ubports_notifications_total.inc();
162
+
Ok(StatusCode::OK)
163
+
}
164
+
116
165
/// Notifies a single FCM token.
117
166
///
118
167
/// API documentation is available at
@@ -247,6 +296,11 @@ async fn notify_device(
247
296
let device_token:NotificationToken = device_token.as_str().parse()?;
0 commit comments