forked from jmug/stoatchat
Fetch profile route, push badges and status.
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -1068,6 +1068,8 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35"
|
||||
[[package]]
|
||||
name = "hive_pubsub"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ac4635b1e9faf304ccb33c2f0edbc615030e40d249183281fc788ef20ef5c76"
|
||||
dependencies = [
|
||||
"futures",
|
||||
"many-to-many",
|
||||
@@ -2473,7 +2475,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "revolt"
|
||||
version = "0.4.0-alpha.2"
|
||||
version = "0.4.0-alpha.3"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-tungstenite",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "revolt"
|
||||
version = "0.4.0-alpha.2"
|
||||
version = "0.4.0-alpha.3"
|
||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
|
||||
@@ -25,6 +25,20 @@ pub struct Relationship {
|
||||
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)]
|
||||
pub struct User {
|
||||
#[serde(rename = "_id")]
|
||||
@@ -33,6 +47,13 @@ pub struct User {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
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.
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub relationship: Option<RelationshipStatus>,
|
||||
@@ -65,6 +86,7 @@ impl User {
|
||||
self.online = Some(is_online(&self.id));
|
||||
}
|
||||
|
||||
self.profile = None;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -73,7 +95,7 @@ impl User {
|
||||
if username == "revolt" && username == "admin" {
|
||||
return Ok(true)
|
||||
}
|
||||
|
||||
|
||||
if get_collection("users")
|
||||
.find_one(
|
||||
doc! {
|
||||
|
||||
@@ -77,7 +77,7 @@ pub async fn generate_ready(mut user: User) -> Result<ClientboundNotification> {
|
||||
}
|
||||
},
|
||||
FindOptions::builder()
|
||||
.projection(doc! { "_id": 1, "username": 1 })
|
||||
.projection(doc! { "_id": 1, "username": 1, "badges": 1, "status": 1 })
|
||||
.build(),
|
||||
)
|
||||
.await
|
||||
|
||||
@@ -32,11 +32,11 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
|
||||
}
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
|
||||
let perm = permissions::PermissionCalculator::new(&user)
|
||||
.with_channel(&target)
|
||||
.for_channel()
|
||||
.await?;
|
||||
|
||||
if !perm.get_send_message() {
|
||||
Err(Error::MissingPermission)?
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ use rocket_contrib::json::JsonValue;
|
||||
#[get("/")]
|
||||
pub async fn root() -> JsonValue {
|
||||
json!({
|
||||
"revolt": "0.4.0-alpha.2",
|
||||
"revolt": "0.4.0-alpha.3",
|
||||
"features": {
|
||||
"registration": !*DISABLE_REGISTRATION,
|
||||
"captcha": {
|
||||
|
||||
24
src/routes/users/fetch_profile.rs
Normal file
24
src/routes/users/fetch_profile.rs
Normal 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!({}))
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ use rocket::Route;
|
||||
mod add_friend;
|
||||
mod block_user;
|
||||
mod fetch_dms;
|
||||
mod fetch_profile;
|
||||
mod fetch_relationship;
|
||||
mod fetch_relationships;
|
||||
mod fetch_user;
|
||||
@@ -19,6 +20,7 @@ pub fn routes() -> Vec<Route> {
|
||||
fetch_user::req,
|
||||
get_default_avatar::req,
|
||||
get_avatar::req,
|
||||
fetch_profile::req,
|
||||
// Direct Messaging
|
||||
fetch_dms::req,
|
||||
open_dm::req,
|
||||
|
||||
Reference in New Issue
Block a user