feat(users): implement relationships, DMs, proper perms

This commit is contained in:
Paul Makles
2022-02-04 13:38:24 +00:00
parent 63064cc9bb
commit 1aafa51033
11 changed files with 117 additions and 77 deletions

View File

@@ -1,11 +1,22 @@
use revolt_quark::{Error, Result};
//! Fetch IDs of servers and friends that are mutually shared between the
//! authenticated user and the target user
use futures::StreamExt;
use mongodb::bson::{doc, Document};
use mongodb::options::FindOptions;
use revolt_quark::models::User;
use revolt_quark::{Error, Result, perms, Database, Ref};
use rocket::State;
use rocket::serde::json::Value;
#[get("/<target>/mutual")]
pub async fn req(/*user: UserRef, target: Ref*/ target: String) -> Result<Value> {
todo!()
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Value> {
let target = target.as_user(db).await?;
if perms(&user).user(&target).calc_user(db).await.get_view_profile() {
Ok(json!({
"users": db.fetch_mutual_user_ids(&user.id, &target.id).await?,
"servers": db.fetch_mutual_server_ids(&user.id, &target.id).await?
}))
} else {
Err(Error::NotFound)
}
}