Compare commits
29
Commits
20250530-1
...
20250818-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f9015a6ff | ||
|
|
ed22b3a5ce | ||
|
|
65fbd36624 | ||
|
|
050ba16d4a | ||
|
|
65bc6c8fc6 | ||
|
|
6ad3da5f35 | ||
|
|
947eb15771 | ||
|
|
f4ee35fb09 | ||
|
|
6048587d34 | ||
|
|
80cf8fc4e8 | ||
|
|
4f54227495 | ||
|
|
aab1734615 | ||
|
|
40a41ffd64 | ||
|
|
d30ceea373 | ||
|
|
3e8a401077 | ||
|
|
99f400bc7b | ||
|
|
73b576a75f | ||
|
|
4e4e598daf | ||
|
|
77daf82b94 | ||
|
|
e00603f276 | ||
|
|
1b2c7b2fa1 | ||
|
|
c526095d4f | ||
|
|
8cc4bbea4d | ||
|
|
911ffc767e | ||
|
|
1690df998d | ||
|
|
519d3c08a8 | ||
|
|
9846d8aac2 | ||
|
|
c74b6255dd | ||
|
|
df91b8c990 |
No files matched your search
Generated
+1498
-1055
File diff suppressed because it is too large.
Load diff
@@ -11,6 +11,8 @@ members = [
|
|||||||
|
|
||||||
[patch.crates-io]
|
[patch.crates-io]
|
||||||
redis23 = { package = "redis", version = "0.23.3", git = "https://github.com/revoltchat/redis-rs", rev = "523b2937367e17bd0073722bf6e23d06042cb4e4" }
|
redis23 = { package = "redis", version = "0.23.3", git = "https://github.com/revoltchat/redis-rs", rev = "523b2937367e17bd0073722bf6e23d06042cb4e4" }
|
||||||
|
#authifier = { package = "authifier", version = "1.0.10", path = "../authifier/crates/authifier" }
|
||||||
|
#rocket_authifier = { package = "rocket_authifier", version = "1.0.10", path = "../authifier/crates/rocket_authifier" }
|
||||||
|
|
||||||
# I'm 99% sure this is overloading the GitHub worker
|
# I'm 99% sure this is overloading the GitHub worker
|
||||||
# hence builds have been failing since, let's just
|
# hence builds have been failing since, let's just
|
||||||
|
|||||||
@@ -114,7 +114,8 @@ If you'd like to change anything, create a `Revolt.overrides.toml` file and spec
|
|||||||
> And corresponding Revolt configuration:
|
> And corresponding Revolt configuration:
|
||||||
>
|
>
|
||||||
> ```toml
|
> ```toml
|
||||||
> # Revolt.overrides.toml
|
> # Revolt.overrides.toml
|
||||||
|
> # and Revolt.test-overrides.toml
|
||||||
> [database]
|
> [database]
|
||||||
> mongodb = "mongodb://127.0.0.1:14017"
|
> mongodb = "mongodb://127.0.0.1:14017"
|
||||||
> redis = "redis://127.0.0.1:14079/"
|
> redis = "redis://127.0.0.1:14079/"
|
||||||
|
|||||||
+1
-1
@@ -34,7 +34,7 @@ services:
|
|||||||
- minio
|
- minio
|
||||||
entrypoint: >
|
entrypoint: >
|
||||||
/bin/sh -c "while ! /usr/bin/mc ready minio; do
|
/bin/sh -c "while ! /usr/bin/mc ready minio; do
|
||||||
/usr/bin/mc config host add minio http://minio:9000 minioautumn minioautumn;
|
/usr/bin/mc alias set minio http://minio:9000 minioautumn minioautumn;
|
||||||
echo 'Waiting minio...' && sleep 1;
|
echo 'Waiting minio...' && sleep 1;
|
||||||
done; /usr/bin/mc mb minio/revolt-uploads; exit 0;"
|
done; /usr/bin/mc mb minio/revolt-uploads; exit 0;"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-bonfire"
|
name = "revolt-bonfire"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ revolt-result = { path = "../core/result" }
|
|||||||
revolt-models = { path = "../core/models" }
|
revolt-models = { path = "../core/models" }
|
||||||
revolt-config = { path = "../core/config" }
|
revolt-config = { path = "../core/config" }
|
||||||
revolt-database = { path = "../core/database" }
|
revolt-database = { path = "../core/database" }
|
||||||
revolt-permissions = { version = "0.8.7", path = "../core/permissions" }
|
revolt-permissions = { version = "0.8.8", path = "../core/permissions" }
|
||||||
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
revolt-presence = { path = "../core/presence", features = ["redis-is-patched"] }
|
||||||
|
|
||||||
# redis
|
# redis
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use redis_kiss::{PayloadType, REDIS_PAYLOAD_TYPE, REDIS_URI};
|
|||||||
use revolt_config::report_internal_error;
|
use revolt_config::report_internal_error;
|
||||||
use revolt_database::{
|
use revolt_database::{
|
||||||
events::{client::EventV1, server::ClientMessage},
|
events::{client::EventV1, server::ClientMessage},
|
||||||
|
iso8601_timestamp::Timestamp,
|
||||||
Database, User, UserHint,
|
Database, User, UserHint,
|
||||||
};
|
};
|
||||||
use revolt_presence::{create_session, delete_session};
|
use revolt_presence::{create_session, delete_session};
|
||||||
@@ -100,6 +101,10 @@ pub async fn client(db: &'static Database, stream: TcpStream, addr: SocketAddr)
|
|||||||
|
|
||||||
info!("User {addr:?} authenticated as @{}", user.username);
|
info!("User {addr:?} authenticated as @{}", user.username);
|
||||||
|
|
||||||
|
db.update_session_last_seen(&session_id, Timestamp::now_utc())
|
||||||
|
.await
|
||||||
|
.ok();
|
||||||
|
|
||||||
// Create local state.
|
// Create local state.
|
||||||
let mut state = State::from(user, session_id);
|
let mut state = State::from(user, session_id);
|
||||||
let user_id = state.cache.user_id.clone();
|
let user_id = state.cache.user_id.clone();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-config"
|
name = "revolt-config"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -11,8 +11,9 @@ description = "Revolt Backend: Configuration"
|
|||||||
[features]
|
[features]
|
||||||
anyhow = ["dep:sentry-anyhow"]
|
anyhow = ["dep:sentry-anyhow"]
|
||||||
report-macros = ["revolt-result"]
|
report-macros = ["revolt-result"]
|
||||||
|
sentry = ["dep:sentry"]
|
||||||
test = ["async-std"]
|
test = ["async-std"]
|
||||||
default = ["test", "anyhow"]
|
default = ["test", "sentry"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Utility
|
# Utility
|
||||||
@@ -32,8 +33,8 @@ log = "0.4.14"
|
|||||||
pretty_env_logger = "0.4.0"
|
pretty_env_logger = "0.4.0"
|
||||||
|
|
||||||
# Sentry
|
# Sentry
|
||||||
sentry = "0.31.5"
|
sentry = { version = "0.31.5", optional = true }
|
||||||
sentry-anyhow = { version = "0.38.1", optional = true }
|
sentry-anyhow = { version = "0.38.1", optional = true }
|
||||||
|
|
||||||
# Core
|
# Core
|
||||||
revolt-result = { version = "0.8.7", path = "../result", optional = true }
|
revolt-result = { version = "0.8.8", path = "../result", optional = true }
|
||||||
@@ -6,10 +6,12 @@ use futures_locks::RwLock;
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
|
#[cfg(feature = "sentry")]
|
||||||
pub use sentry::{capture_error, capture_message, Level};
|
pub use sentry::{capture_error, capture_message, Level};
|
||||||
|
#[cfg(feature = "anyhow")]
|
||||||
pub use sentry_anyhow::capture_anyhow;
|
pub use sentry_anyhow::capture_anyhow;
|
||||||
|
|
||||||
#[cfg(feature = "report-macros")]
|
#[cfg(all(feature = "report-macros", feature = "sentry"))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! report_error {
|
macro_rules! report_error {
|
||||||
( $expr: expr, $error: ident $( $tt:tt )? ) => {
|
( $expr: expr, $error: ident $( $tt:tt )? ) => {
|
||||||
@@ -24,7 +26,7 @@ macro_rules! report_error {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "report-macros")]
|
#[cfg(all(feature = "report-macros", feature = "sentry"))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! capture_internal_error {
|
macro_rules! capture_internal_error {
|
||||||
( $expr: expr ) => {
|
( $expr: expr ) => {
|
||||||
@@ -35,7 +37,7 @@ macro_rules! capture_internal_error {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "report-macros")]
|
#[cfg(all(feature = "report-macros", feature = "sentry"))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! report_internal_error {
|
macro_rules! report_internal_error {
|
||||||
( $expr: expr ) => {
|
( $expr: expr ) => {
|
||||||
@@ -60,6 +62,9 @@ static CONFIG_SEARCH_PATHS: [&str; 3] = [
|
|||||||
"/Revolt.toml",
|
"/Revolt.toml",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/// Path to search for test overrides
|
||||||
|
static TEST_OVERRIDE_PATH: &str = "Revolt.test-overrides.toml";
|
||||||
|
|
||||||
/// Configuration builder
|
/// Configuration builder
|
||||||
static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
||||||
RwLock::new({
|
RwLock::new({
|
||||||
@@ -73,6 +78,20 @@ static CONFIG_BUILDER: Lazy<RwLock<Config>> = Lazy::new(|| {
|
|||||||
include_str!("../Revolt.test.toml"),
|
include_str!("../Revolt.test.toml"),
|
||||||
FileFormat::Toml,
|
FileFormat::Toml,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// recursively search upwards for an overrides file (if there is one)
|
||||||
|
if let Ok(cwd) = std::env::current_dir() {
|
||||||
|
let mut path = Some(cwd.as_path());
|
||||||
|
while let Some(current_path) = path {
|
||||||
|
let target_path = current_path.join(TEST_OVERRIDE_PATH);
|
||||||
|
if target_path.exists() {
|
||||||
|
builder = builder
|
||||||
|
.add_source(File::new(target_path.to_str().unwrap(), FileFormat::Toml));
|
||||||
|
}
|
||||||
|
|
||||||
|
path = current_path.parent();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for path in CONFIG_SEARCH_PATHS {
|
for path in CONFIG_SEARCH_PATHS {
|
||||||
@@ -388,6 +407,11 @@ pub async fn read() -> Config {
|
|||||||
pub async fn config() -> Settings {
|
pub async fn config() -> Settings {
|
||||||
let mut config = read().await.try_deserialize::<Settings>().unwrap();
|
let mut config = read().await.try_deserialize::<Settings>().unwrap();
|
||||||
|
|
||||||
|
// inject REDIS_URI for redis-kiss library
|
||||||
|
if std::env::var("REDIS_URL").is_err() {
|
||||||
|
std::env::set_var("REDIS_URI", config.database.redis.clone());
|
||||||
|
}
|
||||||
|
|
||||||
// auto-detect production nodes
|
// auto-detect production nodes
|
||||||
if config.hosts.api.contains("https") && config.hosts.api.contains("revolt.chat") {
|
if config.hosts.api.contains("https") && config.hosts.api.contains("revolt.chat") {
|
||||||
config.production = true;
|
config.production = true;
|
||||||
@@ -397,6 +421,7 @@ pub async fn config() -> Settings {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Configure logging and common Rust variables
|
/// Configure logging and common Rust variables
|
||||||
|
#[cfg(feature = "sentry")]
|
||||||
pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry::ClientInitGuard> {
|
pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry::ClientInitGuard> {
|
||||||
if std::env::var("RUST_LOG").is_err() {
|
if std::env::var("RUST_LOG").is_err() {
|
||||||
std::env::set_var("RUST_LOG", "info");
|
std::env::set_var("RUST_LOG", "info");
|
||||||
@@ -406,12 +431,6 @@ pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry:
|
|||||||
std::env::set_var("ROCKET_ADDRESS", "0.0.0.0");
|
std::env::set_var("ROCKET_ADDRESS", "0.0.0.0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if std::env::var("REDIS_URL").is_err() {
|
|
||||||
// Configure redis-kiss library
|
|
||||||
let config = config().await;
|
|
||||||
std::env::set_var("REDIS_URI", config.database.redis);
|
|
||||||
}
|
|
||||||
|
|
||||||
pretty_env_logger::init();
|
pretty_env_logger::init();
|
||||||
log::info!("Starting {release}");
|
log::info!("Starting {release}");
|
||||||
|
|
||||||
@@ -428,6 +447,7 @@ pub async fn setup_logging(release: &'static str, dsn: String) -> Option<sentry:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "sentry")]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! configure {
|
macro_rules! configure {
|
||||||
($application: ident) => {
|
($application: ident) => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-database"
|
name = "revolt-database"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -10,12 +10,12 @@ description = "Revolt Backend: Database Implementation"
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
# Databases
|
# Databases
|
||||||
mongodb = ["dep:mongodb", "bson"]
|
mongodb = ["dep:mongodb", "bson", "authifier/database-mongodb"]
|
||||||
|
|
||||||
# ... Other
|
# ... Other
|
||||||
tasks = ["isahc", "linkify", "url-escape"]
|
tasks = ["isahc", "linkify", "url-escape"]
|
||||||
async-std-runtime = ["async-std"]
|
async-std-runtime = ["async-std", "authifier/async-std-runtime"]
|
||||||
rocket-impl = ["rocket", "schemars", "revolt_okapi", "revolt_rocket_okapi"]
|
rocket-impl = ["rocket", "schemars", "revolt_okapi", "revolt_rocket_okapi", "authifier/rocket_impl"]
|
||||||
axum-impl = ["axum"]
|
axum-impl = ["axum"]
|
||||||
redis-is-patched = ["revolt-presence/redis-is-patched"]
|
redis-is-patched = ["revolt-presence/redis-is-patched"]
|
||||||
|
|
||||||
@@ -24,19 +24,19 @@ default = ["mongodb", "async-std-runtime", "tasks"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-config = { version = "0.8.7", path = "../config", features = [
|
revolt-config = { version = "0.8.8", path = "../config", features = [
|
||||||
"report-macros",
|
"report-macros",
|
||||||
] }
|
] }
|
||||||
revolt-result = { version = "0.8.7", path = "../result" }
|
revolt-result = { version = "0.8.8", path = "../result" }
|
||||||
revolt-models = { version = "0.8.7", path = "../models", features = [
|
revolt-models = { version = "0.8.8", path = "../models", features = [
|
||||||
"validator",
|
"validator",
|
||||||
] }
|
] }
|
||||||
revolt-presence = { version = "0.8.7", path = "../presence" }
|
revolt-presence = { version = "0.8.8", path = "../presence" }
|
||||||
revolt-permissions = { version = "0.8.7", path = "../permissions", features = [
|
revolt-permissions = { version = "0.8.8", path = "../permissions", features = [
|
||||||
"serde",
|
"serde",
|
||||||
"bson",
|
"bson",
|
||||||
] }
|
] }
|
||||||
revolt-parser = { version = "0.8.7", path = "../parser" }
|
revolt-parser = { version = "0.8.8", path = "../parser" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
@@ -91,13 +91,8 @@ rocket = { version = "0.5.1", default-features = false, features = [
|
|||||||
revolt_okapi = { version = "0.9.1", optional = true }
|
revolt_okapi = { version = "0.9.1", optional = true }
|
||||||
revolt_rocket_okapi = { version = "0.10.0", optional = true }
|
revolt_rocket_okapi = { version = "0.10.0", optional = true }
|
||||||
|
|
||||||
# Notifications
|
|
||||||
fcm_v1 = "0.3.0"
|
|
||||||
web-push = "0.10.0"
|
|
||||||
revolt_a2 = { version = "0.10", default-features = false, features = ["ring"] }
|
|
||||||
|
|
||||||
# Authifier
|
# Authifier
|
||||||
authifier = { version = "1.0.15", features = ["rocket_impl"] }
|
authifier = { version = "1.0.15" }
|
||||||
|
|
||||||
# RabbitMQ
|
# RabbitMQ
|
||||||
amqprs = { version = "1.7.0" }
|
amqprs = { version = "1.7.0" }
|
||||||
@@ -3,18 +3,21 @@
|
|||||||
"_object_type": "User",
|
"_object_type": "User",
|
||||||
"_id": "__ID:0__",
|
"_id": "__ID:0__",
|
||||||
"username": "Owner",
|
"username": "Owner",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
"discriminator": "0001"
|
"discriminator": "0001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_object_type": "User",
|
"_object_type": "User",
|
||||||
"_id": "__ID:1__",
|
"_id": "__ID:1__",
|
||||||
"username": "Member",
|
"username": "Member",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
"discriminator": "0001"
|
"discriminator": "0001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_object_type": "User",
|
"_object_type": "User",
|
||||||
"_id": "__ID:2__",
|
"_id": "__ID:2__",
|
||||||
"username": "Member",
|
"username": "Member",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
"discriminator": "0002"
|
"discriminator": "0002"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -23,6 +26,9 @@
|
|||||||
"channel_type": "Group",
|
"channel_type": "Group",
|
||||||
"name": "My Group",
|
"name": "My Group",
|
||||||
"owner": "__ID:0__",
|
"owner": "__ID:0__",
|
||||||
"recipients": ["__ID:0__", "__ID:1__"]
|
"recipients": [
|
||||||
|
"__ID:0__",
|
||||||
|
"__ID:1__"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -3,18 +3,21 @@
|
|||||||
"_object_type": "User",
|
"_object_type": "User",
|
||||||
"_id": "__ID:0__",
|
"_id": "__ID:0__",
|
||||||
"username": "Owner",
|
"username": "Owner",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
"discriminator": "0001"
|
"discriminator": "0001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_object_type": "User",
|
"_object_type": "User",
|
||||||
"_id": "__ID:1__",
|
"_id": "__ID:1__",
|
||||||
"username": "Moderator",
|
"username": "Moderator",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
"discriminator": "0001"
|
"discriminator": "0001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"_object_type": "User",
|
"_object_type": "User",
|
||||||
"_id": "__ID:2__",
|
"_id": "__ID:2__",
|
||||||
"username": "User",
|
"username": "User",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
"discriminator": "0001"
|
"discriminator": "0001"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -39,7 +42,9 @@
|
|||||||
"_id": "__ID:4__",
|
"_id": "__ID:4__",
|
||||||
"owner": "__ID:0__",
|
"owner": "__ID:0__",
|
||||||
"name": "Server",
|
"name": "Server",
|
||||||
"channels": ["__ID:3__"],
|
"channels": [
|
||||||
|
"__ID:3__"
|
||||||
|
],
|
||||||
"roles": {
|
"roles": {
|
||||||
"__ID:5__": {
|
"__ID:5__": {
|
||||||
"name": "Moderator",
|
"name": "Moderator",
|
||||||
@@ -47,7 +52,7 @@
|
|||||||
"a": 545270208,
|
"a": 545270208,
|
||||||
"d": 0
|
"d": 0
|
||||||
},
|
},
|
||||||
"rank": 3
|
"rank": 1
|
||||||
},
|
},
|
||||||
"__ID:6__": {
|
"__ID:6__": {
|
||||||
"name": "Owner",
|
"name": "Owner",
|
||||||
@@ -66,7 +71,9 @@
|
|||||||
"user": "__ID:0__",
|
"user": "__ID:0__",
|
||||||
"server": "__ID:4__"
|
"server": "__ID:4__"
|
||||||
},
|
},
|
||||||
"roles": ["__ID:6__"],
|
"roles": [
|
||||||
|
"__ID:6__"
|
||||||
|
],
|
||||||
"joined_at": 1698318340195
|
"joined_at": 1698318340195
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -75,7 +82,9 @@
|
|||||||
"user": "__ID:1__",
|
"user": "__ID:1__",
|
||||||
"server": "__ID:4__"
|
"server": "__ID:4__"
|
||||||
},
|
},
|
||||||
"roles": ["__ID:5__"],
|
"roles": [
|
||||||
|
"__ID:5__"
|
||||||
|
],
|
||||||
"joined_at": 1698318340195
|
"joined_at": 1698318340195
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -86,4 +95,4 @@
|
|||||||
},
|
},
|
||||||
"joined_at": 1698318340195
|
"joined_at": 1698318340195
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
@@ -13,6 +14,7 @@ use authifier::Authifier;
|
|||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use revolt_config::config;
|
use revolt_config::config;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
pub use self::mongodb::*;
|
pub use self::mongodb::*;
|
||||||
pub use self::reference::*;
|
pub use self::reference::*;
|
||||||
|
|
||||||
@@ -25,8 +27,10 @@ pub enum DatabaseInfo {
|
|||||||
/// Use the mock database
|
/// Use the mock database
|
||||||
Reference,
|
Reference,
|
||||||
/// Connect to MongoDB
|
/// Connect to MongoDB
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
MongoDb { uri: String, database_name: String },
|
MongoDb { uri: String, database_name: String },
|
||||||
/// Use existing MongoDB connection
|
/// Use existing MongoDB connection
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
MongoDbFromClient(::mongodb::Client, String),
|
MongoDbFromClient(::mongodb::Client, String),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -36,6 +40,7 @@ pub enum Database {
|
|||||||
/// Mock database
|
/// Mock database
|
||||||
Reference(ReferenceDb),
|
Reference(ReferenceDb),
|
||||||
/// MongoDB database
|
/// MongoDB database
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
MongoDb(MongoDb),
|
MongoDb(MongoDb),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +50,7 @@ impl DatabaseInfo {
|
|||||||
pub async fn connect(self) -> Result<Database, String> {
|
pub async fn connect(self) -> Result<Database, String> {
|
||||||
let config = config().await;
|
let config = config().await;
|
||||||
|
|
||||||
Ok(match self {
|
match self {
|
||||||
DatabaseInfo::Auto => {
|
DatabaseInfo::Auto => {
|
||||||
if std::env::var("TEST_DB").is_ok() {
|
if std::env::var("TEST_DB").is_ok() {
|
||||||
DatabaseInfo::Test(format!(
|
DatabaseInfo::Test(format!(
|
||||||
@@ -53,16 +58,20 @@ impl DatabaseInfo {
|
|||||||
rand::thread_rng().gen_range(1_000_000..10_000_000)
|
rand::thread_rng().gen_range(1_000_000..10_000_000)
|
||||||
))
|
))
|
||||||
.connect()
|
.connect()
|
||||||
.await?
|
.await
|
||||||
} else if !config.database.mongodb.is_empty() {
|
} else if !config.database.mongodb.is_empty() {
|
||||||
DatabaseInfo::MongoDb {
|
#[cfg(feature = "mongodb")]
|
||||||
|
return DatabaseInfo::MongoDb {
|
||||||
uri: config.database.mongodb,
|
uri: config.database.mongodb,
|
||||||
database_name: "revolt".to_string(),
|
database_name: "revolt".to_string(),
|
||||||
}
|
}
|
||||||
.connect()
|
.connect()
|
||||||
.await?
|
.await;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mongodb"))]
|
||||||
|
return Err("MongoDB not enabled.".to_string())
|
||||||
} else {
|
} else {
|
||||||
DatabaseInfo::Reference.connect().await?
|
DatabaseInfo::Reference.connect().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DatabaseInfo::Test(database_name) => {
|
DatabaseInfo::Test(database_name) => {
|
||||||
@@ -70,30 +79,36 @@ impl DatabaseInfo {
|
|||||||
.expect("`TEST_DB` environment variable should be set to REFERENCE or MONGODB")
|
.expect("`TEST_DB` environment variable should be set to REFERENCE or MONGODB")
|
||||||
.as_str()
|
.as_str()
|
||||||
{
|
{
|
||||||
"REFERENCE" => DatabaseInfo::Reference.connect().await?,
|
"REFERENCE" => DatabaseInfo::Reference.connect().await,
|
||||||
"MONGODB" => {
|
"MONGODB" => {
|
||||||
DatabaseInfo::MongoDb {
|
#[cfg(feature = "mongodb")]
|
||||||
|
return DatabaseInfo::MongoDb {
|
||||||
uri: config.database.mongodb,
|
uri: config.database.mongodb,
|
||||||
database_name,
|
database_name,
|
||||||
}
|
}
|
||||||
.connect()
|
.connect()
|
||||||
.await?
|
.await;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "mongodb"))]
|
||||||
|
return Err("MongoDB not enabled.".to_string())
|
||||||
}
|
}
|
||||||
_ => unreachable!("must specify REFERENCE or MONGODB"),
|
_ => unreachable!("must specify REFERENCE or MONGODB"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DatabaseInfo::Reference => Database::Reference(Default::default()),
|
DatabaseInfo::Reference => Ok(Database::Reference(Default::default())),
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
DatabaseInfo::MongoDb { uri, database_name } => {
|
DatabaseInfo::MongoDb { uri, database_name } => {
|
||||||
let client = ::mongodb::Client::with_uri_str(uri)
|
let client = ::mongodb::Client::with_uri_str(uri)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| "Failed to init db connection.".to_string())?;
|
.map_err(|_| "Failed to init db connection.".to_string())?;
|
||||||
|
|
||||||
Database::MongoDb(MongoDb(client, database_name))
|
Ok(Database::MongoDb(MongoDb(client, database_name)))
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
DatabaseInfo::MongoDbFromClient(client, database_name) => {
|
DatabaseInfo::MongoDbFromClient(client, database_name) => {
|
||||||
Database::MongoDb(MongoDb(client, database_name))
|
Ok(Database::MongoDb(MongoDb(client, database_name)))
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,12 +234,16 @@ impl Database {
|
|||||||
Authifier {
|
Authifier {
|
||||||
database: match self {
|
database: match self {
|
||||||
Database::Reference(_) => Default::default(),
|
Database::Reference(_) => Default::default(),
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
Database::MongoDb(MongoDb(client, _)) => authifier::Database::MongoDb(
|
Database::MongoDb(MongoDb(client, _)) => authifier::Database::MongoDb(
|
||||||
authifier::database::MongoDb(client.database("revolt")),
|
authifier::database::MongoDb(client.database("revolt")),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
config: auth_config,
|
config: auth_config,
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
event_channel: Some(crate::tasks::authifier_relay::sender()),
|
event_channel: Some(crate::tasks::authifier_relay::sender()),
|
||||||
|
#[cfg(not(feature = "tasks"))]
|
||||||
|
event_channel: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,6 @@ use serde::de::DeserializeOwned;
|
|||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
database_derived!(
|
database_derived!(
|
||||||
#[cfg(feature = "mongodb")]
|
|
||||||
/// MongoDB implementation
|
/// MongoDB implementation
|
||||||
pub struct MongoDb(pub ::mongodb::Client, pub String);
|
pub struct MongoDb(pub ::mongodb::Client, pub String);
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -165,6 +165,9 @@ pub enum EventV1 {
|
|||||||
/// Server role deleted
|
/// Server role deleted
|
||||||
ServerRoleDelete { id: String, role_id: String },
|
ServerRoleDelete { id: String, role_id: String },
|
||||||
|
|
||||||
|
/// Server roles ranks updated
|
||||||
|
ServerRoleRanksUpdate { id: String, ranks: Vec<String> },
|
||||||
|
|
||||||
/// Update existing user
|
/// Update existing user
|
||||||
UserUpdate {
|
UserUpdate {
|
||||||
id: String,
|
id: String,
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ pub use mongodb;
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate bson;
|
extern crate bson;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "async-std-runtime"))]
|
||||||
|
compile_error!("async-std-runtime feature must be enabled.");
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
macro_rules! query {
|
macro_rules! query {
|
||||||
@@ -103,6 +106,7 @@ pub mod util;
|
|||||||
pub use models::*;
|
pub use models::*;
|
||||||
|
|
||||||
pub mod events;
|
pub mod events;
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
pub mod tasks;
|
pub mod tasks;
|
||||||
|
|
||||||
mod amqp;
|
mod amqp;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
use std::{collections::HashSet, ops::BitXor, time::Duration};
|
use std::{
|
||||||
|
collections::{HashMap, HashSet},
|
||||||
|
ops::BitXor,
|
||||||
|
time::Duration,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
mongodb::{
|
mongodb::{
|
||||||
@@ -22,7 +26,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 41; // MUST BE +1 to last migration
|
pub const LATEST_REVISION: i32 = 42; // MUST BE +1 to last migration
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
let migrations = db.col::<Document>("migrations");
|
||||||
@@ -1165,6 +1169,63 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.expect("failed to update users");
|
.expect("failed to update users");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if revision <= 41 {
|
||||||
|
info!(
|
||||||
|
"Running migration [revision 41 / 05-06-2025]: convert role ranks to uniform numbers."
|
||||||
|
);
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
struct Role {
|
||||||
|
pub rank: i64,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone)]
|
||||||
|
struct Server {
|
||||||
|
#[serde(rename = "_id")]
|
||||||
|
pub id: String,
|
||||||
|
#[serde(default = "HashMap::<String, Role>::new")]
|
||||||
|
pub roles: HashMap<String, Role>,
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut servers = db
|
||||||
|
.db()
|
||||||
|
.collection::<Server>("servers")
|
||||||
|
.find(doc! {
|
||||||
|
"roles": {
|
||||||
|
"$exists": true,
|
||||||
|
"$ne": []
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap()
|
||||||
|
.filter_map(|s| async { s.ok() })
|
||||||
|
.boxed();
|
||||||
|
|
||||||
|
while let Some(server) = servers.next().await {
|
||||||
|
let mut ordered_roles = server.roles.clone().into_iter().collect::<Vec<_>>();
|
||||||
|
ordered_roles.sort_by(|(_, role_a), (_, role_b)| role_a.rank.cmp(&role_b.rank));
|
||||||
|
let ordered_roles = ordered_roles
|
||||||
|
.into_iter()
|
||||||
|
.map(|(id, _)| id)
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
let mut doc = doc! {};
|
||||||
|
|
||||||
|
for id in server.roles.keys() {
|
||||||
|
doc.insert(
|
||||||
|
format!("roles.{id}.rank"),
|
||||||
|
ordered_roles.iter().position(|x| id == x).unwrap() as i64,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.collection::<Server>("servers")
|
||||||
|
.update_one(doc! { "_id": &server.id }, doc! { "$set": doc })
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
LATEST_REVISION.max(revision)
|
LATEST_REVISION.max(revision)
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::{Bot, FieldsBot, PartialBot};
|
use crate::{Bot, FieldsBot, PartialBot};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::Invite;
|
use crate::Invite;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::ChannelUnread;
|
use crate::ChannelUnread;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::{FieldsWebhook, PartialWebhook, Webhook};
|
use crate::{FieldsWebhook, PartialWebhook, Webhook};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,13 @@ use serde::{Deserialize, Serialize};
|
|||||||
use ulid::Ulid;
|
use ulid::Ulid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
events::client::EventV1, tasks::ack::AckEvent, Database, File, IntoDocumentPath, PartialServer,
|
events::client::EventV1, Database, File, PartialServer,
|
||||||
Server, SystemMessage, User, AMQP,
|
Server, SystemMessage, User, AMQP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
|
use crate::IntoDocumentPath;
|
||||||
|
|
||||||
auto_derived!(
|
auto_derived!(
|
||||||
#[serde(tag = "channel_type")]
|
#[serde(tag = "channel_type")]
|
||||||
pub enum Channel {
|
pub enum Channel {
|
||||||
@@ -646,10 +649,11 @@ impl Channel {
|
|||||||
.private(user.to_string())
|
.private(user.to_string())
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
crate::tasks::ack::queue_ack(
|
crate::tasks::ack::queue_ack(
|
||||||
self.id().to_string(),
|
self.id().to_string(),
|
||||||
user.to_string(),
|
user.to_string(),
|
||||||
AckEvent::AckMessage {
|
crate::tasks::ack::AckEvent::AckMessage {
|
||||||
id: message.to_string(),
|
id: message.to_string(),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -766,6 +770,7 @@ impl Channel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
impl IntoDocumentPath for FieldsChannel {
|
impl IntoDocumentPath for FieldsChannel {
|
||||||
fn as_path(&self) -> Option<&'static str> {
|
fn as_path(&self) -> Option<&'static str> {
|
||||||
Some(match self {
|
Some(match self {
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
use crate::{revolt_result::Result, Channel, FieldsChannel, PartialChannel};
|
use crate::{revolt_result::Result, Channel, FieldsChannel, PartialChannel};
|
||||||
use revolt_permissions::OverrideField;
|
use revolt_permissions::OverrideField;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::Emoji;
|
use crate::Emoji;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::FileHash;
|
use crate::FileHash;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use crate::File;
|
|||||||
|
|
||||||
use super::FileUsedFor;
|
use super::FileUsedFor;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ use validator::Validate;
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
events::client::EventV1,
|
events::client::EventV1,
|
||||||
tasks::{self, ack::AckEvent},
|
|
||||||
util::{
|
util::{
|
||||||
bulk_permissions::BulkDatabasePermissionQuery, idempotency::IdempotencyKey,
|
bulk_permissions::BulkDatabasePermissionQuery, idempotency::IdempotencyKey,
|
||||||
permissions::DatabasePermissionQuery,
|
permissions::DatabasePermissionQuery,
|
||||||
@@ -22,6 +21,9 @@ use crate::{
|
|||||||
Channel, Database, Emoji, File, User, AMQP,
|
Channel, Database, Emoji, File, User, AMQP,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
|
use crate::tasks::{self, ack::AckEvent};
|
||||||
|
|
||||||
auto_derived_partial!(
|
auto_derived_partial!(
|
||||||
/// Message
|
/// Message
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
@@ -616,9 +618,11 @@ impl Message {
|
|||||||
.await;
|
.await;
|
||||||
|
|
||||||
// Update last_message_id
|
// Update last_message_id
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
tasks::last_message_id::queue(self.channel.to_string(), self.id.to_string(), is_dm).await;
|
tasks::last_message_id::queue(self.channel.to_string(), self.id.to_string(), is_dm).await;
|
||||||
|
|
||||||
// Add mentions for affected users
|
// Add mentions for affected users
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
if !mentions_elsewhere {
|
if !mentions_elsewhere {
|
||||||
if let Some(mentions) = &self.mentions {
|
if let Some(mentions) = &self.mentions {
|
||||||
tasks::ack::queue_message(
|
tasks::ack::queue_message(
|
||||||
@@ -637,6 +641,7 @@ impl Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate embeds
|
// Generate embeds
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
if generate_embeds {
|
if generate_embeds {
|
||||||
if let Some(content) = &self.content {
|
if let Some(content) = &self.content {
|
||||||
tasks::process_embeds::queue(
|
tasks::process_embeds::queue(
|
||||||
@@ -673,10 +678,12 @@ impl Message {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
||||||
if !self.has_suppressed_notifications()
|
if !self.has_suppressed_notifications()
|
||||||
&& (self.mentions.is_some() || self.contains_mass_push_mention())
|
&& (self.mentions.is_some() || self.contains_mass_push_mention())
|
||||||
{
|
{
|
||||||
// send Push notifications
|
// send Push notifications
|
||||||
|
#[cfg(feature = "tasks")]
|
||||||
tasks::ack::queue_message(
|
tasks::ack::queue_message(
|
||||||
self.channel.to_string(),
|
self.channel.to_string(),
|
||||||
AckEvent::ProcessMessage {
|
AckEvent::ProcessMessage {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::{AppendMessage, FieldsMessage, Message, MessageQuery, PartialMessage};
|
use crate::{AppendMessage, FieldsMessage, Message, MessageQuery, PartialMessage};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,10 @@ pub use servers::*;
|
|||||||
pub use user_settings::*;
|
pub use user_settings::*;
|
||||||
pub use users::*;
|
pub use users::*;
|
||||||
|
|
||||||
use crate::{Database, MongoDb, ReferenceDb};
|
use crate::{Database, ReferenceDb};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
|
use crate::MongoDb;
|
||||||
|
|
||||||
pub trait AbstractDatabase:
|
pub trait AbstractDatabase:
|
||||||
Sync
|
Sync
|
||||||
@@ -66,6 +69,8 @@ pub trait AbstractDatabase:
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AbstractDatabase for ReferenceDb {}
|
impl AbstractDatabase for ReferenceDb {}
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
impl AbstractDatabase for MongoDb {}
|
impl AbstractDatabase for MongoDb {}
|
||||||
|
|
||||||
impl std::ops::Deref for Database {
|
impl std::ops::Deref for Database {
|
||||||
@@ -74,6 +79,7 @@ impl std::ops::Deref for Database {
|
|||||||
fn deref(&self) -> &Self::Target {
|
fn deref(&self) -> &Self::Target {
|
||||||
match &self {
|
match &self {
|
||||||
Database::Reference(dummy) => dummy,
|
Database::Reference(dummy) => dummy,
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
Database::MongoDb(mongo) => mongo,
|
Database::MongoDb(mongo) => mongo,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::PolicyChange;
|
use crate::PolicyChange;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::{revolt_result::Result, RatelimitEvent, RatelimitEventType};
|
use crate::{revolt_result::Result, RatelimitEvent, RatelimitEventType};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::Report;
|
use crate::Report;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::Snapshot;
|
use crate::Snapshot;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::{MemberCompositeKey, ServerBan};
|
use crate::{MemberCompositeKey, ServerBan};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,20 @@
|
|||||||
use ::mongodb::SessionCursor;
|
#[cfg(feature = "mongodb")]
|
||||||
|
use ::mongodb::{ClientSession, SessionCursor};
|
||||||
|
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::{FieldsMember, Member, MemberCompositeKey, PartialMember};
|
use crate::{FieldsMember, Member, MemberCompositeKey, PartialMember};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
#[allow(clippy::large_enum_variant)]
|
||||||
pub enum ChunkedServerMembersGenerator {
|
pub enum ChunkedServerMembersGenerator {
|
||||||
#[cfg(feature = "mongodb")]
|
#[cfg(feature = "mongodb")]
|
||||||
MongoDb {
|
MongoDb {
|
||||||
session: ::mongodb::ClientSession,
|
session: ClientSession,
|
||||||
cursor: Option<SessionCursor<Member>>,
|
cursor: Option<SessionCursor<Member>>,
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -22,7 +26,7 @@ pub enum ChunkedServerMembersGenerator {
|
|||||||
|
|
||||||
impl ChunkedServerMembersGenerator {
|
impl ChunkedServerMembersGenerator {
|
||||||
#[cfg(feature = "mongodb")]
|
#[cfg(feature = "mongodb")]
|
||||||
pub fn new_mongo(session: ::mongodb::ClientSession, cursor: SessionCursor<Member>) -> Self {
|
pub fn new_mongo(session: ClientSession, cursor: SessionCursor<Member>) -> Self {
|
||||||
ChunkedServerMembersGenerator::MongoDb {
|
ChunkedServerMembersGenerator::MongoDb {
|
||||||
session,
|
session,
|
||||||
cursor: Some(cursor),
|
cursor: Some(cursor),
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update server data
|
/// Update server data
|
||||||
pub async fn update<'a>(
|
pub async fn update(
|
||||||
&mut self,
|
&mut self,
|
||||||
db: &Database,
|
db: &Database,
|
||||||
partial: PartialServer,
|
partial: PartialServer,
|
||||||
@@ -228,6 +228,13 @@ impl Server {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ordered roles list
|
||||||
|
pub fn ordered_roles(&self) -> Vec<(String, Role)> {
|
||||||
|
let mut ordered_roles = self.roles.clone().into_iter().collect::<Vec<_>>();
|
||||||
|
ordered_roles.sort_by(|(_, role_a), (_, role_b)| role_a.rank.cmp(&role_b.rank));
|
||||||
|
ordered_roles
|
||||||
|
}
|
||||||
|
|
||||||
/// Set role permission on a server
|
/// Set role permission on a server
|
||||||
pub async fn set_role_permission(
|
pub async fn set_role_permission(
|
||||||
&mut self,
|
&mut self,
|
||||||
@@ -253,6 +260,37 @@ impl Server {
|
|||||||
Err(create_error!(NotFound))
|
Err(create_error!(NotFound))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reorders the server's roles rankings
|
||||||
|
pub async fn set_role_ordering(&mut self, db: &Database, new_order: Vec<String>) -> Result<()> {
|
||||||
|
// New order must always contain every role
|
||||||
|
debug_assert_eq!(self.roles.len(), new_order.len());
|
||||||
|
|
||||||
|
// Set the role's ranks to the positions in the vec
|
||||||
|
for (rank, id) in new_order.iter().enumerate() {
|
||||||
|
self.roles.get_mut(id).unwrap().rank = rank as i64;
|
||||||
|
}
|
||||||
|
|
||||||
|
db.update_server(
|
||||||
|
&self.id,
|
||||||
|
&PartialServer {
|
||||||
|
roles: Some(self.roles.clone()),
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
Vec::new(),
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Publish bulk update event
|
||||||
|
EventV1::ServerRoleRanksUpdate {
|
||||||
|
id: self.id.clone(),
|
||||||
|
ranks: new_order,
|
||||||
|
}
|
||||||
|
.p(self.id.clone())
|
||||||
|
.await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Role {
|
impl Role {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::{FieldsRole, FieldsServer, PartialRole, PartialServer, Role, Server};
|
use crate::{FieldsRole, FieldsServer, PartialRole, PartialServer, Role, Server};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ use revolt_result::Result;
|
|||||||
|
|
||||||
use crate::UserSettings;
|
use crate::UserSettings;
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,5 @@ mod rocket;
|
|||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
mod schema;
|
mod schema;
|
||||||
|
|
||||||
#[cfg(feature = "axum-impl")]
|
|
||||||
pub use self::axum::*;
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
pub use self::rocket::*;
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
|
||||||
pub use self::schema::*;
|
|
||||||
pub use model::*;
|
pub use model::*;
|
||||||
pub use ops::*;
|
pub use ops::*;
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
use authifier::models::Session;
|
use authifier::models::Session;
|
||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::{FieldsUser, PartialUser, RelationshipStatus, User};
|
use crate::{FieldsUser, PartialUser, RelationshipStatus, User};
|
||||||
|
|
||||||
|
#[cfg(feature = "mongodb")]
|
||||||
mod mongodb;
|
mod mongodb;
|
||||||
mod reference;
|
mod reference;
|
||||||
|
|
||||||
@@ -61,4 +63,6 @@ pub trait AbstractUsers: Sync + Send {
|
|||||||
|
|
||||||
/// Remove push subscription for a session by session id (TODO: remove)
|
/// Remove push subscription for a session by session id (TODO: remove)
|
||||||
async fn remove_push_subscription_by_session_id(&self, session_id: &str) -> Result<()>;
|
async fn remove_push_subscription_by_session_id(&self, session_id: &str) -> Result<()>;
|
||||||
|
|
||||||
|
async fn update_session_last_seen(&self, session_id: &str, when: Timestamp) -> Result<()>;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
use ::mongodb::options::{Collation, CollationStrength, FindOneOptions, FindOptions};
|
use ::mongodb::options::{Collation, CollationStrength, FindOneOptions, FindOptions};
|
||||||
use authifier::models::Session;
|
use authifier::models::Session;
|
||||||
use futures::StreamExt;
|
use futures::StreamExt;
|
||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::DocumentId;
|
use crate::DocumentId;
|
||||||
@@ -211,16 +212,34 @@ impl AbstractUsers for MongoDb {
|
|||||||
partial: &PartialUser,
|
partial: &PartialUser,
|
||||||
remove: Vec<FieldsUser>,
|
remove: Vec<FieldsUser>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
query!(
|
if remove.contains(&FieldsUser::StatusText) && partial.status.is_some() {
|
||||||
self,
|
// stupid-ass workaround to fix mongo conflicting the same item
|
||||||
update_one_by_id,
|
let _: Result<()> = query!(
|
||||||
COL,
|
self,
|
||||||
id,
|
update_one_by_id,
|
||||||
partial,
|
COL,
|
||||||
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(),
|
id,
|
||||||
None
|
PartialUser {
|
||||||
)
|
..Default::default()
|
||||||
.map(|_| ())
|
},
|
||||||
|
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
.map(|_| ());
|
||||||
|
|
||||||
|
query!(self, update_one_by_id, COL, id, partial, vec![], None).map(|_| ())
|
||||||
|
} else {
|
||||||
|
query!(
|
||||||
|
self,
|
||||||
|
update_one_by_id,
|
||||||
|
COL,
|
||||||
|
id,
|
||||||
|
partial,
|
||||||
|
remove.iter().map(|x| x as &dyn IntoDocumentPath).collect(),
|
||||||
|
None
|
||||||
|
)
|
||||||
|
.map(|_| ())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set relationship with another user
|
/// Set relationship with another user
|
||||||
@@ -317,7 +336,26 @@ impl AbstractUsers for MongoDb {
|
|||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
.map_err(|_| create_database_error!("update_one", COL))
|
.map_err(|_| create_database_error!("update_one", "sessions"))
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn update_session_last_seen(&self, session_id: &str, when: Timestamp) -> Result<()> {
|
||||||
|
let formatted: &str = &when.format();
|
||||||
|
|
||||||
|
self.col::<Session>("sessions")
|
||||||
|
.update_one(
|
||||||
|
doc! {
|
||||||
|
"_id": session_id
|
||||||
|
},
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"last_seen": formatted
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.map(|_| ())
|
||||||
|
.map_err(|_| create_database_error!("update_one", "sessions"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
use authifier::models::Session;
|
use authifier::models::Session;
|
||||||
|
use iso8601_timestamp::Timestamp;
|
||||||
use revolt_result::Result;
|
use revolt_result::Result;
|
||||||
|
|
||||||
use crate::{FieldsUser, PartialUser, RelationshipStatus, User};
|
use crate::{FieldsUser, PartialUser, RelationshipStatus, User};
|
||||||
@@ -168,4 +169,8 @@ impl AbstractUsers for ReferenceDb {
|
|||||||
async fn remove_push_subscription_by_session_id(&self, _session_id: &str) -> Result<()> {
|
async fn remove_push_subscription_by_session_id(&self, _session_id: &str) -> Result<()> {
|
||||||
todo!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn update_session_last_seen(&self, _session_id: &str, _when: Timestamp) -> Result<()> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ use once_cell::sync::Lazy;
|
|||||||
|
|
||||||
use crate::events::client::EventV1;
|
use crate::events::client::EventV1;
|
||||||
|
|
||||||
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(|| unbounded());
|
static Q: Lazy<(Sender<AuthifierEvent>, Receiver<AuthifierEvent>)> = Lazy::new(unbounded);
|
||||||
|
|
||||||
/// Get sender
|
/// Get sender
|
||||||
pub fn sender() -> Sender<AuthifierEvent> {
|
pub fn sender() -> Sender<AuthifierEvent> {
|
||||||
|
|||||||
@@ -15,8 +15,7 @@ impl crate::Bot {
|
|||||||
avatar: user.avatar.map(|x| x.id).unwrap_or_default(),
|
avatar: user.avatar.map(|x| x.id).unwrap_or_default(),
|
||||||
description: user
|
description: user
|
||||||
.profile
|
.profile
|
||||||
.map(|profile| profile.content)
|
.and_then(|profile| profile.content)
|
||||||
.flatten()
|
|
||||||
.unwrap_or_default(),
|
.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1114,7 +1113,7 @@ impl crate::User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Convert user object into user model without presence information
|
/// Convert user object into user model without presence information
|
||||||
pub async fn into_known_static<'a>(self, is_online: bool) -> User {
|
pub async fn into_known_static(self, is_online: bool) -> User {
|
||||||
let badges = self.get_badges().await;
|
let badges = self.get_badges().await;
|
||||||
|
|
||||||
User {
|
User {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ use revolt_rocket_okapi::{
|
|||||||
use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
use schemars::schema::{InstanceType, SchemaObject, SingleOrVec};
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
impl<'r> OpenApiFromRequest<'r> for IdempotencyKey {
|
impl OpenApiFromRequest<'_> for IdempotencyKey {
|
||||||
fn from_request_input(
|
fn from_request_input(
|
||||||
_gen: &mut OpenApiGenerator,
|
_gen: &mut OpenApiGenerator,
|
||||||
_name: String,
|
_name: String,
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ impl PermissionQuery for DatabasePermissionQuery<'_> {
|
|||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
self.cached_mutual_connection = Some(value);
|
self.cached_mutual_connection = Some(value);
|
||||||
matches!(value, true)
|
value
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,41 +14,40 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Reference to some object in the database
|
/// Reference to some object in the database
|
||||||
#[derive(Serialize, Deserialize)]
|
pub struct Reference<'a> {
|
||||||
pub struct Reference {
|
|
||||||
/// Id of object
|
/// Id of object
|
||||||
pub id: String,
|
pub id: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Reference {
|
impl<'a> Reference<'a> {
|
||||||
/// Create a Ref from an unchecked string
|
/// Create a Ref from an unchecked string
|
||||||
pub fn from_unchecked(id: String) -> Reference {
|
pub fn from_unchecked(id: &'a str) -> Reference<'a> {
|
||||||
Reference { id }
|
Reference { id }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch ban from Ref
|
/// Fetch ban from Ref
|
||||||
pub async fn as_ban(&self, db: &Database, server: &str) -> Result<ServerBan> {
|
pub async fn as_ban(&self, db: &Database, server: &str) -> Result<ServerBan> {
|
||||||
db.fetch_ban(server, &self.id).await
|
db.fetch_ban(server, self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch bot from Ref
|
/// Fetch bot from Ref
|
||||||
pub async fn as_bot(&self, db: &Database) -> Result<Bot> {
|
pub async fn as_bot(&self, db: &Database) -> Result<Bot> {
|
||||||
db.fetch_bot(&self.id).await
|
db.fetch_bot(self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch emoji from Ref
|
/// Fetch emoji from Ref
|
||||||
pub async fn as_emoji(&self, db: &Database) -> Result<Emoji> {
|
pub async fn as_emoji(&self, db: &Database) -> Result<Emoji> {
|
||||||
db.fetch_emoji(&self.id).await
|
db.fetch_emoji(self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch channel from Ref
|
/// Fetch channel from Ref
|
||||||
pub async fn as_channel(&self, db: &Database) -> Result<Channel> {
|
pub async fn as_channel(&self, db: &Database) -> Result<Channel> {
|
||||||
db.fetch_channel(&self.id).await
|
db.fetch_channel(self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch invite from Ref or create invite to server if discoverable
|
/// Fetch invite from Ref or create invite to server if discoverable
|
||||||
pub async fn as_invite(&self, db: &Database) -> Result<Invite> {
|
pub async fn as_invite(&self, db: &Database) -> Result<Invite> {
|
||||||
if ulid::Ulid::from_str(&self.id).is_ok() {
|
if ulid::Ulid::from_str(self.id).is_ok() {
|
||||||
let server = self.as_server(db).await?;
|
let server = self.as_server(db).await?;
|
||||||
if !server.discoverable {
|
if !server.discoverable {
|
||||||
return Err(create_error!(NotFound));
|
return Err(create_error!(NotFound));
|
||||||
@@ -65,18 +64,18 @@ impl Reference {
|
|||||||
.ok_or(create_error!(NotFound))?,
|
.ok_or(create_error!(NotFound))?,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
db.fetch_invite(&self.id).await
|
db.fetch_invite(self.id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch message from Ref
|
/// Fetch message from Ref
|
||||||
pub async fn as_message(&self, db: &Database) -> Result<Message> {
|
pub async fn as_message(&self, db: &Database) -> Result<Message> {
|
||||||
db.fetch_message(&self.id).await
|
db.fetch_message(self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch message from Ref and validate channel
|
/// Fetch message from Ref and validate channel
|
||||||
pub async fn as_message_in_channel(&self, db: &Database, channel: &str) -> Result<Message> {
|
pub async fn as_message_in_channel(&self, db: &Database, channel: &str) -> Result<Message> {
|
||||||
let msg = db.fetch_message(&self.id).await?;
|
let msg = db.fetch_message(self.id).await?;
|
||||||
if msg.channel != channel {
|
if msg.channel != channel {
|
||||||
return Err(create_error!(NotFound));
|
return Err(create_error!(NotFound));
|
||||||
}
|
}
|
||||||
@@ -86,36 +85,36 @@ impl Reference {
|
|||||||
|
|
||||||
/// Fetch member from Ref
|
/// Fetch member from Ref
|
||||||
pub async fn as_member(&self, db: &Database, server: &str) -> Result<Member> {
|
pub async fn as_member(&self, db: &Database, server: &str) -> Result<Member> {
|
||||||
db.fetch_member(server, &self.id).await
|
db.fetch_member(server, self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch server from Ref
|
/// Fetch server from Ref
|
||||||
pub async fn as_server(&self, db: &Database) -> Result<Server> {
|
pub async fn as_server(&self, db: &Database) -> Result<Server> {
|
||||||
db.fetch_server(&self.id).await
|
db.fetch_server(self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch user from Ref
|
/// Fetch user from Ref
|
||||||
pub async fn as_user(&self, db: &Database) -> Result<User> {
|
pub async fn as_user(&self, db: &Database) -> Result<User> {
|
||||||
db.fetch_user(&self.id).await
|
db.fetch_user(self.id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch webhook from Ref
|
/// Fetch webhook from Ref
|
||||||
pub async fn as_webhook(&self, db: &Database) -> Result<Webhook> {
|
pub async fn as_webhook(&self, db: &Database) -> Result<Webhook> {
|
||||||
db.fetch_webhook(&self.id).await
|
db.fetch_webhook(self.id).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
impl<'r> FromParam<'r> for Reference {
|
impl<'r> FromParam<'r> for Reference<'r> {
|
||||||
type Error = &'r str;
|
type Error = &'r str;
|
||||||
|
|
||||||
fn from_param(param: &'r str) -> Result<Self, Self::Error> {
|
fn from_param(param: &'r str) -> Result<Self, Self::Error> {
|
||||||
Ok(Reference::from_unchecked(param.into()))
|
Ok(Reference::from_unchecked(param))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "rocket-impl")]
|
#[cfg(feature = "rocket-impl")]
|
||||||
impl JsonSchema for Reference {
|
impl<'a> JsonSchema for Reference<'a> {
|
||||||
fn schema_name() -> String {
|
fn schema_name() -> String {
|
||||||
"Id".to_string()
|
"Id".to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-files"
|
name = "revolt-files"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -20,10 +20,10 @@ typenum = "1.17.0"
|
|||||||
aws-config = "1.5.5"
|
aws-config = "1.5.5"
|
||||||
aws-sdk-s3 = { version = "1.46.0", features = ["behavior-version-latest"] }
|
aws-sdk-s3 = { version = "1.46.0", features = ["behavior-version-latest"] }
|
||||||
|
|
||||||
revolt-config = { version = "0.8.7", path = "../config", features = [
|
revolt-config = { version = "0.8.8", path = "../config", features = [
|
||||||
"report-macros",
|
"report-macros",
|
||||||
] }
|
] }
|
||||||
revolt-result = { version = "0.8.7", path = "../result" }
|
revolt-result = { version = "0.8.8", path = "../result" }
|
||||||
|
|
||||||
# image processing
|
# image processing
|
||||||
jxl-oxide = "0.8.1"
|
jxl-oxide = "0.8.1"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-models"
|
name = "revolt-models"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -20,8 +20,8 @@ default = ["serde", "partials", "rocket"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-config = { version = "0.8.7", path = "../config" }
|
revolt-config = { version = "0.8.8", path = "../config" }
|
||||||
revolt-permissions = { version = "0.8.7", path = "../permissions" }
|
revolt-permissions = { version = "0.8.8", path = "../permissions" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
regex = "1.11"
|
regex = "1.11"
|
||||||
|
|||||||
@@ -132,8 +132,8 @@ auto_derived!(
|
|||||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 2048)))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 2048)))]
|
||||||
pub interactions_url: Option<String>,
|
pub interactions_url: Option<String>,
|
||||||
/// Fields to remove from bot object
|
/// Fields to remove from bot object
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1)))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsBot>>,
|
pub remove: Vec<FieldsBot>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Where we are inviting a bot to
|
/// Where we are inviting a bot to
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ auto_derived!(
|
|||||||
|
|
||||||
/// Fields to remove from channel
|
/// Fields to remove from channel
|
||||||
#[cfg_attr(feature = "serde", serde(default))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsChannel>>,
|
pub remove: Vec<FieldsChannel>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create new group
|
/// Create new group
|
||||||
@@ -310,14 +310,14 @@ impl Channel {
|
|||||||
/// This returns a Result because the recipient name can't be determined here without a db call,
|
/// This returns a Result because the recipient name can't be determined here without a db call,
|
||||||
/// which can't be done since this is models, which can't reference the database crate.
|
/// which can't be done since this is models, which can't reference the database crate.
|
||||||
///
|
///
|
||||||
/// If it returns Err, you need to fetch the name from the db.
|
/// If it returns None, you need to fetch the name from the db.
|
||||||
pub fn name(&self) -> Result<&str, ()> {
|
pub fn name(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
Channel::DirectMessage { .. } => Err(()),
|
Channel::DirectMessage { .. } => None,
|
||||||
Channel::SavedMessages { .. } => Ok("Saved Messages"),
|
Channel::SavedMessages { .. } => Some("Saved Messages"),
|
||||||
Channel::TextChannel { name, .. }
|
Channel::TextChannel { name, .. }
|
||||||
| Channel::Group { name, .. }
|
| Channel::Group { name, .. }
|
||||||
| Channel::VoiceChannel { name, .. } => Ok(name),
|
| Channel::VoiceChannel { name, .. } => Some(name),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ auto_derived!(
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
#[cfg_attr(feature = "validator", derive(Validate))]
|
#[cfg_attr(feature = "validator", derive(Validate))]
|
||||||
pub struct SendableEmbed {
|
pub struct SendableEmbed {
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 128)))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 256)))]
|
||||||
pub icon_url: Option<String>,
|
pub icon_url: Option<String>,
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 256)))]
|
#[cfg_attr(feature = "validator", validate(length(min = 1, max = 256)))]
|
||||||
pub url: Option<String>,
|
pub url: Option<String>,
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ auto_derived!(
|
|||||||
/// Timestamp this member is timed out until
|
/// Timestamp this member is timed out until
|
||||||
pub timeout: Option<Timestamp>,
|
pub timeout: Option<Timestamp>,
|
||||||
/// Fields to remove from channel object
|
/// Fields to remove from channel object
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1)))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsMember>>,
|
pub remove: Vec<FieldsMember>,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -175,6 +175,8 @@ auto_derived!(
|
|||||||
/// Ranking position
|
/// Ranking position
|
||||||
///
|
///
|
||||||
/// Smaller values take priority.
|
/// Smaller values take priority.
|
||||||
|
///
|
||||||
|
/// **Removed** - no effect, use the edit server role positions route
|
||||||
pub rank: Option<i64>,
|
pub rank: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,8 +249,8 @@ auto_derived!(
|
|||||||
pub analytics: Option<bool>,
|
pub analytics: Option<bool>,
|
||||||
|
|
||||||
/// Fields to remove from server object
|
/// Fields to remove from server object
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1)))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsServer>>,
|
pub remove: Vec<FieldsServer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// New role information
|
/// New role information
|
||||||
@@ -267,11 +269,11 @@ auto_derived!(
|
|||||||
pub hoist: Option<bool>,
|
pub hoist: Option<bool>,
|
||||||
/// Ranking position
|
/// Ranking position
|
||||||
///
|
///
|
||||||
/// Smaller values take priority.
|
/// **Removed** - no effect, use the edit server role positions route
|
||||||
pub rank: Option<i64>,
|
pub rank: Option<i64>,
|
||||||
/// Fields to remove from role object
|
/// Fields to remove from role object
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1)))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsRole>>,
|
pub remove: Vec<FieldsRole>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// New role permissions
|
/// New role permissions
|
||||||
@@ -286,4 +288,9 @@ auto_derived!(
|
|||||||
/// Whether to not send a leave message
|
/// Whether to not send a leave message
|
||||||
pub leave_silently: Option<bool>,
|
pub leave_silently: Option<bool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// New role positions
|
||||||
|
pub struct DataEditRoleRanks {
|
||||||
|
pub ranks: Vec<String>,
|
||||||
|
}
|
||||||
);
|
);
|
||||||
@@ -245,8 +245,8 @@ auto_derived!(
|
|||||||
pub flags: Option<i32>,
|
pub flags: Option<i32>,
|
||||||
|
|
||||||
/// Fields to remove from user object
|
/// Fields to remove from user object
|
||||||
#[cfg_attr(feature = "validator", validate(length(min = 1)))]
|
#[cfg_attr(feature = "serde", serde(default))]
|
||||||
pub remove: Option<Vec<FieldsUser>>,
|
pub remove: Vec<FieldsUser>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// User flag reponse
|
/// User flag reponse
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-parser"
|
name = "revolt-parser"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
description = "Revolt Backend: Message Parser"
|
description = "Revolt Backend: Message Parser"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-permissions"
|
name = "revolt-permissions"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -21,7 +21,7 @@ async-std = { version = "1.8.0", features = ["attributes"] }
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Core
|
# Core
|
||||||
revolt-result = { version = "0.8.7", path = "../result" }
|
revolt-result = { version = "0.8.8", path = "../result" }
|
||||||
|
|
||||||
# Utility
|
# Utility
|
||||||
auto_ops = "0.3.0"
|
auto_ops = "0.3.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-presence"
|
name = "revolt-presence"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
@@ -15,6 +15,9 @@ redis-is-patched = []
|
|||||||
# Async
|
# Async
|
||||||
async-std = { version = "1.8.0", features = ["attributes"] }
|
async-std = { version = "1.8.0", features = ["attributes"] }
|
||||||
|
|
||||||
|
# Config for loading Redis URI
|
||||||
|
revolt-config = { version = "0.8.8", path = "../config" }
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# Utility
|
# Utility
|
||||||
log = "0.4.17"
|
log = "0.4.17"
|
||||||
|
|||||||
@@ -197,6 +197,8 @@ mod tests {
|
|||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn it_works() {
|
async fn it_works() {
|
||||||
|
revolt_config::config().await;
|
||||||
|
|
||||||
// Clear the region before we start the tests:
|
// Clear the region before we start the tests:
|
||||||
clear_region(None).await;
|
clear_region(None).await;
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-result"
|
name = "revolt-result"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-crond"
|
name = "revolt-crond"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <me@insrt.uk>"]
|
authors = ["Paul Makles <me@insrt.uk>"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
@@ -16,7 +16,7 @@ log = "0.4"
|
|||||||
tokio = { version = "1" }
|
tokio = { version = "1" }
|
||||||
|
|
||||||
# Core
|
# Core
|
||||||
revolt-database = { version = "0.8.7", path = "../../core/database" }
|
revolt-database = { version = "0.8.8", path = "../../core/database" }
|
||||||
revolt-result = { version = "0.8.7", path = "../../core/result" }
|
revolt-result = { version = "0.8.8", path = "../../core/result" }
|
||||||
revolt-config = { version = "0.8.7", path = "../../core/config" }
|
revolt-config = { version = "0.8.8", path = "../../core/config" }
|
||||||
revolt-files = { version = "0.8.7", path = "../../core/files" }
|
revolt-files = { version = "0.8.8", path = "../../core/files" }
|
||||||
@@ -1,19 +1,20 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-pushd"
|
name = "revolt-pushd"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
revolt-result = { version = "0.8.7", path = "../../core/result" }
|
revolt-result = { version = "0.8.8", path = "../../core/result" }
|
||||||
revolt-config = { version = "0.8.7", path = "../../core/config", features = [
|
revolt-config = { version = "0.8.8", path = "../../core/config", features = [
|
||||||
"report-macros",
|
"report-macros",
|
||||||
|
"anyhow"
|
||||||
] }
|
] }
|
||||||
revolt-database = { version = "0.8.7", path = "../../core/database" }
|
revolt-database = { version = "0.8.8", path = "../../core/database" }
|
||||||
revolt-models = { version = "0.8.7", path = "../../core/models", features = [
|
revolt-models = { version = "0.8.8", path = "../../core/models", features = [
|
||||||
"validator",
|
"validator",
|
||||||
] }
|
] }
|
||||||
revolt-presence = { version = "0.8.7", path = "../../core/presence", features = [
|
revolt-presence = { version = "0.8.8", path = "../../core/presence", features = [
|
||||||
"redis-is-patched",
|
"redis-is-patched",
|
||||||
] }
|
] }
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-delta"
|
name = "revolt-delta"
|
||||||
version = "0.8.7"
|
version = "0.8.8"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"_object_type": "User",
|
||||||
|
"_id": "__ID:0__",
|
||||||
|
"username": "Owner",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
|
"discriminator": "0001"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "User",
|
||||||
|
"_id": "__ID:1__",
|
||||||
|
"username": "Moderator",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
|
"discriminator": "0001"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "User",
|
||||||
|
"_id": "__ID:2__",
|
||||||
|
"username": "User",
|
||||||
|
"last_acknowledged_policy_change": "2025-06-07T04:04:48+0000",
|
||||||
|
"discriminator": "0001"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "Channel",
|
||||||
|
"_id": "__ID:3__",
|
||||||
|
"channel_type": "TextChannel",
|
||||||
|
"name": "General",
|
||||||
|
"server": "__ID:4__",
|
||||||
|
"default_permissions": {
|
||||||
|
"a": 0,
|
||||||
|
"d": 1048576
|
||||||
|
},
|
||||||
|
"role_permissions": {
|
||||||
|
"__ID:5__": {
|
||||||
|
"a": 1048576,
|
||||||
|
"d": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "Server",
|
||||||
|
"_id": "__ID:4__",
|
||||||
|
"owner": "__ID:0__",
|
||||||
|
"name": "Server",
|
||||||
|
"channels": [
|
||||||
|
"__ID:3__"
|
||||||
|
],
|
||||||
|
"roles": {
|
||||||
|
"__ID:5__": {
|
||||||
|
"name": "Moderator",
|
||||||
|
"permissions": {
|
||||||
|
"a": 545270216,
|
||||||
|
"d": 0
|
||||||
|
},
|
||||||
|
"rank": 1
|
||||||
|
},
|
||||||
|
"__ID:6__": {
|
||||||
|
"name": "Owner",
|
||||||
|
"permissions": {
|
||||||
|
"a": 0,
|
||||||
|
"d": 0
|
||||||
|
},
|
||||||
|
"rank": 0
|
||||||
|
},
|
||||||
|
"__ID:7__": {
|
||||||
|
"name": "Lower Rank 1",
|
||||||
|
"permissions": {
|
||||||
|
"a": 0,
|
||||||
|
"d": 0
|
||||||
|
},
|
||||||
|
"rank": 2
|
||||||
|
},
|
||||||
|
"__ID:8__": {
|
||||||
|
"name": "Lower Rank 2",
|
||||||
|
"permissions": {
|
||||||
|
"a": 0,
|
||||||
|
"d": 0
|
||||||
|
},
|
||||||
|
"rank": 2
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"default_permissions": 4000322560
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "ServerMember",
|
||||||
|
"_id": {
|
||||||
|
"user": "__ID:0__",
|
||||||
|
"server": "__ID:4__"
|
||||||
|
},
|
||||||
|
"roles": [
|
||||||
|
"__ID:6__"
|
||||||
|
],
|
||||||
|
"joined_at": 1698318340195
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "ServerMember",
|
||||||
|
"_id": {
|
||||||
|
"user": "__ID:1__",
|
||||||
|
"server": "__ID:4__"
|
||||||
|
},
|
||||||
|
"roles": [
|
||||||
|
"__ID:5__"
|
||||||
|
],
|
||||||
|
"joined_at": 1698318340195
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"_object_type": "ServerMember",
|
||||||
|
"_id": {
|
||||||
|
"user": "__ID:2__",
|
||||||
|
"server": "__ID:4__"
|
||||||
|
},
|
||||||
|
"joined_at": 1698318340195
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -11,7 +11,7 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn delete_bot(
|
pub async fn delete_bot(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let bot = target.as_bot(db).await?;
|
let bot = target.as_bot(db).await?;
|
||||||
if bot.owner != user.id {
|
if bot.owner != user.id {
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use validator::Validate;
|
|||||||
pub async fn edit_bot(
|
pub async fn edit_bot(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
data: Json<DataEditBot>,
|
data: Json<DataEditBot>,
|
||||||
) -> Result<Json<v0::BotWithUserResponse>> {
|
) -> Result<Json<v0::BotWithUserResponse>> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
@@ -37,7 +37,7 @@ pub async fn edit_bot(
|
|||||||
if data.public.is_none()
|
if data.public.is_none()
|
||||||
&& data.analytics.is_none()
|
&& data.analytics.is_none()
|
||||||
&& data.interactions_url.is_none()
|
&& data.interactions_url.is_none()
|
||||||
&& data.remove.is_none()
|
&& data.remove.is_empty()
|
||||||
{
|
{
|
||||||
return Ok(Json(v0::BotWithUserResponse {
|
return Ok(Json(v0::BotWithUserResponse {
|
||||||
bot: bot.into(),
|
bot: bot.into(),
|
||||||
@@ -64,7 +64,6 @@ pub async fn edit_bot(
|
|||||||
db,
|
db,
|
||||||
partial,
|
partial,
|
||||||
remove
|
remove
|
||||||
.unwrap_or_default()
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|v| v.into())
|
.map(|v| v.into())
|
||||||
.collect(),
|
.collect(),
|
||||||
@@ -100,7 +99,7 @@ mod test {
|
|||||||
.body(
|
.body(
|
||||||
json!(v0::DataEditBot {
|
json!(v0::DataEditBot {
|
||||||
public: Some(true),
|
public: Some(true),
|
||||||
remove: Some(vec![FieldsBot::Token]),
|
remove: vec![FieldsBot::Token],
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})
|
})
|
||||||
.to_string(),
|
.to_string(),
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn fetch_bot(
|
pub async fn fetch_bot(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
bot: Reference,
|
bot: Reference<'_>,
|
||||||
) -> Result<Json<FetchBotResponse>> {
|
) -> Result<Json<FetchBotResponse>> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
return Err(create_error!(IsBot));
|
return Err(create_error!(IsBot));
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ use rocket::State;
|
|||||||
pub async fn fetch_public_bot(
|
pub async fn fetch_public_bot(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: Option<User>,
|
user: Option<User>,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<Json<PublicBot>> {
|
) -> Result<Json<PublicBot>> {
|
||||||
let bot = db.fetch_bot(&target.id).await?;
|
let bot = db.fetch_bot(target.id).await?;
|
||||||
if !bot.public && user.map_or(true, |x| x.id != bot.owner) {
|
if !bot.public && user.is_none_or(|x| x.id != bot.owner) {
|
||||||
return Err(create_error!(NotFound));
|
return Err(create_error!(NotFound));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ pub async fn invite_bot(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
dest: Json<v0::InviteBotDestination>,
|
dest: Json<v0::InviteBotDestination>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn ack(
|
pub async fn ack(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
message: Reference,
|
message: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
return Err(create_error!(IsBot));
|
return Err(create_error!(IsBot));
|
||||||
@@ -29,7 +29,7 @@ pub async fn ack(
|
|||||||
.throw_if_lacking_channel_permission(ChannelPermission::ViewChannel)?;
|
.throw_if_lacking_channel_permission(ChannelPermission::ViewChannel)?;
|
||||||
|
|
||||||
channel
|
channel
|
||||||
.ack(&user.id, &message.id)
|
.ack(&user.id, message.id)
|
||||||
.await
|
.await
|
||||||
.map(|_| EmptyResponse)
|
.map(|_| EmptyResponse)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub async fn delete(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
options: v0::OptionsChannelDelete,
|
options: v0::OptionsChannelDelete,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let mut channel = target.as_channel(db).await?;
|
let mut channel = target.as_channel(db).await?;
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub async fn edit(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
data: Json<v0::DataEditChannel>,
|
data: Json<v0::DataEditChannel>,
|
||||||
) -> Result<Json<v0::Channel>> {
|
) -> Result<Json<v0::Channel>> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
@@ -38,7 +38,7 @@ pub async fn edit(
|
|||||||
&& data.icon.is_none()
|
&& data.icon.is_none()
|
||||||
&& data.nsfw.is_none()
|
&& data.nsfw.is_none()
|
||||||
&& data.owner.is_none()
|
&& data.owner.is_none()
|
||||||
&& data.remove.is_none()
|
&& data.remove.is_empty()
|
||||||
{
|
{
|
||||||
return Ok(Json(channel.into()));
|
return Ok(Json(channel.into()));
|
||||||
}
|
}
|
||||||
@@ -112,23 +112,21 @@ pub async fn edit(
|
|||||||
nsfw,
|
nsfw,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
if let Some(fields) = &data.remove {
|
if data.remove.contains(&v0::FieldsChannel::Icon) {
|
||||||
if fields.contains(&v0::FieldsChannel::Icon) {
|
if let Some(icon) = &icon {
|
||||||
if let Some(icon) = &icon {
|
db.mark_attachment_as_deleted(&icon.id).await?;
|
||||||
db.mark_attachment_as_deleted(&icon.id).await?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for field in fields {
|
for field in &data.remove {
|
||||||
match field {
|
match field {
|
||||||
v0::FieldsChannel::Description => {
|
v0::FieldsChannel::Description => {
|
||||||
description.take();
|
description.take();
|
||||||
}
|
|
||||||
v0::FieldsChannel::Icon => {
|
|
||||||
icon.take();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
v0::FieldsChannel::Icon => {
|
||||||
|
icon.take();
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,11 +212,7 @@ pub async fn edit(
|
|||||||
.update(
|
.update(
|
||||||
db,
|
db,
|
||||||
partial,
|
partial,
|
||||||
data.remove
|
data.remove.into_iter().map(|f| f.into()).collect(),
|
||||||
.unwrap_or_default()
|
|
||||||
.into_iter()
|
|
||||||
.map(|f| f.into())
|
|
||||||
.collect(),
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn fetch(
|
pub async fn fetch(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<Json<v0::Channel>> {
|
) -> Result<Json<v0::Channel>> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ pub async fn add_member(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
group_id: Reference,
|
group_id: Reference<'_>,
|
||||||
member_id: Reference,
|
member_id: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
return Err(create_error!(IsBot));
|
return Err(create_error!(IsBot));
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ pub async fn remove_member(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
member: Reference,
|
member: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
return Err(create_error!(IsBot));
|
return Err(create_error!(IsBot));
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn create_invite(
|
pub async fn create_invite(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<Json<v0::Invite>> {
|
) -> Result<Json<v0::Invite>> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
return Err(create_error!(IsBot));
|
return Err(create_error!(IsBot));
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn fetch_members(
|
pub async fn fetch_members(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<Json<Vec<v0::User>>> {
|
) -> Result<Json<Vec<v0::User>>> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ use validator::Validate;
|
|||||||
pub async fn bulk_delete_messages(
|
pub async fn bulk_delete_messages(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
options: Json<v0::OptionsBulkDelete>,
|
options: Json<v0::OptionsBulkDelete>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let options = options.into_inner();
|
let options = options.into_inner();
|
||||||
@@ -51,7 +51,7 @@ pub async fn bulk_delete_messages(
|
|||||||
.await
|
.await
|
||||||
.throw_if_lacking_channel_permission(ChannelPermission::ManageMessages)?;
|
.throw_if_lacking_channel_permission(ChannelPermission::ManageMessages)?;
|
||||||
|
|
||||||
Message::bulk_delete(db, &target.id, options.ids)
|
Message::bulk_delete(db, target.id, options.ids)
|
||||||
.await
|
.await
|
||||||
.map(|_| EmptyResponse)
|
.map(|_| EmptyResponse)
|
||||||
}
|
}
|
||||||
@@ -17,8 +17,8 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn clear_reactions(
|
pub async fn clear_reactions(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn delete(
|
pub async fn delete(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let message = msg.as_message_in_channel(db, &target.id).await?;
|
let message = msg.as_message_in_channel(db, target.id).await?;
|
||||||
|
|
||||||
if message.author != user.id {
|
if message.author != user.id {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
|
|||||||
@@ -18,8 +18,8 @@ use validator::Validate;
|
|||||||
pub async fn edit(
|
pub async fn edit(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
edit: Json<v0::DataEditMessage>,
|
edit: Json<v0::DataEditMessage>,
|
||||||
) -> Result<Json<v0::Message>> {
|
) -> Result<Json<v0::Message>> {
|
||||||
let edit = edit.into_inner();
|
let edit = edit.into_inner();
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn fetch(
|
pub async fn fetch(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
) -> Result<Json<v0::Message>> {
|
) -> Result<Json<v0::Message>> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
use revolt_database::{util::{permissions::DatabasePermissionQuery, reference::Reference}, Channel, Database, PartialMessage, SystemMessage, User, AMQP};
|
use revolt_database::{
|
||||||
|
util::{permissions::DatabasePermissionQuery, reference::Reference},
|
||||||
|
Channel, Database, PartialMessage, SystemMessage, User, AMQP,
|
||||||
|
};
|
||||||
use revolt_models::v0::MessageAuthor;
|
use revolt_models::v0::MessageAuthor;
|
||||||
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
|
use revolt_permissions::{calculate_channel_permissions, ChannelPermission};
|
||||||
use revolt_result::{create_error, Result};
|
use revolt_result::{create_error, Result};
|
||||||
@@ -14,8 +17,8 @@ pub async fn message_pin(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
|
|
||||||
@@ -169,7 +172,7 @@ mod test {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let updated_message = Reference::from_unchecked(message.id)
|
let updated_message = Reference::from_unchecked(&message.id)
|
||||||
.as_message(&harness.db)
|
.as_message(&harness.db)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to find updated message");
|
.expect("Failed to find updated message");
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use validator::Validate;
|
|||||||
pub async fn query(
|
pub async fn query(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
options: v0::OptionsQueryMessages,
|
options: v0::OptionsQueryMessages,
|
||||||
) -> Result<Json<v0::BulkMessageResponse>> {
|
) -> Result<Json<v0::BulkMessageResponse>> {
|
||||||
options.validate().map_err(|error| {
|
options.validate().map_err(|error| {
|
||||||
|
|||||||
@@ -15,9 +15,9 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn react_message(
|
pub async fn react_message(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
emoji: Reference,
|
emoji: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
||||||
@@ -30,7 +30,7 @@ pub async fn react_message(
|
|||||||
|
|
||||||
// Add the reaction
|
// Add the reaction
|
||||||
message
|
message
|
||||||
.add_reaction(db, &user, &emoji.id)
|
.add_reaction(db, &user, emoji.id)
|
||||||
.await
|
.await
|
||||||
.map(|_| EmptyResponse)
|
.map(|_| EmptyResponse)
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@ use validator::Validate;
|
|||||||
pub async fn search(
|
pub async fn search(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
options: Json<v0::DataMessageSearch>,
|
options: Json<v0::DataMessageSearch>,
|
||||||
) -> Result<Json<v0::BulkMessageResponse>> {
|
) -> Result<Json<v0::BulkMessageResponse>> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub async fn message_send(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
data: Json<v0::DataMessageSend>,
|
data: Json<v0::DataMessageSend>,
|
||||||
idempotency: IdempotencyKey,
|
idempotency: IdempotencyKey,
|
||||||
) -> Result<Json<v0::Message>> {
|
) -> Result<Json<v0::Message>> {
|
||||||
@@ -84,7 +84,8 @@ pub async fn message_send(
|
|||||||
// Create model user / members
|
// Create model user / members
|
||||||
let model_user = user
|
let model_user = user
|
||||||
.clone()
|
.clone()
|
||||||
.into_known_static(revolt_presence::is_online(&user.id).await).await;
|
.into_known_static(revolt_presence::is_online(&user.id).await)
|
||||||
|
.await;
|
||||||
|
|
||||||
let model_member: Option<v0::Member> = query
|
let model_member: Option<v0::Member> = query
|
||||||
.member_ref()
|
.member_ref()
|
||||||
@@ -201,7 +202,7 @@ mod test {
|
|||||||
Member::create(&harness.db, &server, &user, Some(channels.clone()))
|
Member::create(&harness.db, &server, &user, Some(channels.clone()))
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create member");
|
.expect("Failed to create member");
|
||||||
let member = Reference::from_unchecked(user.id.clone())
|
let member = Reference::from_unchecked(&user.id)
|
||||||
.as_member(&harness.db, &server.id)
|
.as_member(&harness.db, &server.id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get member");
|
.expect("Failed to get member");
|
||||||
@@ -241,7 +242,7 @@ mod test {
|
|||||||
Member::create(&harness.db, &server, &second_user, Some(channels.clone()))
|
Member::create(&harness.db, &server, &second_user, Some(channels.clone()))
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create second member");
|
.expect("Failed to create second member");
|
||||||
let mut second_member = Reference::from_unchecked(second_user.id.clone())
|
let mut second_member = Reference::from_unchecked(&second_user.id)
|
||||||
.as_member(&harness.db, &server.id)
|
.as_member(&harness.db, &server.id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get second member");
|
.expect("Failed to get second member");
|
||||||
@@ -491,7 +492,7 @@ mod test {
|
|||||||
let (_, _, other_user) = harness.new_user().await;
|
let (_, _, other_user) = harness.new_user().await;
|
||||||
let (server, _) = harness.new_server(&user).await;
|
let (server, _) = harness.new_server(&user).await;
|
||||||
let channel = harness.new_channel(&server).await;
|
let channel = harness.new_channel(&server).await;
|
||||||
let (role_id, mut role) = harness
|
let (role_id, _role) = harness
|
||||||
.new_role(
|
.new_role(
|
||||||
&server,
|
&server,
|
||||||
1,
|
1,
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ pub async fn message_unpin(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
|
|
||||||
@@ -91,7 +91,7 @@ mod test {
|
|||||||
Member::create(&harness.db, &server, &user, Some(channels.clone()))
|
Member::create(&harness.db, &server, &user, Some(channels.clone()))
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create member");
|
.expect("Failed to create member");
|
||||||
let member = Reference::from_unchecked(user.id.clone())
|
let member = Reference::from_unchecked(&user.id)
|
||||||
.as_member(&harness.db, &server.id)
|
.as_member(&harness.db, &server.id)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to get member");
|
.expect("Failed to get member");
|
||||||
@@ -174,7 +174,7 @@ mod test {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let updated_message = Reference::from_unchecked(message.id)
|
let updated_message = Reference::from_unchecked(&message.id)
|
||||||
.as_message(&harness.db)
|
.as_message(&harness.db)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to find updated message");
|
.expect("Failed to find updated message");
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn unreact_message(
|
pub async fn unreact_message(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
msg: Reference,
|
msg: Reference<'_>,
|
||||||
emoji: Reference,
|
emoji: Reference<'_>,
|
||||||
options: v0::OptionsUnreact,
|
options: v0::OptionsUnreact,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
@@ -41,14 +41,14 @@ pub async fn unreact_message(
|
|||||||
// Check if we should wipe all of this reaction
|
// Check if we should wipe all of this reaction
|
||||||
if remove_all {
|
if remove_all {
|
||||||
return message
|
return message
|
||||||
.clear_reaction(db, &emoji.id)
|
.clear_reaction(db, emoji.id)
|
||||||
.await
|
.await
|
||||||
.map(|_| EmptyResponse);
|
.map(|_| EmptyResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove the reaction
|
// Remove the reaction
|
||||||
message
|
message
|
||||||
.remove_reaction(db, options.user_id.as_ref().unwrap_or(&user.id), &emoji.id)
|
.remove_reaction(db, options.user_id.as_ref().unwrap_or(&user.id), emoji.id)
|
||||||
.await
|
.await
|
||||||
.map(|_| EmptyResponse)
|
.map(|_| EmptyResponse)
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ pub fn routes() -> (Vec<Route>, OpenApi) {
|
|||||||
group_remove_member::remove_member,
|
group_remove_member::remove_member,
|
||||||
voice_join::call,
|
voice_join::call,
|
||||||
permissions_set::set_role_permissions,
|
permissions_set::set_role_permissions,
|
||||||
permissions_set_default::set_default_permissions,
|
permissions_set_default::set_default_channel_permissions,
|
||||||
message_react::react_message,
|
message_react::react_message,
|
||||||
message_unreact::unreact_message,
|
message_unreact::unreact_message,
|
||||||
message_clear_reactions::clear_reactions,
|
message_clear_reactions::clear_reactions,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn set_role_permissions(
|
pub async fn set_role_permissions(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
role_id: String,
|
role_id: String,
|
||||||
data: Json<v0::DataSetRolePermissions>,
|
data: Json<v0::DataSetRolePermissions>,
|
||||||
) -> Result<Json<v0::Channel>> {
|
) -> Result<Json<v0::Channel>> {
|
||||||
|
|||||||
@@ -14,10 +14,10 @@ use rocket::{serde::json::Json, State};
|
|||||||
/// Channel must be a `Group`, `TextChannel` or `VoiceChannel`.
|
/// Channel must be a `Group`, `TextChannel` or `VoiceChannel`.
|
||||||
#[openapi(tag = "Channel Permissions")]
|
#[openapi(tag = "Channel Permissions")]
|
||||||
#[put("/<target>/permissions/default", data = "<data>", rank = 1)]
|
#[put("/<target>/permissions/default", data = "<data>", rank = 1)]
|
||||||
pub async fn set_default_permissions(
|
pub async fn set_default_channel_permissions(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
data: Json<v0::DataDefaultChannelPermissions>,
|
data: Json<v0::DataDefaultChannelPermissions>,
|
||||||
) -> Result<Json<v0::Channel>> {
|
) -> Result<Json<v0::Channel>> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn call(
|
pub async fn call(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<Json<v0::LegacyCreateVoiceUserResponse>> {
|
) -> Result<Json<v0::LegacyCreateVoiceUserResponse>> {
|
||||||
let channel = target.as_channel(db).await?;
|
let channel = target.as_channel(db).await?;
|
||||||
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
let mut query = DatabasePermissionQuery::new(db, &user).channel(&channel);
|
||||||
@@ -41,7 +41,7 @@ pub async fn call(
|
|||||||
// - If not, create it.
|
// - If not, create it.
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let result = client
|
let result = client
|
||||||
.get(&format!(
|
.get(format!(
|
||||||
"{}/room/{}",
|
"{}/room/{}",
|
||||||
config.hosts.voso_legacy,
|
config.hosts.voso_legacy,
|
||||||
channel.id()
|
channel.id()
|
||||||
@@ -59,7 +59,7 @@ pub async fn call(
|
|||||||
reqwest::StatusCode::OK => (),
|
reqwest::StatusCode::OK => (),
|
||||||
reqwest::StatusCode::NOT_FOUND => {
|
reqwest::StatusCode::NOT_FOUND => {
|
||||||
if (client
|
if (client
|
||||||
.post(&format!(
|
.post(format!(
|
||||||
"{}/room/{}",
|
"{}/room/{}",
|
||||||
config.hosts.voso_legacy,
|
config.hosts.voso_legacy,
|
||||||
channel.id()
|
channel.id()
|
||||||
@@ -81,7 +81,7 @@ pub async fn call(
|
|||||||
|
|
||||||
// Then create a user for the room.
|
// Then create a user for the room.
|
||||||
if let Ok(response) = client
|
if let Ok(response) = client
|
||||||
.post(&format!(
|
.post(format!(
|
||||||
"{}/room/{}/user/{}",
|
"{}/room/{}/user/{}",
|
||||||
config.hosts.voso_legacy,
|
config.hosts.voso_legacy,
|
||||||
channel.id(),
|
channel.id(),
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ use validator::Validate;
|
|||||||
pub async fn create_webhook(
|
pub async fn create_webhook(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
data: Json<v0::CreateWebhookBody>,
|
data: Json<v0::CreateWebhookBody>,
|
||||||
) -> Result<Json<v0::Webhook>> {
|
) -> Result<Json<v0::Webhook>> {
|
||||||
let data = data.into_inner();
|
let data = data.into_inner();
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
pub async fn fetch_webhooks(
|
pub async fn fetch_webhooks(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
channel_id: Reference,
|
channel_id: Reference<'_>,
|
||||||
) -> Result<Json<Vec<Webhook>>> {
|
) -> Result<Json<Vec<Webhook>>> {
|
||||||
let channel = channel_id.as_channel(db).await?;
|
let channel = channel_id.as_channel(db).await?;
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use rocket_empty::EmptyResponse;
|
|||||||
pub async fn delete_emoji(
|
pub async fn delete_emoji(
|
||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
user: User,
|
user: User,
|
||||||
emoji_id: Reference,
|
emoji_id: Reference<'_>,
|
||||||
) -> Result<EmptyResponse> {
|
) -> Result<EmptyResponse> {
|
||||||
// Fetch the emoji
|
// Fetch the emoji
|
||||||
let emoji = emoji_id.as_emoji(db).await?;
|
let emoji = emoji_id.as_emoji(db).await?;
|
||||||
@@ -26,7 +26,7 @@ pub async fn delete_emoji(
|
|||||||
// Otherwise, validate we have permission to delete from parent
|
// Otherwise, validate we have permission to delete from parent
|
||||||
match &emoji.parent {
|
match &emoji.parent {
|
||||||
EmojiParent::Server { id } => {
|
EmojiParent::Server { id } => {
|
||||||
let server = db.fetch_server(id).await?;
|
let server = db.fetch_server(id.as_str()).await?;
|
||||||
|
|
||||||
// Check for permission
|
// Check for permission
|
||||||
let mut query = DatabasePermissionQuery::new(db, &user).server(&server);
|
let mut query = DatabasePermissionQuery::new(db, &user).server(&server);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
/// Fetch an emoji by its id.
|
/// Fetch an emoji by its id.
|
||||||
#[openapi(tag = "Emojis")]
|
#[openapi(tag = "Emojis")]
|
||||||
#[get("/emoji/<emoji_id>")]
|
#[get("/emoji/<emoji_id>")]
|
||||||
pub async fn fetch_emoji(db: &State<Database>, emoji_id: Reference) -> Result<Json<v0::Emoji>> {
|
pub async fn fetch_emoji(db: &State<Database>, emoji_id: Reference<'_>) -> Result<Json<v0::Emoji>> {
|
||||||
emoji_id
|
emoji_id
|
||||||
.as_emoji(db)
|
.as_emoji(db)
|
||||||
.await
|
.await
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use rocket_empty::EmptyResponse;
|
|||||||
/// Delete an invite by its id.
|
/// Delete an invite by its id.
|
||||||
#[openapi(tag = "Invites")]
|
#[openapi(tag = "Invites")]
|
||||||
#[delete("/<target>")]
|
#[delete("/<target>")]
|
||||||
pub async fn delete(db: &State<Database>, user: User, target: Reference) -> Result<EmptyResponse> {
|
pub async fn delete(db: &State<Database>, user: User, target: Reference<'_>) -> Result<EmptyResponse> {
|
||||||
let invite = target.as_invite(db).await?;
|
let invite = target.as_invite(db).await?;
|
||||||
|
|
||||||
if user.id == invite.creator() {
|
if user.id == invite.creator() {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use rocket::{serde::json::Json, State};
|
|||||||
/// Fetch an invite by its id.
|
/// Fetch an invite by its id.
|
||||||
#[openapi(tag = "Invites")]
|
#[openapi(tag = "Invites")]
|
||||||
#[get("/<target>")]
|
#[get("/<target>")]
|
||||||
pub async fn fetch(db: &State<Database>, target: Reference) -> Result<Json<v0::InviteResponse>> {
|
pub async fn fetch(db: &State<Database>, target: Reference<'_>) -> Result<Json<v0::InviteResponse>> {
|
||||||
Ok(Json(match target.as_invite(db).await? {
|
Ok(Json(match target.as_invite(db).await? {
|
||||||
Invite::Server {
|
Invite::Server {
|
||||||
channel, creator, ..
|
channel, creator, ..
|
||||||
@@ -34,7 +34,7 @@ pub async fn fetch(db: &State<Database>, target: Reference) -> Result<Json<v0::I
|
|||||||
let server = db.fetch_server(&server).await?;
|
let server = db.fetch_server(&server).await?;
|
||||||
|
|
||||||
v0::InviteResponse::Server {
|
v0::InviteResponse::Server {
|
||||||
code: target.id,
|
code: target.id.to_string(),
|
||||||
member_count: db.fetch_member_count(&server.id).await? as i64,
|
member_count: db.fetch_member_count(&server.id).await? as i64,
|
||||||
server_id: server.id,
|
server_id: server.id,
|
||||||
server_name: server.name,
|
server_name: server.name,
|
||||||
@@ -64,7 +64,7 @@ pub async fn fetch(db: &State<Database>, target: Reference) -> Result<Json<v0::I
|
|||||||
description,
|
description,
|
||||||
..
|
..
|
||||||
} => v0::InviteResponse::Group {
|
} => v0::InviteResponse::Group {
|
||||||
code: target.id,
|
code: target.id.to_string(),
|
||||||
channel_id: id,
|
channel_id: id,
|
||||||
channel_name: name,
|
channel_name: name,
|
||||||
channel_description: description,
|
channel_description: description,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ pub async fn join(
|
|||||||
db: &State<Database>,
|
db: &State<Database>,
|
||||||
amqp: &State<AMQP>,
|
amqp: &State<AMQP>,
|
||||||
user: User,
|
user: User,
|
||||||
target: Reference,
|
target: Reference<'_>,
|
||||||
) -> Result<Json<v0::InviteJoinResponse>> {
|
) -> Result<Json<v0::InviteJoinResponse>> {
|
||||||
if user.bot.is_some() {
|
if user.bot.is_some() {
|
||||||
return Err(create_error!(IsBot));
|
return Err(create_error!(IsBot));
|
||||||
|
|||||||
Loaded 100 of 153 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user