forked from jmug/stoatchat
Run cargo fmt
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -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?;
|
||||
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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![
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user