From fed1da72fdfe3c4a9865820f5362eb9f0e3f0fd7 Mon Sep 17 00:00:00 2001 From: Paul Makles Date: Fri, 20 Jan 2023 15:43:45 +0000 Subject: [PATCH] feat: support rauth events feat: add platform user wipe event --- Cargo.lock | 14 +++++++------- crates/bonfire/Cargo.toml | 2 +- crates/delta/Cargo.toml | 4 ++-- crates/delta/src/main.rs | 26 ++++++++++++++++++++++++-- crates/quark/Cargo.toml | 4 ++-- crates/quark/src/events/client.rs | 15 +++++++++++++++ crates/quark/src/events/impl.rs | 5 +++++ crates/quark/src/models/users/user.rs | 2 ++ 8 files changed, 58 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 09263c63..628e06cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2580,8 +2580,8 @@ dependencies = [ [[package]] name = "rauth" -version = "1.0.0" -source = "git+https://github.com/insertish/rauth?rev=195f1703cc4c57be01a39f465296cab4e22524b3#195f1703cc4c57be01a39f465296cab4e22524b3" +version = "1.0.2" +source = "git+https://github.com/insertish/rauth?tag=1.0.2#d466718bb4f1c8ca03f4a17265a646a52e07dff5" dependencies = [ "async-std", "async-trait", @@ -2790,7 +2790,7 @@ dependencies = [ [[package]] name = "revolt-bonfire" -version = "0.5.5" +version = "0.5.6" dependencies = [ "async-std", "async-tungstenite", @@ -2806,7 +2806,7 @@ dependencies = [ [[package]] name = "revolt-delta" -version = "0.5.5" +version = "0.5.6" dependencies = [ "async-channel", "async-std", @@ -2846,7 +2846,7 @@ dependencies = [ [[package]] name = "revolt-quark" -version = "0.1.0" +version = "0.5.6" dependencies = [ "async-recursion", "async-std", @@ -3080,8 +3080,8 @@ dependencies = [ [[package]] name = "rocket_rauth" -version = "1.0.0" -source = "git+https://github.com/insertish/rauth?rev=195f1703cc4c57be01a39f465296cab4e22524b3#195f1703cc4c57be01a39f465296cab4e22524b3" +version = "1.0.2" +source = "git+https://github.com/insertish/rauth?tag=1.0.2#d466718bb4f1c8ca03f4a17265a646a52e07dff5" dependencies = [ "iso8601-timestamp", "rauth", diff --git a/crates/bonfire/Cargo.toml b/crates/bonfire/Cargo.toml index ba684e55..bb7a05fd 100644 --- a/crates/bonfire/Cargo.toml +++ b/crates/bonfire/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt-bonfire" -version = "0.5.5" +version = "0.5.6" license = "AGPL-3.0-or-later" edition = "2021" diff --git a/crates/delta/Cargo.toml b/crates/delta/Cargo.toml index 056fcb9d..5dcdc6e0 100644 --- a/crates/delta/Cargo.toml +++ b/crates/delta/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt-delta" -version = "0.5.5" +version = "0.5.6" license = "AGPL-3.0-or-later" authors = ["Paul Makles "] edition = "2018" @@ -52,7 +52,7 @@ mobc-redis = { version = "0.7.0", default-features = false, features = ["async-s # web rocket = { version = "0.5.0-rc.2", default-features = false, features = ["json"] } rocket_empty = { version = "0.1.1", features = ["schema"] } -rocket_rauth = { git = "https://github.com/insertish/rauth", rev = "195f1703cc4c57be01a39f465296cab4e22524b3" } +rocket_rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.2" } # spec generation schemars = "0.8.8" diff --git a/crates/delta/src/main.rs b/crates/delta/src/main.rs index 728bdcf6..4a7ab96d 100644 --- a/crates/delta/src/main.rs +++ b/crates/delta/src/main.rs @@ -10,7 +10,9 @@ extern crate lazy_static; pub mod routes; pub mod util; -use revolt_quark::rauth::RAuth; +use async_std::channel::unbounded; +use revolt_quark::events::client::EventV1; +use revolt_quark::rauth::{RAuth, RAuthEvent}; use revolt_quark::DatabaseInfo; #[launch] @@ -25,13 +27,33 @@ async fn rocket() -> _ { let db = DatabaseInfo::Auto.connect().await.unwrap(); db.migrate_database().await.unwrap(); + // Setup rAuth event channel + let (sender, receiver) = unbounded(); + // Setup rAuth let rauth = RAuth { database: db.clone().into(), config: revolt_quark::util::rauth::config(), + event_channel: Some(sender), }; - // Launch background task workers. + // Launch a listener for rAuth events + async_std::task::spawn(async move { + while let Ok(event) = receiver.recv().await { + match &event { + RAuthEvent::CreateSession { .. } | RAuthEvent::CreateAccount { .. } => { + EventV1::Auth(event).global().await + } + RAuthEvent::DeleteSession { user_id, .. } + | RAuthEvent::DeleteAllSessions { user_id, .. } => { + let id = user_id.to_string(); + EventV1::Auth(event).private(id).await + } + } + } + }); + + // Launch background task workers async_std::task::spawn(revolt_quark::tasks::start_workers(db.clone())); // Configure CORS diff --git a/crates/quark/Cargo.toml b/crates/quark/Cargo.toml index 51b5666c..6f67c6d9 100644 --- a/crates/quark/Cargo.toml +++ b/crates/quark/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "revolt-quark" -version = "0.1.0" +version = "0.5.6" license = "AGPL-3.0-or-later" edition = "2021" @@ -84,7 +84,7 @@ rocket_empty = { version = "0.1.1", optional = true, features = [ "schema" ] } rocket_cors = { optional = true, git = "https://github.com/lawliet89/rocket_cors", rev = "c17e8145baa4790319fdb6a473e465b960f55e7c" } # rAuth -rauth = { git = "https://github.com/insertish/rauth", rev = "195f1703cc4c57be01a39f465296cab4e22524b3", features = [ "async-std-runtime" ] } +rauth = { git = "https://github.com/insertish/rauth", tag = "1.0.2", features = [ "async-std-runtime" ] } # Sentry sentry = "0.25.0" diff --git a/crates/quark/src/events/client.rs b/crates/quark/src/events/client.rs index 28f7eb6a..f9275e9d 100644 --- a/crates/quark/src/events/client.rs +++ b/crates/quark/src/events/client.rs @@ -1,3 +1,4 @@ +use rauth::RAuthEvent; use serde::{Deserialize, Serialize}; use crate::models::channel::{FieldsChannel, PartialChannel}; @@ -195,9 +196,23 @@ pub enum EventV1 { /// Settings updated remotely UserSettingsUpdate { id: String, update: UserSettings }, + /// User has been platform banned or deleted their account + /// + /// Clients should remove the following associated data: + /// - Messages + /// - DM Channels + /// - Relationships + /// - Server Memberships + /// + /// User flags are specified to explain why a wipe is occurring though not all reasons will necessarily ever appear. + UserPlatformWipe { user_id: String, flags: i32 }, + /// New emoji EmojiCreate(Emoji), /// Delete emoji EmojiDelete { id: String }, + + /// Auth events + Auth(RAuthEvent), } diff --git a/crates/quark/src/events/impl.rs b/crates/quark/src/events/impl.rs index 6da72a77..d4b36c19 100644 --- a/crates/quark/src/events/impl.rs +++ b/crates/quark/src/events/impl.rs @@ -559,4 +559,9 @@ impl EventV1 { pub async fn private(self, id: String) { self.p(format!("{}!", id)).await; } + + /// Publish internal global event + pub async fn global(self) { + self.p("global".to_string()).await; + } } diff --git a/crates/quark/src/models/users/user.rs b/crates/quark/src/models/users/user.rs index 185bf286..1ea03fd9 100644 --- a/crates/quark/src/models/users/user.rs +++ b/crates/quark/src/models/users/user.rs @@ -105,6 +105,8 @@ pub enum Flags { Deleted = 2, /// User was banned off the platform Banned = 4, + /// User was marked as spam and removed from platform + Spam = 8, } /// Bot information for if the user is a bot