Push env variables to rAuth + cargo fmt.

This commit is contained in:
Paul Makles
2021-01-26 17:29:03 +00:00
parent abd8b1821d
commit 23ec2d61f1
10 changed files with 94 additions and 56 deletions

View File

@@ -79,8 +79,12 @@ impl Channel {
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
let id = self.id().to_string();
ClientboundNotification::ChannelUpdate {
id: id.clone(), data
}.publish(id).await.ok();
id: id.clone(),
data,
}
.publish(id)
.await
.ok();
Ok(())
}

View File

@@ -48,46 +48,48 @@ impl Message {
let channels = get_collection("channels");
match channel {
Channel::DirectMessage { id, .. } => {
channels.update_one(
doc! { "_id": id },
doc! {
"$set": {
"active": true,
"last_message": {
"_id": self.id.clone(),
"author": self.author.clone(),
"short": self.content.chars().take(24).collect::<String>()
channels
.update_one(
doc! { "_id": id },
doc! {
"$set": {
"active": true,
"last_message": {
"_id": self.id.clone(),
"author": self.author.clone(),
"short": self.content.chars().take(24).collect::<String>()
}
}
}
},
None
)
.await
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "channel",
})?;
},
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "channel",
})?;
}
Channel::Group { id, .. } => {
channels.update_one(
doc! { "_id": id },
doc! {
"$set": {
"last_message": {
"_id": self.id.clone(),
"author": self.author.clone(),
"short": self.content.chars().take(24).collect::<String>()
channels
.update_one(
doc! { "_id": id },
doc! {
"$set": {
"last_message": {
"_id": self.id.clone(),
"author": self.author.clone(),
"short": self.content.chars().take(24).collect::<String>()
}
}
}
},
None
)
.await
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "channel",
})?;
},
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "update_one",
with: "channel",
})?;
}
_ => {}
}
@@ -102,8 +104,12 @@ impl Message {
pub async fn publish_update(&self, data: JsonValue) -> Result<()> {
let channel = self.channel.clone();
ClientboundNotification::MessageUpdate {
id: self.id.clone(), data
}.publish(channel).await.ok();
id: self.id.clone(),
data,
}
.publish(channel)
.await
.ok();
Ok(())
}

View File

@@ -29,7 +29,10 @@ impl<'a, 'r> FromRequest<'a, 'r> for User {
} else {
Outcome::Failure((
Status::InternalServerError,
rauth::util::Error::DatabaseError { operation: "find_one", with: "user" },
rauth::util::Error::DatabaseError {
operation: "find_one",
with: "user",
},
))
}
}

View File

@@ -1,9 +1,7 @@
use super::super::{get_collection, get_db};
use crate::database::get_collection;
use crate::rocket::futures::StreamExt;
use log::info;
use mongodb::bson::{doc, from_document};
use mongodb::options::FindOptions;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]