summaryrefslogtreecommitdiff
path: root/src/test/webpush.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2025-11-08 16:28:10 -0500
committerOwen Jacobson <owen@grimoire.ca>2025-11-08 16:28:10 -0500
commitfc6914831743f6d683c59adb367479defe6f8b3a (patch)
tree5b997adac55f47b52f30022013b8ec3b2c10bcc5 /src/test/webpush.rs
parent0ef69c7d256380e660edc45ace7f1d6151226340 (diff)
parent6bab5b4405c9adafb2ce76540595a62eea80acc0 (diff)
Integrate the prototype push notification support.
We're going to move forwards with this for now, as low-utility as it is, so that we can more easily iterate on it in a real-world environment (hi.grimoire.ca).
Diffstat (limited to 'src/test/webpush.rs')
-rw-r--r--src/test/webpush.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/test/webpush.rs b/src/test/webpush.rs
new file mode 100644
index 0000000..c86d03f
--- /dev/null
+++ b/src/test/webpush.rs
@@ -0,0 +1,37 @@
+use std::{
+ mem,
+ sync::{Arc, Mutex},
+};
+
+use web_push::{WebPushClient, WebPushError, WebPushMessage};
+
+#[derive(Clone)]
+pub struct Client {
+ sent: Arc<Mutex<Vec<WebPushMessage>>>,
+}
+
+impl Client {
+ pub fn new() -> Self {
+ Self {
+ sent: Arc::default(),
+ }
+ }
+
+ // Clears the list of sent messages (for all clones of this Client) when called, because we
+ // can't clone `WebPushMessage`s so we either need to move them or try to reconstruct them,
+ // either of which sucks but moving them sucks less.
+ pub fn sent(&self) -> Vec<WebPushMessage> {
+ let mut sent = self.sent.lock().unwrap();
+ mem::replace(&mut *sent, Vec::new())
+ }
+}
+
+#[async_trait::async_trait]
+impl WebPushClient for Client {
+ async fn send(&self, message: WebPushMessage) -> Result<(), WebPushError> {
+ let mut sent = self.sent.lock().unwrap();
+ sent.push(message);
+
+ Ok(())
+ }
+}