Servers: Add edit route. Ability to set icon / banner.

This commit is contained in:
Paul
2021-06-01 17:42:23 +01:00
parent bff72fa6c3
commit 6bb4501c52
9 changed files with 181 additions and 32 deletions

View File

@@ -6,7 +6,7 @@ use crate::{
util::result::{Error, Result},
};
use futures::StreamExt;
use mongodb::bson::{doc, from_document, Document};
use mongodb::bson::{doc, from_document};
pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
let mut user_ids: HashSet<String> = HashSet::new();
@@ -19,30 +19,7 @@ pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
);
}
let server_ids = get_collection("server_members")
.find(
doc! {
"_id.user": &user.id
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "find",
with: "server_members",
})?
.filter_map(async move |s| s.ok())
.collect::<Vec<Document>>()
.await
.into_iter()
.filter_map(|x| {
x.get_document("_id")
.ok()
.map(|i| i.get_str("server").ok().map(|x| x.to_string()))
})
.flatten()
.collect::<Vec<String>>();
let server_ids = user.fetch_server_ids().await?;
let mut cursor = get_collection("servers")
.find(
doc! {

View File

@@ -45,7 +45,14 @@ pub async fn generate_subscriptions(user: &User) -> Result<(), String> {
}
}
// ! FIXME: fetch memberships for servers
let server_ids = user
.fetch_server_ids()
.await
.map_err(|_| "Failed to fetch memberships.".to_string())?;
for id in server_ids {
hive.subscribe(user.id.clone(), id)?;
}
Ok(())
}