forked from jmug/stoatchat
feat: separate friend request route
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -2505,7 +2505,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rauth"
|
||||
version = "1.0.0"
|
||||
source = "git+https://github.com/insertish/rauth?rev=e71d54eba4712b6c6a8a4354ad9fa39677714e1f#e71d54eba4712b6c6a8a4354ad9fa39677714e1f"
|
||||
source = "git+https://github.com/insertish/rauth?rev=7a579daa6a90845fe86139edcadbd01639b330b6#7a579daa6a90845fe86139edcadbd01639b330b6"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"async-trait",
|
||||
@@ -2986,7 +2986,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rocket_rauth"
|
||||
version = "1.0.0"
|
||||
source = "git+https://github.com/insertish/rauth?rev=e71d54eba4712b6c6a8a4354ad9fa39677714e1f#e71d54eba4712b6c6a8a4354ad9fa39677714e1f"
|
||||
source = "git+https://github.com/insertish/rauth?rev=7a579daa6a90845fe86139edcadbd01639b330b6#7a579daa6a90845fe86139edcadbd01639b330b6"
|
||||
dependencies = [
|
||||
"async-std",
|
||||
"base32",
|
||||
|
||||
@@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s
|
||||
# web
|
||||
rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] }
|
||||
rocket_empty = { git = "https://github.com/insertish/rocket_empty", branch = "master" }
|
||||
rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "e71d54eba4712b6c6a8a4354ad9fa39677714e1f" }
|
||||
rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "7a579daa6a90845fe86139edcadbd01639b330b6" }
|
||||
|
||||
# spec generation
|
||||
schemars = "0.8.8"
|
||||
|
||||
@@ -101,7 +101,8 @@ fn custom_openapi_spec() -> OpenApi {
|
||||
"tags": [
|
||||
"Account",
|
||||
"Session",
|
||||
"Onboarding"
|
||||
"Onboarding",
|
||||
"MFA"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -118,7 +119,7 @@ fn custom_openapi_spec() -> OpenApi {
|
||||
openapi: OpenApi::default_version(),
|
||||
info: Info {
|
||||
title: "Revolt API".to_owned(),
|
||||
description: Some("User-first privacy focused chat platform.".to_owned()),
|
||||
description: Some("Open source user-first chat platform.".to_owned()),
|
||||
terms_of_service: Some("https://revolt.chat/terms".to_owned()),
|
||||
contact: Some(Contact {
|
||||
name: Some("Revolt Support".to_owned()),
|
||||
@@ -243,6 +244,11 @@ fn custom_openapi_spec() -> OpenApi {
|
||||
description: Some("Create and manage sessions".to_owned()),
|
||||
..Default::default()
|
||||
},
|
||||
Tag {
|
||||
name: "MFA".to_owned(),
|
||||
description: Some("Multi-factor Authentication".to_owned()),
|
||||
..Default::default()
|
||||
},
|
||||
Tag {
|
||||
name: "Onboarding".to_owned(),
|
||||
description: Some(
|
||||
|
||||
@@ -1,16 +1,20 @@
|
||||
use revolt_quark::models::User;
|
||||
use revolt_quark::{Database, Error, Result};
|
||||
use revolt_quark::{Database, Error, Ref, Result};
|
||||
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
|
||||
/// # Send Friend Request / Accept Request
|
||||
/// # Accept Friend Request
|
||||
///
|
||||
/// Send a friend request to another user or accept another user's friend request.
|
||||
/// Accept another user's friend request.
|
||||
#[openapi(tag = "Relationships")]
|
||||
#[put("/<username>/friend")]
|
||||
pub async fn req(db: &State<Database>, user: User, username: String) -> Result<Json<User>> {
|
||||
let mut target = db.fetch_user_by_username(&username).await?;
|
||||
#[put("/<target>/friend")]
|
||||
pub async fn req(db: &State<Database>, user: User, target: Ref) -> Result<Json<User>> {
|
||||
let mut target = if let Ok(user) = db.fetch_user_by_username(&target.id).await {
|
||||
user
|
||||
} else {
|
||||
target.as_user(db).await?
|
||||
};
|
||||
|
||||
if user.bot.is_some() || target.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
|
||||
@@ -13,6 +13,7 @@ mod find_mutual;
|
||||
mod get_default_avatar;
|
||||
mod open_dm;
|
||||
mod remove_friend;
|
||||
mod send_friend_request;
|
||||
mod unblock_user;
|
||||
|
||||
pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||
@@ -33,5 +34,6 @@ pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||
remove_friend::req,
|
||||
block_user::req,
|
||||
unblock_user::req,
|
||||
send_friend_request::req,
|
||||
]
|
||||
}
|
||||
|
||||
32
crates/delta/src/routes/users/send_friend_request.rs
Normal file
32
crates/delta/src/routes/users/send_friend_request.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use revolt_quark::models::User;
|
||||
use revolt_quark::{Database, Error, Result};
|
||||
|
||||
use rocket::serde::json::Json;
|
||||
use rocket::State;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// # User Lookup Information
|
||||
#[derive(Serialize, Deserialize, JsonSchema)]
|
||||
pub struct DataSendFriendRequest {
|
||||
username: String,
|
||||
}
|
||||
|
||||
/// # Send Friend Request
|
||||
///
|
||||
/// Send a friend request to another user.
|
||||
#[openapi(tag = "Relationships")]
|
||||
#[post("/friend", data = "<data>")]
|
||||
pub async fn req(
|
||||
db: &State<Database>,
|
||||
user: User,
|
||||
data: Json<DataSendFriendRequest>,
|
||||
) -> Result<Json<User>> {
|
||||
let mut target = db.fetch_user_by_username(&data.username).await?;
|
||||
|
||||
if user.bot.is_some() || target.bot.is_some() {
|
||||
return Err(Error::IsBot);
|
||||
}
|
||||
|
||||
user.add_friend(db, &mut target).await?;
|
||||
Ok(Json(target.with_auto_perspective(db, &user).await))
|
||||
}
|
||||
@@ -84,7 +84,7 @@ rocket_empty = { optional = true, git = "https://github.com/insertish/rocket_emp
|
||||
rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "5843861a88958c16bfaa0b40f0d8910772bcd2f6" }
|
||||
|
||||
# rAuth
|
||||
rauth = { git = "https://github.com/insertish/rauth", rev = "e71d54eba4712b6c6a8a4354ad9fa39677714e1f", features = [ "async-std-runtime" ] }
|
||||
rauth = { git = "https://github.com/insertish/rauth", rev = "7a579daa6a90845fe86139edcadbd01639b330b6", features = [ "async-std-runtime" ] }
|
||||
|
||||
# Sentry
|
||||
sentry = "0.25.0"
|
||||
|
||||
Reference in New Issue
Block a user