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,8 +1,31 @@
use revolt_quark::Result;
use revolt_quark::{
models::{Channel, User},
perms, Db, Error, Ref, Result,
};
use rocket::serde::json::Value;
use rocket::serde::json::Json;
#[get("/<target>/members")]
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<Vec<User>>> {
let channel = target.as_channel(db).await?;
if !perms(&user)
.channel(&channel)
.calc_channel(db)
.await
.get_view()
{
return Err(Error::NotFound);
}
if let Channel::Group { recipients, .. } = channel {
Ok(Json(
db.fetch_users(&recipients)
.await?
.into_iter()
.map(|x| x.with_relationship(&user))
.collect::<Vec<User>>(),
))
} else {
Err(Error::InvalidOperation)
}
}