Servers: Add invites. Create, view and join.

This commit is contained in:
Paul
2021-06-03 20:00:08 +01:00
parent 812fa2a98f
commit 681b2b8ab6
21 changed files with 335 additions and 81 deletions

View File

@@ -18,6 +18,7 @@ pub struct Data {
#[post("/create", data = "<info>")]
pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
let info = info.into_inner();
info.validate()
.map_err(|error| Error::FailedValidation { error })?;
@@ -41,26 +42,24 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
let id = Ulid::new().to_string();
let cid = Ulid::new().to_string();
get_collection("server_members")
.insert_one(
doc! {
"_id": {
"server": &id,
"user": &user.id
}
},
None,
)
.await
.map_err(|_| Error::DatabaseError {
operation: "insert_one",
with: "server_members",
})?;
let server = Server {
id: id.clone(),
nonce: Some(info.nonce.clone()),
owner: user.id.clone(),
name: info.name,
channels: vec![cid.clone()],
icon: None,
banner: None,
};
server.join_member(&user.id).await?;
Channel::TextChannel {
id: cid.clone(),
server: id.clone(),
nonce: Some(info.nonce.clone()),
id: cid,
server: id,
nonce: Some(info.nonce),
name: "general".to_string(),
description: None,
icon: None,
@@ -68,18 +67,6 @@ pub async fn req(user: User, info: Json<Data>) -> Result<JsonValue> {
.publish()
.await?;
let server = Server {
id: id.clone(),
nonce: Some(info.nonce.clone()),
owner: user.id.clone(),
name: info.name.clone(),
channels: vec![cid],
icon: None,
banner: None,
};
server.clone().publish().await?;
Ok(json!(server))