forked from jmug/stoatchat
Refractor WS; remove - fom names.
This commit is contained in:
@@ -1,14 +1,6 @@
|
||||
use crate::database::get_collection;
|
||||
use crate::database::guards::reference::Ref;
|
||||
use crate::{
|
||||
database::get_collection,
|
||||
notifications::events::ClientboundNotification,
|
||||
util::result::{Error, Result},
|
||||
};
|
||||
use futures::StreamExt;
|
||||
use mongodb::{
|
||||
bson::{doc, from_bson, Bson},
|
||||
options::FindOptions,
|
||||
};
|
||||
use mongodb::bson::{doc, from_bson, Bson};
|
||||
use rauth::auth::Session;
|
||||
use rocket::http::Status;
|
||||
use rocket::request::{self, FromRequest, Outcome, Request};
|
||||
@@ -81,57 +73,4 @@ impl User {
|
||||
id: self.id.to_string(),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn generate_ready_payload(self) -> Result<ClientboundNotification> {
|
||||
let mut users = vec![];
|
||||
|
||||
if let Some(relationships) = &self.relations {
|
||||
let user_ids: Vec<String> = relationships
|
||||
.iter()
|
||||
.map(|relationship| relationship.id.clone())
|
||||
.collect();
|
||||
|
||||
let mut cursor = get_collection("users")
|
||||
.find(
|
||||
doc! {
|
||||
"_id": {
|
||||
"$in": user_ids
|
||||
}
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(doc! { "_id": 1, "username": 1 })
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "find",
|
||||
with: "users",
|
||||
})?;
|
||||
|
||||
while let Some(result) = cursor.next().await {
|
||||
if let Ok(doc) = result {
|
||||
let mut user: User =
|
||||
from_bson(Bson::Document(doc)).map_err(|_| Error::DatabaseError {
|
||||
operation: "from_bson",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
user.relationship = Some(
|
||||
relationships
|
||||
.iter()
|
||||
.find(|x| user.id == x.id)
|
||||
.ok_or_else(|| Error::InternalError)?
|
||||
.status
|
||||
.clone(),
|
||||
);
|
||||
|
||||
users.push(user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
users.push(self);
|
||||
|
||||
Ok(ClientboundNotification::Ready { users })
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user