From 901b29f49e74510429ed6b4d76f75da3f8f397a1 Mon Sep 17 00:00:00 2001
From: Paul Makles <paulmakles@gmail.com>
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 797514b..23f964d 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 6b2e517..5dbe89d 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<String>
+    users: Vec<String>,
 }
 
 #[post("/create", data = "<info>")]
 pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
-    info
-        .validate()
+    info.validate()
         .map_err(|error| Error::FailedValidation { error })?;
-    
+
     let mut set: HashSet<String> = 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<Data>) -> Result<JsonValue> {
         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::<Vec<String>>()
+        recipients: set.into_iter().collect::<Vec<String>>(),
     };
 
     channel.clone().publish().await?;
diff --git a/src/routes/channels/message_send.rs b/src/routes/channels/message_send.rs
index 3220d99..ae06890 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<Data>) -> Result<JsonVal
         nonce: Some(message.nonce.clone()),
         edited: None,
     };
-    
-    msg
-        .clone()
-        .publish()
-        .await?;
+
+    msg.clone().publish().await?;
 
     Ok(json!(msg))
 }
diff --git a/src/routes/channels/mod.rs b/src/routes/channels/mod.rs
index f2a2f7e..4c9d5a8 100644
--- a/src/routes/channels/mod.rs
+++ b/src/routes/channels/mod.rs
@@ -2,12 +2,12 @@ use rocket::Route;
 
 mod delete_channel;
 mod fetch_channel;
+mod group_create;
 mod message_delete;
 mod message_edit;
 mod message_fetch;
 mod message_query;
 mod message_send;
-mod group_create;
 
 pub fn routes() -> Vec<Route> {
     routes![
diff --git a/src/util/result.rs b/src/util/result.rs
index 5bf66c7..0de30d8 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,
-- 
GitLab