diff --git a/Cargo.lock b/Cargo.lock index d0b7d221abf39fd5215ca79862a5807d74b99d8a..7682ea68416046396a158930bf234b31d047162e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2473,7 +2473,7 @@ dependencies = [ [[package]] name = "revolt" -version = "0.3.3-alpha.6" +version = "0.3.3-alpha.7" dependencies = [ "async-std", "async-tungstenite", diff --git a/Cargo.toml b/Cargo.toml index b02ce5c0cf0cc3ea8a39137809604ad9f9753ec5..b43a5be13af05e05af10e1e77ef7e56f3c6b653c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt" -version = "0.3.3-alpha.6" +version = "0.3.3-alpha.7" authors = ["Paul Makles <paulmakles@gmail.com>"] edition = "2018" diff --git a/src/database/entities/message.rs b/src/database/entities/message.rs index aaf5f484406f81c04e3f723ca5c962d7390a4e7b..9fbffd3113bf388db167d5a4505722ff6102de11 100644 --- a/src/database/entities/message.rs +++ b/src/database/entities/message.rs @@ -13,7 +13,9 @@ use mongodb::{ use rocket_contrib::json::JsonValue; use serde::{Deserialize, Serialize}; use ulid::Ulid; -use web_push::{ContentEncoding, SubscriptionInfo, VapidSignatureBuilder, WebPushClient, WebPushMessageBuilder}; +use web_push::{ + ContentEncoding, SubscriptionInfo, VapidSignatureBuilder, WebPushClient, WebPushMessageBuilder, +}; #[derive(Serialize, Deserialize, Debug, Clone)] pub struct Message { @@ -171,7 +173,8 @@ impl Message { for subscription in subscriptions { let mut builder = WebPushMessageBuilder::new(&subscription).unwrap(); let sig_builder = - VapidSignatureBuilder::from_pem(std::io::Cursor::new(&key), &subscription).unwrap(); + VapidSignatureBuilder::from_pem(std::io::Cursor::new(&key), &subscription) + .unwrap(); let signature = sig_builder.build().unwrap(); builder.set_vapid_signature(signature); builder.set_payload(ContentEncoding::AesGcm, enc.as_bytes()); diff --git a/src/routes/push/subscribe.rs b/src/routes/push/subscribe.rs index 57d30a3541ef55300b703c8b78e0ec3959773cc3..d2a060472f604ec098728d19735856f0f88ac4df 100644 --- a/src/routes/push/subscribe.rs +++ b/src/routes/push/subscribe.rs @@ -16,7 +16,7 @@ pub struct Subscription { #[post("/subscribe", data = "<data>")] pub async fn req(session: Session, data: Json<Subscription>) -> Result<()> { let data = data.into_inner(); - let col = get_collection("accounts") + get_collection("accounts") .update_one( doc! { "_id": session.user_id, @@ -24,13 +24,14 @@ pub async fn req(session: Session, data: Json<Subscription>) -> Result<()> { }, doc! { "$set": { - "sessions.$.subscription": to_document(&data).unwrap() + "sessions.$.subscription": to_document(&data) + .map_err(|_| Error::DatabaseError { operation: "to_document", with: "subscription" })? } }, None, ) .await - .unwrap(); + .map_err(|_| Error::DatabaseError { operation: "update_one", with: "account" })?; Ok(()) } diff --git a/src/routes/push/unsubscribe.rs b/src/routes/push/unsubscribe.rs index deb1026d4b3ab60f04816e13888b54b04c208981..41634e7bdda2ef1107cd12134f1ee8287d8f2f43 100644 --- a/src/routes/push/unsubscribe.rs +++ b/src/routes/push/unsubscribe.rs @@ -6,7 +6,7 @@ use rauth::auth::Session; #[post("/unsubscribe")] pub async fn req(session: Session) -> Result<()> { - let col = get_collection("accounts") + get_collection("accounts") .update_one( doc! { "_id": session.user_id, @@ -20,7 +20,10 @@ pub async fn req(session: Session) -> Result<()> { None, ) .await - .unwrap(); + .map_err(|_| Error::DatabaseError { + operation: "to_document", + with: "subscription", + })?; Ok(()) } diff --git a/src/routes/root.rs b/src/routes/root.rs index 23f276901ff9c38de5546c103b76bbfbef2ca01b..9fc8e1c7f9985c0828a09f14b1acffdf17394b27 100644 --- a/src/routes/root.rs +++ b/src/routes/root.rs @@ -9,7 +9,7 @@ use rocket_contrib::json::JsonValue; #[get("/")] pub async fn root() -> JsonValue { json!({ - "revolt": "0.3.3-alpha.6", + "revolt": "0.3.3-alpha.7", "features": { "registration": !*DISABLE_REGISTRATION, "captcha": { diff --git a/src/util/variables.rs b/src/util/variables.rs index 6431673acd6901c2f6aff381c08c10328af7c3d2..19b72491eb9b4be5ddb38ab53a89fbb8a550d0d5 100644 --- a/src/util/variables.rs +++ b/src/util/variables.rs @@ -52,8 +52,6 @@ lazy_static! { // Application Logic Settings pub static ref MAX_GROUP_SIZE: usize = env::var("REVOLT_MAX_GROUP_SIZE").unwrap_or_else(|_| "50".to_string()).parse().unwrap(); - pub static ref PUSH_LIMIT: usize = - env::var("REVOLT_PUSH_LIMIT").unwrap_or_else(|_| "50".to_string()).parse().unwrap(); } pub fn preflight_checks() {