forked from jmug/stoatchat
Format code.
This commit is contained in:
@@ -102,7 +102,7 @@ pub async fn req(user: User, target: Ref) -> Result<()> {
|
||||
Message::create(
|
||||
"00000000000000000000000000".to_string(),
|
||||
id.clone(),
|
||||
Content::SystemMessage(SystemMessage::UserLeft { id: user.id })
|
||||
Content::SystemMessage(SystemMessage::UserLeft { id: user.id }),
|
||||
)
|
||||
.publish(&target)
|
||||
.await
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use validator::Validate;
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
@@ -21,9 +21,9 @@ pub struct Data {
|
||||
pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<()> {
|
||||
info.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
|
||||
if info.name.is_none() && info.description.is_none() {
|
||||
return Ok(())
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
@@ -31,7 +31,7 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<()> {
|
||||
.with_channel(&target)
|
||||
.for_channel()
|
||||
.await?;
|
||||
|
||||
|
||||
if !perm.get_manage_channel() {
|
||||
Err(Error::MissingPermission)?
|
||||
}
|
||||
@@ -49,7 +49,7 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<()> {
|
||||
|
||||
ClientboundNotification::ChannelUpdate {
|
||||
id: id.clone(),
|
||||
data: json!(info.0)
|
||||
data: json!(info.0),
|
||||
}
|
||||
.publish(id.clone())
|
||||
.await
|
||||
@@ -59,7 +59,10 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<()> {
|
||||
Message::create(
|
||||
"00000000000000000000000000".to_string(),
|
||||
id.clone(),
|
||||
Content::SystemMessage(SystemMessage::ChannelRenamed { name: name.clone(), by: user.id })
|
||||
Content::SystemMessage(SystemMessage::ChannelRenamed {
|
||||
name: name.clone(),
|
||||
by: user.id,
|
||||
}),
|
||||
)
|
||||
.publish(&target)
|
||||
.await
|
||||
@@ -68,6 +71,6 @@ pub async fn req(user: User, target: Ref, info: Json<Data>) -> Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
_ => Err(Error::InvalidOperation)
|
||||
_ => Err(Error::InvalidOperation),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,10 @@ pub async fn req(user: User, target: Ref, member: Ref) -> Result<()> {
|
||||
Message::create(
|
||||
"00000000000000000000000000".to_string(),
|
||||
id.clone(),
|
||||
Content::SystemMessage(SystemMessage::UserAdded { id: member.id, by: user.id })
|
||||
Content::SystemMessage(SystemMessage::UserAdded {
|
||||
id: member.id,
|
||||
by: user.id,
|
||||
}),
|
||||
)
|
||||
.publish(&channel)
|
||||
.await
|
||||
|
||||
@@ -56,7 +56,10 @@ pub async fn req(user: User, target: Ref, member: Ref) -> Result<()> {
|
||||
Message::create(
|
||||
"00000000000000000000000000".to_string(),
|
||||
id.clone(),
|
||||
Content::SystemMessage(SystemMessage::UserRemove { id: member.id, by: user.id })
|
||||
Content::SystemMessage(SystemMessage::UserRemove {
|
||||
id: member.id,
|
||||
by: user.id,
|
||||
}),
|
||||
)
|
||||
.publish(&channel)
|
||||
.await
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::util::variables::{USE_VOSO, VOSO_URL, VOSO_MANAGE_TOKEN};
|
||||
use crate::util::variables::{USE_VOSO, VOSO_MANAGE_TOKEN, VOSO_URL};
|
||||
|
||||
use serde::{Serialize, Deserialize};
|
||||
use rocket_contrib::json::JsonValue;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
struct CreateUserResponse {
|
||||
token: String
|
||||
token: String,
|
||||
}
|
||||
|
||||
#[post("/<target>/join_call")]
|
||||
pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
if !*USE_VOSO {
|
||||
return Err(Error::VosoUnavailable)
|
||||
return Err(Error::VosoUnavailable);
|
||||
}
|
||||
|
||||
let target = target.fetch_channel().await?;
|
||||
@@ -21,9 +21,9 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
.with_channel(&target)
|
||||
.for_channel()
|
||||
.await?;
|
||||
|
||||
|
||||
if !perm.get_voice_call() {
|
||||
return Err(Error::MissingPermission)
|
||||
return Err(Error::MissingPermission);
|
||||
}
|
||||
|
||||
// To join a call:
|
||||
@@ -32,39 +32,51 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
let client = reqwest::Client::new();
|
||||
let result = client
|
||||
.get(&format!("{}/room/{}", *VOSO_URL, target.id()))
|
||||
.header(reqwest::header::AUTHORIZATION, VOSO_MANAGE_TOKEN.to_string())
|
||||
.header(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
VOSO_MANAGE_TOKEN.to_string(),
|
||||
)
|
||||
.send()
|
||||
.await;
|
||||
|
||||
|
||||
match result {
|
||||
Err(_) => return Err(Error::VosoUnavailable),
|
||||
Ok(result) => {
|
||||
match result.status() {
|
||||
reqwest::StatusCode::OK => (),
|
||||
reqwest::StatusCode::NOT_FOUND => {
|
||||
if let Err(_) = client
|
||||
.post(&format!("{}/room/{}", *VOSO_URL, target.id()))
|
||||
.header(reqwest::header::AUTHORIZATION, VOSO_MANAGE_TOKEN.to_string())
|
||||
.send()
|
||||
.await {
|
||||
return Err(Error::VosoUnavailable)
|
||||
}
|
||||
},
|
||||
_ => return Err(Error::VosoUnavailable)
|
||||
Ok(result) => match result.status() {
|
||||
reqwest::StatusCode::OK => (),
|
||||
reqwest::StatusCode::NOT_FOUND => {
|
||||
if let Err(_) = client
|
||||
.post(&format!("{}/room/{}", *VOSO_URL, target.id()))
|
||||
.header(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
VOSO_MANAGE_TOKEN.to_string(),
|
||||
)
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
return Err(Error::VosoUnavailable);
|
||||
}
|
||||
}
|
||||
}
|
||||
_ => return Err(Error::VosoUnavailable),
|
||||
},
|
||||
}
|
||||
|
||||
// Then create a user for the room.
|
||||
if let Ok(response) = client
|
||||
.post(&format!("{}/room/{}/user/{}", *VOSO_URL, target.id(), user.id))
|
||||
.header(reqwest::header::AUTHORIZATION, VOSO_MANAGE_TOKEN.to_string())
|
||||
.post(&format!(
|
||||
"{}/room/{}/user/{}",
|
||||
*VOSO_URL,
|
||||
target.id(),
|
||||
user.id
|
||||
))
|
||||
.header(
|
||||
reqwest::header::AUTHORIZATION,
|
||||
VOSO_MANAGE_TOKEN.to_string(),
|
||||
)
|
||||
.send()
|
||||
.await {
|
||||
let res: CreateUserResponse = response.json()
|
||||
.await
|
||||
.map_err(|_| Error::InvalidOperation)?;
|
||||
|
||||
.await
|
||||
{
|
||||
let res: CreateUserResponse = response.json().await.map_err(|_| Error::InvalidOperation)?;
|
||||
|
||||
Ok(json!(res))
|
||||
} else {
|
||||
Err(Error::VosoUnavailable)
|
||||
|
||||
@@ -26,7 +26,7 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
|
||||
message
|
||||
.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
|
||||
if message.content.len() == 0 && message.attachment.is_none() {
|
||||
return Err(Error::EmptyMessage);
|
||||
}
|
||||
@@ -119,7 +119,7 @@ pub async fn req(user: User, target: Ref, message: Json<Data>) -> Result<JsonVal
|
||||
attachment,
|
||||
nonce: Some(message.nonce.clone()),
|
||||
edited: None,
|
||||
embeds: None
|
||||
embeds: None,
|
||||
};
|
||||
|
||||
msg.clone().publish(&target).await?;
|
||||
|
||||
@@ -28,21 +28,22 @@ pub async fn req(session: Session, user: Option<User>, data: Json<Data>) -> Resu
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
if User::is_username_taken(&data.username).await? {
|
||||
return Err(Error::UsernameTaken)
|
||||
return Err(Error::UsernameTaken);
|
||||
}
|
||||
|
||||
get_collection("users").insert_one(
|
||||
doc! {
|
||||
"_id": session.user_id,
|
||||
"username": &data.username
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "insert_one",
|
||||
with: "user",
|
||||
})?;
|
||||
get_collection("users")
|
||||
.insert_one(
|
||||
doc! {
|
||||
"_id": session.user_id,
|
||||
"username": &data.username
|
||||
},
|
||||
None,
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "insert_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::util::variables::{
|
||||
AUTUMN_URL, DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY, USE_AUTUMN, APP_URL,
|
||||
USE_EMAIL, USE_HCAPTCHA, VAPID_PUBLIC_KEY, USE_VOSO, VOSO_URL, VOSO_WS_HOST
|
||||
APP_URL, AUTUMN_URL, DISABLE_REGISTRATION, EXTERNAL_WS_URL, HCAPTCHA_SITEKEY, INVITE_ONLY,
|
||||
USE_AUTUMN, USE_EMAIL, USE_HCAPTCHA, USE_VOSO, VAPID_PUBLIC_KEY, VOSO_URL, VOSO_WS_HOST,
|
||||
};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::doc;
|
||||
use rauth::auth::{Auth, Session};
|
||||
use regex::Regex;
|
||||
use mongodb::bson::doc;
|
||||
use rocket::State;
|
||||
use validator::Validate;
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
// ! FIXME: should be global somewhere; maybe use config(?)
|
||||
lazy_static! {
|
||||
@@ -24,10 +24,15 @@ pub struct Data {
|
||||
}
|
||||
|
||||
#[patch("/username", data = "<data>")]
|
||||
pub async fn req(auth: State<'_, Auth>, session: Session, user: User, data: Json<Data>) -> Result<()> {
|
||||
pub async fn req(
|
||||
auth: State<'_, Auth>,
|
||||
session: Session,
|
||||
user: User,
|
||||
data: Json<Data>,
|
||||
) -> Result<()> {
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
|
||||
auth.verify_password(&session, data.password.clone())
|
||||
.await
|
||||
.map_err(|_| Error::InvalidCredentials)?;
|
||||
@@ -35,24 +40,23 @@ pub async fn req(auth: State<'_, Auth>, session: Session, user: User, data: Json
|
||||
let mut set = doc! {};
|
||||
if let Some(username) = &data.username {
|
||||
if User::is_username_taken(&username).await? {
|
||||
return Err(Error::UsernameTaken)
|
||||
return Err(Error::UsernameTaken);
|
||||
}
|
||||
|
||||
set.insert("username", username.clone());
|
||||
}
|
||||
|
||||
|
||||
get_collection("users")
|
||||
.update_one(
|
||||
doc! { "_id": &user.id },
|
||||
doc! { "$set": set },
|
||||
None
|
||||
)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError { operation: "update_one", with: "user" })?;
|
||||
.update_one(doc! { "_id": &user.id }, doc! { "$set": set }, None)
|
||||
.await
|
||||
.map_err(|_| Error::DatabaseError {
|
||||
operation: "update_one",
|
||||
with: "user",
|
||||
})?;
|
||||
|
||||
ClientboundNotification::UserUpdate {
|
||||
id: user.id.clone(),
|
||||
data: json!(data.0)
|
||||
data: json!(data.0),
|
||||
}
|
||||
.publish(user.id.clone())
|
||||
.await
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
use crate::database::*;
|
||||
use crate::util::result::{Error, Result};
|
||||
use crate::notifications::events::ClientboundNotification;
|
||||
use crate::util::result::{Error, Result};
|
||||
|
||||
use mongodb::bson::{doc, to_document};
|
||||
use validator::Validate;
|
||||
use rocket_contrib::json::Json;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Validate, Serialize, Deserialize)]
|
||||
pub struct Data {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
status: Option<UserStatus>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
profile: Option<UserProfile>
|
||||
profile: Option<UserProfile>,
|
||||
}
|
||||
|
||||
#[patch("/", data = "<data>")]
|
||||
pub async fn req(user: User, data: Json<Data>) -> Result<()> {
|
||||
data.validate()
|
||||
.map_err(|error| Error::FailedValidation { error })?;
|
||||
|
||||
|
||||
get_collection("users")
|
||||
.update_one(
|
||||
doc! { "_id": &user.id },
|
||||
@@ -31,7 +31,7 @@ pub async fn req(user: User, data: Json<Data>) -> Result<()> {
|
||||
|
||||
ClientboundNotification::UserUpdate {
|
||||
id: user.id.clone(),
|
||||
data: json!(data.0)
|
||||
data: json!(data.0),
|
||||
}
|
||||
.publish(user.id.clone())
|
||||
.await
|
||||
|
||||
@@ -11,7 +11,7 @@ pub async fn req(user: User, target: Ref) -> Result<JsonValue> {
|
||||
.with_user(&target)
|
||||
.for_user_given()
|
||||
.await?;
|
||||
|
||||
|
||||
if !perm.get_view_profile() {
|
||||
Err(Error::MissingPermission)?
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user