feat: implement channel invites, perms, group create, members fetch

chore: when you accidentally run fmt
This commit is contained in:
Paul Makles
2022-02-04 21:50:30 +00:00
parent b58755dbeb
commit 88f811761b
59 changed files with 536 additions and 195 deletions

View File

@@ -1,17 +1,25 @@
use revolt_quark::Result;
use revolt_quark::{
models::{Invite, User},
perms, ChannelPermission, Db, Error, Ref, Result,
};
use mongodb::bson::doc;
use rocket::serde::json::Value;
lazy_static! {
static ref ALPHABET: [char; 54] = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'J', 'K', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z'
];
}
use rocket::serde::json::Json;
#[post("/<target>/invites")]
pub async fn req(/*user: UserRef, target: Ref*/ target: String) -> Result<Value> {
todo!()
pub async fn req(db: &Db, user: User, target: Ref) -> Result<Json<Invite>> {
let channel = target.as_channel(db).await?;
if !perms(&user)
.channel(&channel)
.calc_channel(db)
.await
.get_invite_others()
{
return Err(Error::MissingPermission {
permission: ChannelPermission::InviteOthers as i32,
});
}
Invite::create(db, &user, &channel).await.map(Json)
}