Fetch profile route, push badges and status.

This commit is contained in:
Paul
2021-04-02 21:55:02 +01:00
parent 3797878d20
commit 78c42fd412
8 changed files with 56 additions and 6 deletions

4
Cargo.lock generated
View File

@@ -1068,6 +1068,8 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
[[package]] [[package]]
name = "hive_pubsub" name = "hive_pubsub"
version = "0.4.4" version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2ac4635b1e9faf304ccb33c2f0edbc615030e40d249183281fc788ef20ef5c76"
dependencies = [ dependencies = [
"futures", "futures",
"many-to-many", "many-to-many",
@@ -2473,7 +2475,7 @@ dependencies = [
[[package]] [[package]]
name = "revolt" name = "revolt"
version = "0.4.0-alpha.2" version = "0.4.0-alpha.3"
dependencies = [ dependencies = [
"async-std", "async-std",
"async-tungstenite", "async-tungstenite",

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "revolt" name = "revolt"
version = "0.4.0-alpha.2" version = "0.4.0-alpha.3"
authors = ["Paul Makles <paulmakles@gmail.com>"] authors = ["Paul Makles <paulmakles@gmail.com>"]
edition = "2018" edition = "2018"

View File

@@ -25,6 +25,20 @@ pub struct Relationship {
pub status: RelationshipStatus, pub status: RelationshipStatus,
} }
/*
pub enum Badge {
Developer = 1
}
*/
#[derive(Serialize, Deserialize, Debug)]
#[serde(tag = "type")]
pub enum UserStatus {
Text {
text: String
}
}
#[derive(Serialize, Deserialize, Debug)] #[derive(Serialize, Deserialize, Debug)]
pub struct User { pub struct User {
#[serde(rename = "_id")] #[serde(rename = "_id")]
@@ -33,6 +47,13 @@ pub struct User {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub relations: Option<Vec<Relationship>>, pub relations: Option<Vec<Relationship>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub badges: Option<i32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub status: Option<Vec<UserStatus>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub profile: Option<String>,
// ? This should never be pushed to the collection. // ? This should never be pushed to the collection.
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub relationship: Option<RelationshipStatus>, pub relationship: Option<RelationshipStatus>,
@@ -65,6 +86,7 @@ impl User {
self.online = Some(is_online(&self.id)); self.online = Some(is_online(&self.id));
} }
self.profile = None;
self self
} }
@@ -73,7 +95,7 @@ impl User {
if username == "revolt" && username == "admin" { if username == "revolt" && username == "admin" {
return Ok(true) return Ok(true)
} }
if get_collection("users") if get_collection("users")
.find_one( .find_one(
doc! { doc! {

View File

@@ -77,7 +77,7 @@ pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
} }
}, },
FindOptions::builder() FindOptions::builder()
.projection(doc! { "_id": 1, "username": 1 }) .projection(doc! { "_id": 1, "username": 1, "badges": 1, "status": 1 })
.build(), .build(),
) )
.await .await

View File

@@ -32,11 +32,11 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
} }
let target = target.fetch_channel().await?; let target = target.fetch_channel().await?;
let perm = permissions::PermissionCalculator::new(&user) let perm = permissions::PermissionCalculator::new(&user)
.with_channel(&target) .with_channel(&target)
.for_channel() .for_channel()
.await?; .await?;
if !perm.get_send_message() { if !perm.get_send_message() {
Err(Error::MissingPermission)? Err(Error::MissingPermission)?
} }

View File

@@ -9,7 +9,7 @@ use rocket_contrib::json::JsonValue;
#[get("/")] #[get("/")]
pub async fn root() -> JsonValue { pub async fn root() -> JsonValue {
json!({ json!({
"revolt": "0.4.0-alpha.2", "revolt": "0.4.0-alpha.3",
"features": { "features": {
"registration": !*DISABLE_REGISTRATION, "registration": !*DISABLE_REGISTRATION,
"captcha": { "captcha": {

View File

@@ -0,0 +1,24 @@
use crate::database::*;
use crate::util::result::{Error, Result};
use mongodb::bson::doc;
use rocket_contrib::json::JsonValue;
#[get("/<target>/profile")]
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
let target = target.fetch_user().await?;
let perm = permissions::PermissionCalculator::new(&user)
.with_user(&target)
.for_user_given()
.await?;
if !perm.get_view_profile() {
Err(Error::MissingPermission)?
}
if target.profile.is_some() {
Ok(json!({ "profile": target.profile }))
} else {
Ok(json!({}))
}
}

View File

@@ -3,6 +3,7 @@ use rocket::Route;
mod add_friend; mod add_friend;
mod block_user; mod block_user;
mod fetch_dms; mod fetch_dms;
mod fetch_profile;
mod fetch_relationship; mod fetch_relationship;
mod fetch_relationships; mod fetch_relationships;
mod fetch_user; mod fetch_user;
@@ -19,6 +20,7 @@ pub fn routes() -> Vec<Route> {
fetch_user::req, fetch_user::req,
get_default_avatar::req, get_default_avatar::req,
get_avatar::req, get_avatar::req,
fetch_profile::req,
// Direct Messaging // Direct Messaging
fetch_dms::req, fetch_dms::req,
open_dm::req, open_dm::req,