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?;
|
||||
|
||||
Reference in New Issue
Block a user