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

@@ -0,0 +1,31 @@
use crate::database::*;
use crate::util::result::Result;
use rocket_contrib::json::JsonValue;
#[post("/<target>")]
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
let target = target.fetch_invite().await?;
match target {
Invite::Server {
channel,
..
} => {
let channel = Ref::from_unchecked(channel).fetch_channel().await?;
let server = if let Channel::TextChannel { server, .. } = &channel {
Ref::from_unchecked(server.clone()).fetch_server().await?
} else {
unreachable!()
};
server.join_member(&user.id).await?;
Ok(json!({
"channel": channel,
"server": server
}))
}
_ => unreachable!(),
}
}