From 901b29f49e74510429ed6b4d76f75da3f8f397a1 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Mon, 18 Jan 2021 22:02:46 +0000 Subject: [PATCH] Run cargo fmt --- src/database/entities/channel.rs | 12 +++++++----- src/routes/channels/group_create.rs | 18 +++++++++++------- src/routes/channels/message_send.rs | 7 ++----- src/routes/channels/mod.rs | 2 +- src/util/result.rs | 8 +++----- 5 files changed, 24 insertions(+), 23 deletions(-) diff --git a/src/database/entities/channel.rs b/src/database/entities/channel.rs index 797514b5..23f964db 100644 --- a/src/database/entities/channel.rs +++ b/src/database/entities/channel.rs @@ -1,7 +1,10 @@ -use crate::{database::*, notifications::{events::ClientboundNotification, hive}}; use crate::util::result::{Error, Result}; -use serde::{Deserialize, Serialize}; +use crate::{ + database::*, + notifications::{events::ClientboundNotification, hive}, +}; use mongodb::bson::to_document; +use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] #[serde(tag = "type")] @@ -52,15 +55,14 @@ impl Channel { operation: "insert_one", with: "channel", })?; - + // ! IMPORTANT FIXME: THESE SUBSCRIPTIONS SHOULD BE DONE FROM HIVE NOT HERE!!! let channel_id = self.id().to_string(); match &self { Channel::SavedMessages { user, .. } => { hive::subscribe_if_exists(user.clone(), channel_id.clone()).ok(); } - Channel::DirectMessage { recipients, .. } | - Channel::Group { recipients, .. } => { + Channel::DirectMessage { recipients, .. } | Channel::Group { recipients, .. } => { for recipient in recipients { hive::subscribe_if_exists(recipient.clone(), channel_id.clone()).ok(); } diff --git a/src/routes/channels/group_create.rs b/src/routes/channels/group_create.rs index 6b2e517e..5dbe89d6 100644 --- a/src/routes/channels/group_create.rs +++ b/src/routes/channels/group_create.rs @@ -19,20 +19,21 @@ pub struct Data { // Maximum length of 36 allows both ULIDs and UUIDs. #[validate(length(min = 1, max = 36))] nonce: String, - users: Vec + users: Vec, } #[post("/create", data = "")] pub async fn req(user: User, info: Json) -> Result { - info - .validate() + info.validate() .map_err(|error| Error::FailedValidation { error })?; - + let mut set: HashSet = HashSet::from_iter(info.users.iter().cloned()); set.insert(user.id.clone()); if set.len() > *MAX_GROUP_SIZE { - Err(Error::GroupTooLarge { max: *MAX_GROUP_SIZE })? + Err(Error::GroupTooLarge { + max: *MAX_GROUP_SIZE, + })? } if get_collection("channels") @@ -63,9 +64,12 @@ pub async fn req(user: User, info: Json) -> Result { id, nonce: Some(info.nonce.clone()), name: info.name.clone(), - description: info.description.clone().unwrap_or_else(|| "A group.".to_string()), + description: info + .description + .clone() + .unwrap_or_else(|| "A group.".to_string()), owner: user.id, - recipients: set.into_iter().collect::>() + recipients: set.into_iter().collect::>(), }; channel.clone().publish().await?; diff --git a/src/routes/channels/message_send.rs b/src/routes/channels/message_send.rs index 3220d992..ae06890f 100644 --- a/src/routes/channels/message_send.rs +++ b/src/routes/channels/message_send.rs @@ -55,11 +55,8 @@ pub async fn req(user: User, target: Ref, message: Json) -> Result Vec { routes![ diff --git a/src/util/result.rs b/src/util/result.rs index 5bf66c7b..0de30d8c 100644 --- a/src/util/result.rs +++ b/src/util/result.rs @@ -37,10 +37,8 @@ pub enum Error { #[snafu(display("Cannot edit someone else's message."))] CannotEditMessage, #[snafu(display("Group size is too large."))] - GroupTooLarge { - max: usize - }, - + GroupTooLarge { max: usize }, + // ? General errors. #[snafu(display("Failed to validate fields."))] FailedValidation { error: ValidationErrors }, @@ -77,7 +75,7 @@ impl<'r> Responder<'r, 'static> for Error { Error::CannotEditMessage => Status::Forbidden, Error::GroupTooLarge { .. } => Status::Forbidden, - + Error::FailedValidation { .. } => Status::UnprocessableEntity, Error::DatabaseError { .. } => Status::InternalServerError, Error::InternalError => Status::InternalServerError,